This page is no longer maintained — Please continue to the home page at

fascinating repl behavior

1 reply
Joined: 2008-07-01,
User offline. Last seen 45 weeks 5 days ago.
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")

"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

Did i call the "getter"? And what kind of value is "a.m(s).t: Int = -282"?

Joined: 2008-12-17,
User offline. Last seen 35 weeks 3 days ago.
Re: fascinating repl behavior

On Wed, Jan 25, 2012 at 9:08 AM, Lukas Rytz <lukas [dot] rytz [at] epfl [dot] 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...)

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland