Dotty: Numeric harmonization is broken

Created on 22 Mar 2019  路  2Comments  路  Source: lampepfl/dotty

Or at least, I don't think this is the behavior we want:

scala> val x: Int = 0
val val x: Int = 0

scala> val y: Long = 0
val y: Long = 0

scala> val b: Boolean = true
val b: Boolean = true

scala> val z = if (b) x else y
val z: AnyVal = 0

I'd expect z to be a Long, like it would be in Scala 2 or Java. The current behavior required some adaptation in the standard library: https://github.com/scala/scala/pull/7458/commits/e65e2c7490a5ea8d085a1d3081b5a91211e8a3ba
/cc @odersky @sjrd

typer

Most helpful comment

I would argue that this is exactly the behavior we want. Only constant Ints are allowed to be harmonized. For other Ints you need an explicit .toLong if you want them to be reinterpreted as Longs.

All 2 comments

I would argue that this is exactly the behavior we want. Only constant Ints are allowed to be harmonized. For other Ints you need an explicit .toLong if you want them to be reinterpreted as Longs.

The current behavior corresponds to the SIP. Do we want to re-open it? After the discussion we had (where the majority was pushing to be even more restrictive than we are now), I am skeptical.

Was this page helpful?
0 / 5 - 0 ratings