Skip to content

malformed number literal 0x7FFF_FFFF : Float #8398

Closed
@som-snytt

Description

@som-snytt

minimized code

Dotty compiler version 0.22.0-RC1 -- Copyright 2002-2020, LAMP/EPFL
scala> 0x7FFF_FFFF
val res0: Int = 2147483647

scala> 0x7FFF_FFFF : Float
1 |0x7FFF_FFFF : Float
  |^^^^^^^^^^^
  |malformed number literal

scala> Seq(3.14f, 0x7FFF_FFFF)
val res1: Seq[Float] = List(3.14, 2.14748365E9)

scala> Seq(3.14f, 0x7FFF_FFFE)                                                                                                                    
val res2: Seq[AnyVal] = List(3.14, 2147483646)

scala> Array(3.14f, 0x7FFF_FFFE)                                                                                                                  
val res3: Array[Float] = Array(3.14, 2.14748365E9)

scala> 2147483647 : Float                                                                                                                         
val res4: Float = 2.14748365E9

Compilation output

per transcript

expectation

0x7FFF_FFFF : Float is the same as 2147483647 : Float.

Would be nice to warn or indicate that Array(3.14f, 0x7FFF_FFFE) is inferred Float element, so that the int literal is lossy. Alternatively, infer boxed AnyVal, which is not intended but will catch the eye of a linter.

Similarly, Seq(3.14f, 0x7FFF_FFFE): Seq[Float] is tricky if you're innocently passing the arg to a method f(xs: Seq[Float]).

Also repeating parameter works as above:

scala> def sumall(xs: Float*) = xs.sum
def sumall(xs: Float*): Float

scala> sumall(3.14f, 0x7FFF_FFFF)                                                                                                                 
1 |sumall(3.14f, 0x7FFF_FFFF)
  |              ^^^^^^^^^^^
  |              malformed number literal

I have to do more cleaning, probably I ran .22 and also .23.

scala> sumall(3.14f, 0x7FFF_FFFF)
error while loading test$,
class file f/test.class is broken, reading aborted with class dotty.tools.tasty.UnpickleException
TASTy signature has wrong version.
 expected: 19.0
 found   : 18.0
error while loading C$,
class file f/C.class is broken, reading aborted with class dotty.tools.tasty.UnpickleException
TASTy signature has wrong version.
 expected: 19.0
 found   : 18.0
1 |sumall(3.14f, 0x7FFF_FFFF)
  |       ^^^^^^^^^^^^^^^^^^
  |       Found:    (Float, Int)
  |       Required: Seq[Float]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions