New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
forward reference in block allowed in 2.9 #4419
Comments
Imported From: https://issues.scala-lang.org/browse/SI-4419?orig=1 |
@retronym said: Welcome to Scala version 2.9.0.RC1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_22).
Type in expressions to have them evaluated.
Type :help for more information.
scala> { val b = a; val a = 1} |
@paulp said: scala> { val b = a ; val a = 1 ; b }
res2: Int = 1 Now I see what happened: scala> def foo() = 1
foo: ()Int
scala> { val b = a ; val a = foo() ; b }
<console>:9: error: forward reference extends over definition of value b
{ val b = a ; val a = foo() ; b }
^ So this is due to r23262, which explains the motivation. |
@magarciaEPFL said: For the program object bug4419 {
val b = a
val a = 1
} [[syntax trees at end of cleanup]] package <empty> {
final object bug4419 extends java.lang.Object with ScalaObject {
@volatile private[this] var bitmap$$init$$0: Int = 0;
private[this] val b: Int = _;
<stable> <accessor> def b(): Int = {
if (bug4419.this.bitmap$$init$$0.&(1).!=(0))
bug4419.this.b
else
throw new UninitializedFieldError("Uninitialized field: bt4.scala: 3".toString());
bug4419.this.b
};
private[this] val a: Int = _;
<stable> <accessor> def a(): Int = {
if (bug4419.this.bitmap$$init$$0.&(2).!=(0))
bug4419.this.a
else
throw new UninitializedFieldError("Uninitialized field: bt4.scala: 5".toString());
bug4419.this.a
};
def this(): object bug4419 = {
bug4419.super.this();
bug4419.this.b = bug4419.this.a();
bug4419.this.bitmap$$init$$0 = bug4419.this.bitmap$$init$$0.|(1);
bug4419.this.a = 1;
bug4419.this.bitmap$$init$$0 = bug4419.this.bitmap$$init$$0.|(2);
()
}
}
}
|
@magarciaEPFL said: |
@retronym said: Forward references in template definitions are subject to |
@paulp said:
It now looks to me like "def isLocal" does not really mean what its comment says. The logic in widenIfNecessary should perhaps be more like "if (sym.isFinal || sym.owner.isMethod)" rather than || sym.isLocal. |
@paulp said: |
@paulp said: scala -nc -Xcheckinit -e 'object Test { val b = a ; val a = 1 } ; Test'
scala.UninitializedFieldError: Uninitialized field: scalacmd231514277721527718.scala: 1
at Main$$$$anon$$1$$Test$$.a(scalacmd231514277721527718.scala:1)
at Main$$$$anon$$1$$Test$$.<init>(scalacmd231514277721527718.scala:1)
at Main$$$$anon$$1.Test(scalacmd231514277721527718.scala:1)
at Main$$$$anon$$1.<init>(scalacmd231514277721527718.scala:1)
at Main$$.main(scalacmd231514277721527718.scala:1)
|
@paulp said: |
=== What steps will reproduce the problem? ===
=== What is the expected behavior? ===
Not sure if this change was intentional; but the spec still supports the 2.8.1 view of things.
=== What versions of the following are you using? ===
The text was updated successfully, but these errors were encountered: