typelevel / scala

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

A `final val` with literal type should be treated as a constant value #140

Closed Atry closed 7 years ago

Atry commented 7 years ago
object O {
  final val one = 1
  final val literalOne: 1 = 1
  final val IntOne: Int = 1

  final val compiles: 2 = one + 1
  final val doesNotCompile: 2 = literalOne + 1 // type mismatch; found   : Int; required: 2
  final val alsoDoesNotCompile: 2 = IntOne + 1 // type mismatch; found   : Int; required: 2
}

See https://scastie.scala-lang.org/Atry/Q568k8nZRtSldg4kjw4sSA/3 for complete code

I expect final val doesNotCompile: 2 = literalOne + 1 compiles, because literalOne should be a constant value.

soronpo commented 7 years ago

Maybe related bug. When fixed, also test against:

object O2 {
  final val five : 5 = five + 0
}

This code works in dotty.

milessabin commented 7 years ago

All these examples will work as expected in the next TLS releases.