scala / bug

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

Literal type is TMI for constant #12689

Open som-snytt opened 1 year ago

som-snytt commented 1 year ago

Reproduction steps

Scala version: 2.13.10

class C {
  final val x = 42
  final val y: 42 = 42

  def f = x
  def g = y
  def f2 = x+1
  def g2 = y+1
}

Problem

Scala 3 correctly does the same for both, which is no field.

Scala 2 incorrectly or suboptimally has field for y and accessor is invoked for g, but g2 is constant-folded (during type checking).

Noticed at https://github.com/cquiroz/scala-java-time/pull/403#issuecomment-1309909556 where

It's hard to reason about this.

Of course, inline addresses these concerns.