Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Misc Compiler
    • Labels:
      None
    • Environment:

      refchecks

      Description

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

        Activity

        Hide
        Jason Zaugg added a comment -

        `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}
        
        Show
        Jason Zaugg added a comment - `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}
        Hide
        Paul Phillips added a comment -

        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.

        Show
        Paul Phillips added a comment - 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.
        Hide
        Miguel Garcia added a comment -

        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);
              ()
            }
          }
        }
        
        
        Show
        Miguel Garcia added a comment - 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); () } } }
        Hide
        Miguel Garcia added a comment -

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

        Show
        Miguel Garcia added a comment - If this bug is due to r23262, and r23262 was reviewed by Lukas, asking Lukas for comments.
        Hide
        Jason Zaugg added a comment -

        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.

        Show
        Jason Zaugg added a comment - 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.
        Hide
        Paul Phillips added a comment -

        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.

        Show
        Paul Phillips added a comment - 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.
        Hide
        Paul Phillips added a comment -

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

        Show
        Paul Phillips added a comment - ...which still wouldn't fix the bug jason reported, but that one is pretty innocuous, the one in the object is much more serious.
        Hide
        Paul Phillips added a comment -

        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)
        
        
        Show
        Paul Phillips added a comment - 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)
        Hide
        Paul Phillips added a comment -

        Fixed in r25015.

        Show
        Paul Phillips added a comment - Fixed in r25015.

          People

          • Assignee:
            Paul Phillips
            Reporter:
            Jason Zaugg
            TracCC:
            Ismael Juma, Paul Phillips, Seth Tisue
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development