bug
bug copied to clipboard
REPL doesn't do leading dot of float
Reproduction steps
Welcome to Scala 2.13.8 (OpenJDK 64-Bit Server VM, Java 17.0.2).
Type in expressions for evaluation. Or try :help.
scala> 42
val res0: Int = 42
scala> .42
^
error: ';' expected but double literal found.
scala> def f = .42
def f: Double
scala> "hi"
val res1: String = hi
scala> .length
val res2: Int = 2
Problem
Pity the beginner trying out forms of literals in the REPL. Or me.
Also the caret does not align. It's probably prompt-indented? It's a fixed offset.
workaround
scala 2.13.8> /**/ .42
val res0: Double = 0.42
😜🤡
@som-snytt I agree that this is puzzling and undesirable behavior. It isn't immediately obvious to me what rule that .-on-previous-result implementation ought to use to exclude .42 from its consideration, but probably whatever you come up with (if you choose to tackle this) would be fine, .-on-previous-result being unspec'ed REPL-specific stuff anyway
(Dale observes that it's "fixed" in Scala 3 because the Scala 3 REPL doesn't have the .-on-previous-result feature at all)
Yes, I will backport the solution I come up with for Scala 3. (Numbers and member selection are not ambiguous.)