Skip to content

Should constant-folding see through ascriptions? #24432

@mbovel

Description

@mbovel

Tried with @hamzaremmal.

Compiler version

3.8.0-RC1-bin-20250822-658c8bd-NIGHTLY

Minimized code

import scala.annotation.targetName

def f(x: Int): Unit =
  println("Int")

@targetName("f_42")
def f(x: 42): Unit =
  println("42")

@targetName("f_43")
def f(x: 43): Unit =
  println("43")

inline def fourtyTwo = 42

@main def Test =
  val x: 43 = (42: Int) + 1
  f((42: Int)) // prints "Int"
  f((42: Int) + 1) // prints "43"
  f((42 + 1): Int) // prints "Int"

Output

$ scala -S 3.8.nightly -Xprint:genBCode test.scala
Compiled project (Scala 3.8.0-RC1-bin-20250822-658c8bd-NIGHTLY, JVM (17))
Int
43
Int

Expectation

Maybe val x shouldn't type-check, and f((42: Int) + 1) should resolve to f instead of f_43?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions