bug icon indicating copy to clipboard operation
bug copied to clipboard

REPL doesn't do leading dot of float

Open som-snytt opened this issue 3 years ago • 3 comments

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.

som-snytt avatar Mar 21 '22 19:03 som-snytt

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

SethTisue avatar Apr 19 '22 17:04 SethTisue

(Dale observes that it's "fixed" in Scala 3 because the Scala 3 REPL doesn't have the .-on-previous-result feature at all)

SethTisue avatar Apr 19 '22 17:04 SethTisue

Yes, I will backport the solution I come up with for Scala 3. (Numbers and member selection are not ambiguous.)

som-snytt avatar Apr 19 '22 18:04 som-snytt