Skip to content
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

Closed
scabug opened this issue Mar 30, 2011 · 10 comments
Closed

forward reference in block allowed in 2.9 #4419

scabug opened this issue Mar 30, 2011 · 10 comments
Assignees

Comments

@scabug
Copy link

scabug commented Mar 30, 2011

=== What steps will reproduce the problem? ===

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> { lazy val b = a; val a = 1 }

=== What is the expected behavior? ===

Welcome to Scala version 2.8.1.final (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> { lazy val b = a; val a = 1} 
<console>:6: error: forward reference extends over definition of value a
       { lazy val b = a; val a = 1}
                      ^

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? ===

  • Scala: 2.9.0.RC1
@scabug
Copy link
Author

scabug commented Mar 30, 2011

Imported From: https://issues.scala-lang.org/browse/SI-4419?orig=1
Reporter: @retronym

@scabug
Copy link
Author

scabug commented Mar 30, 2011

@retronym said:
lazy isn't actually required. I need to listen to more minimal house before filing bug reports.

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}

@scabug
Copy link
Author

scabug commented Mar 30, 2011

@paulp said:
Ah, my fault. At first I was a little amazed at this result:

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.

@scabug
Copy link
Author

scabug commented Apr 4, 2011

@magarciaEPFL said:
I've reproduced this bug with r24667 (and -Xcheckinit doesn't help either).

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);
      ()
    }
  }
}

@scabug
Copy link
Author

scabug commented Apr 4, 2011

@magarciaEPFL said:
If this bug is due to r23262, and r23262 was reviewed by Lukas, asking Lukas for comments.

@scabug
Copy link
Author

scabug commented Apr 4, 2011

@retronym said:
I raised the bug about forward references within blocks (which should be illegal).

Forward references in template definitions are subject to -Xcheck-init but are legal.

@scabug
Copy link
Author

scabug commented Apr 4, 2011

@paulp said:
Replying to [comment:6 magarcia]:

If this bug is due to r23262, and r23262 was reviewed by Lukas, asking Lukas for comments.

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.

@scabug
Copy link
Author

scabug commented Apr 4, 2011

@paulp said:
...which still wouldn't fix the bug jason reported, but that one is pretty innocuous, the one in the object is much more serious.

@scabug
Copy link
Author

scabug commented Apr 13, 2011

@paulp said:
The suggested "Xcheckinit not working" bug does not seem to exist. Don't be distracted by the fancy command line:

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)

@scabug
Copy link
Author

scabug commented May 23, 2011

@paulp said:
Fixed in r25015.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants