Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic trait difference from Scala 2.9 to 2.10

Tags:

scala

I have written a little snippet of code to test the Dynamic trait capabilities:

class Foo extends Dynamic {
  def selectDynamic(name: String) {
    println("selectDynamic: " + name)
  }
  def applyDynamic(name: String)(args: Any*) {
    println("applyDynamic: " + name)
  }
  def applyDynamicNamed(name: String)(args: (String, Any)*) {
    println("applyDynamicNamed: " + name)
  }
  def updateDynamic(name: String)(value: Any) {
    println("updateDynamic: " + name)
  }
}

object Test {
  def main(args: Array[String]) {
    val foo = new Foo
    foo.bar(5)     //1
    foo.bar(x = 5) //2
    foo.bar        //3
    foo.baz = 5    //4
  }
}

The problem is that it wouldn't compile both in Scala 2.9 and 2.10 because of the fourth line in main:

error: reassignment to val
foo.baz = 5

If I comment this string, 2.9 would complain about the second line:

error: not found: value x
foo.bar(x = 5)

Meanwhile 2.10 would compile and the program would produce:

applyDynamic: bar
applyDynamicNamed: bar
selectDynamic: bar

So now I wonder if I'm doing something wrong (maybe miss some dependencies)? Is there a difference between Dynamic's in Scala 2.9 and 2.10? And what's wrong with the foo.baz = 5?

like image 773
Sergey Weiss Avatar asked Jul 05 '12 08:07

Sergey Weiss


1 Answers

This is a bug: https://issues.scala-lang.org/browse/SI-5733

like image 92
Eugene Burmako Avatar answered Sep 18 '22 13:09

Eugene Burmako