- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
fascinating repl behavior
Wed, 2012-01-25, 18:09
scala> lamppc11:~ luc$ ~/Downloads/scala-2.10.0.rdev-4250-2012-01-25-gde2b0c6/bin/scalaWelcome to Scala version 2.10.0.rdev-4250-2012-01-25-gde2b0c6 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_29).Type in expressions to have them evaluated.Type :help for more information.
scala> class A {def t: Int = {println("getter"); -282}; def t_=(p: Int) { println("setter") }; def m(v: String) = new A}defined class A
scala> val a = new Aa: A = A@46aea8cf
scala> a m "txt" t = 18; println("x")
scala>
"setter" is not called, there's no "x" printed.. putting the last part in a block, i.e. { a m "txt" t = 18; println("x") } helps.
Now even more surprising:
scala> val s = "txt"s: String = txt
scala> a m s t = 18; println("x")setterxgettera.m(s).t: Int = -282
scala>
Did i call the "getter"? And what kind of value is "a.m(s).t: Int = -282"?
scala> class A {def t: Int = {println("getter"); -282}; def t_=(p: Int) { println("setter") }; def m(v: String) = new A}defined class A
scala> val a = new Aa: A = A@46aea8cf
scala> a m "txt" t = 18; println("x")
scala>
"setter" is not called, there's no "x" printed.. putting the last part in a block, i.e. { a m "txt" t = 18; println("x") } helps.
Now even more surprising:
scala> val s = "txt"s: String = txt
scala> a m s t = 18; println("x")setterxgettera.m(s).t: Int = -282
scala>
Did i call the "getter"? And what kind of value is "a.m(s).t: Int = -282"?
On Wed, Jan 25, 2012 at 9:08 AM, Lukas Rytz <lukas.rytz@epfl.ch> wrote:
>
> Did i call the "getter"? And what kind of value is "a.m(s).t: Int = -282"?
Until relatively recently the repl wouldn't let you use anything but a simple ident on the left hand side of an assignment. I relaxed that restriction, and I can see that this bug arises from the lhs tree in the Assign being fancier than it understands. The traverser which figures out what names need to be imported for a given repl line fails to import 'a'.
> And what kind of value is "a.m(s).t: Int = -282"?
Why, it's an Int of course!
(If you could open a ticket and assign it to me that would be great...)