Aladdin - Scala Bugtracking
[#1201] project: compiler priority: low category: missing feature
submitter assigned to status date submitted
Burak Martin won't fix 2007-07-09 11:46:25.0
subject single-branch if eats up result
code
scala> val x: AnyVal = ()
x: AnyVal = ()

scala> val x: AnyVal = if (true) 1 else ()
x: AnyVal = 1

scala> val x: AnyVal = if (true) 1
x: AnyVal = ()
what happened
the above executes in interpreter and is according to spec
what expected it's not intuitive. spec should take the possibility of AnyVal into account, and let the if return its result. it's more efficient to represent option[valtype] this way. alternatively, we have to discourage using anyval as an actual type
[back to overview]
Changes of this bug report
Martin  edited on  2007-07-14 11:47:11.0
I think if you want an AnyVal (which should be rare) it's not too much to demand that you write an else.