typelevel / scala

Typelevel Scala, a fork of Scala
http://typelevel.org/scala/
372 stars 21 forks source link

Improve -Ywarn-numeric-widen #92

Closed tpolecat closed 8 years ago

tpolecat commented 9 years ago

The -Ywarn-numeric-widen flag mostly warns for widening of non-constant expressions; for example:

scala> def foo(d:Double) = d + 1
foo: (d: Double)Double

scala> foo("x".length)
<console>:9: warning: implicit numeric widening
              foo("x".length)
                      ^
res12: Double = 2.0

However this warning doesn't apply to [foldable] constants:

scala> foo(2 + 4)
res22: Double = 7.0

scala> foo('x')
res23: Double = 121.0

I don't know if this is related to this delightful phenomenon, but if so I would be happy to see this give me the List[AnyVal] I expected:

scala> List('z', 2f, 3.4)
res26: List[Double] = List(122.0, 2.0, 3.4)
som-snytt commented 9 years ago

Related discussion on the ML, Rex Kerr said don't ask me to write 0.0 everywhere. Apparently, it matters if you do it a lot.

tpolecat commented 9 years ago

Well it would need to be hidden behind a flag of course, so Rex is safe.

milessabin commented 8 years ago

To resurrect this issue, please rework it as an issue/PR against Lightbend Scala (ie. scala/scala).