scala-ide / scala-worksheet

A Scala IDE plugin for a multi-line REPL (called worksheet)
96 stars 24 forks source link

Re-assignment of a var is not evaluated #63

Open dotta opened 12 years ago

dotta commented 12 years ago
object o {
   var a = 2                                        //> a : Int = 2
   a = 3
}
dotta commented 12 years ago

Martin doesn't need this for the Coursera class, so moved it to next Milestone (we will need to hack the REPL support in the compiler to get the right behavior)

dragos commented 12 years ago

I don't think this is a bug. The type of an assignment is Unit, so there is no value to display. Otherwise, we could display ()

dotta commented 12 years ago

I see your point, but I think it's a matter of perception. I like the worksheet because it shows me the program's flow, and seeing updates to a var is what I'd expect. (but it may be me having a wrong expectation of course)

luigip commented 11 years ago

The type of var a = 2 is Unit as well, but we display that. I would also expect to see re-assignment of a var displayed, but I'm not sure what I would expect if it were re-assigned multiple times in a loop.

dragos commented 11 years ago

Not exactly. var a = 2 is a definition, not an expression. It does not have a type (for instance, you can't assign a definition to a local variable, or pass it as argument, etc so in fact it does not have a value).

We display initial values of definitions, but not for reassignments. I don't feel that strongly about this one, but it would be an irregularity (what other expressions of type Unit should we special case?).