Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Literal type is TMI for constant #12689

Open
som-snytt opened this issue Nov 10, 2022 · 0 comments
Open

Literal type is TMI for constant #12689

som-snytt opened this issue Nov 10, 2022 · 0 comments
Labels
fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)
Milestone

Comments

@som-snytt
Copy link

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 cquiroz/scala-java-time#403 (comment) where

It's hard to reason about this.

Of course, inline addresses these concerns.

@dwijnand dwijnand added the fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) label Jan 13, 2023
@dwijnand dwijnand added this to the Backlog milestone Jan 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)
Projects
None yet
Development

No branches or pull requests

2 participants