scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
230 stars 21 forks source link

Inferred override type of final val #12830

Closed som-snytt closed 11 months ago

som-snytt commented 11 months ago

Reproduction steps

Scala version: 2.13.12

➜  snips cat narrows.scala

class C {
  def i: Int = 42
}
object D extends C {
  override final val i = 27
}
object Test {
  def f: 27 = D.i
}

Problem

Compiles under 2.13 but not under -Xsource:3 because of the inferred type for D.i.

Dotty correctly infers 27. Probably Scala 2 inadvertently widens when picking the "narrow" intersection.

Noticed at https://github.com/scala/scala/pull/10439#issuecomment-1637074874