Uploaded image for project: 'Scala Programming Language'
  1. Scala Programming Language
  2. SI-8371

Very bad: Change in variable scoping behavior in anonymous inner classes in 2.11-RC1

    Details

      Description

      Scala seems to be picking out the wrong instance variable:

      import scala.collection.mutable._
       
      class Beam { outer =>
        private val queue = new ArrayBuffer[Int]()
       
        def foo {
          outer.queue += 42
          new Beam {
            println(queue)
            assert(queue.length == 0) // boom
          }
        }
      }
       
      // 2.10: prints ArrayBuffer()
      // 2.11: prints ArrayBuffer(42) and then throws assertion error.
      (new Beam).foo() 
      
      

        Attachments

          Activity

            People

            • Assignee:
              moors Adriaan Moors
              Reporter:
              dlwh david hall
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: