I didn’t realize that there were types for double literals as well as integers, but I had a REPL up with Scala 3.1.0 and tried the following. Any chance this is 3.0.0 specific and has been fixed?
âžś ~ sdk use scala 3.0.0
Using scala version 3.0.0 in this shell.
âžś ~ scala
scala> val pi: 3.14 = 1.7
1 |val pi: 3.14 = 1.7
| ^^^
| Found: (1.7d : Double)
| Required: (3.14d : Double)
and also in my terminal window
âžś ~ sdk use scala 3.0.0
Using scala version 3.0.0 in this shell.
âžś ~ scala
scala> val pi: 3.14 = 42
val pi: 3.14 = 42.0
Oh I see, it was ignoring the “harmonized” int literal.
It’s also interesting that the REPL is not showing the value of pi with its definition:
scala> val pi: 3.14 = 42
val pi: 3.14 = 42.0
scala> pi
val res2: Double = 3.14
I expected 3.14 not 42.0, if that is the value of pi after definition. Maybe the scala 3 REPL is trying to show your definition, in the interest of fidelity. Oh, it seems 42.0 is stored in the field, but it’s not used in res2, which only has to report the value that inhabits the literal type!
The fix is in 3.0.1, which has a fix for constant folding, so maybe this was involved.