-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Labels
area:experimental:erased-definitionsarea:inlineitype:bugregressionThis worked in a previous version but doesn't anymoreThis worked in a previous version but doesn't anymore
Description
Compiler version
3.8.0-RC1 and newer (tested 3.8.1-RC1-bin-20251128-fe49539-NIGHTLY)
(compiles in 3.7.4)
Minimized code
Scastie: https://scastie.scala-lang.org/l4JwtPFxQBaKZqMFoAOzaA
object Test {
inline def dispatch(inline v: Long | String) =
inline v match
case str: String => printString(str)
case long: Long => printLong(long)
def printString(s: String) = println(s)
def printLong(s: Long) = println(s)
@main
def run() =
dispatch(System.nanoTime().toString)
dispatch(s"${System.nanoTime().toString}")
}Output
Compiling project (Scala 3.8.1-RC1-bin-20251128-fe49539-NIGHTLY, JVM (17))
[error] ./test.scala:14:5
[error] value str is unusable in method run because it refers to an erased expression
[error] in the selector of an inline match that reduces to
[error]
[error] {
[error] erased val $scrutinee2: String =
[error] _root_.scala.StringContext.apply(["","" : String]*).s(
[error] [System.nanoTime().toString() : Any]*)
[error] erased val str: String = $scrutinee2
[error] {
[error] Test.printString(str)
[error] }
[error] }
[error] dispatch(s"${System.nanoTime().toString}")
[error] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^Expectation
For some reason, specifically when passing s"…" to the dispatch inline def directly, the above error happens. All other strings I tried to pass compile as expected.
Works fine if the parameter of the inline def is not inline.
Metadata
Metadata
Assignees
Labels
area:experimental:erased-definitionsarea:inlineitype:bugregressionThis worked in a previous version but doesn't anymoreThis worked in a previous version but doesn't anymore