-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Labels
Description
Compiler version
Tested on Scala 3.7.3 and 3.8.0-RC1-bin-20251023-9ec1f84-NIGHTLY.
Minimized code
The code below contains two version that summon as singletons in a Tuple
//> using scala 3.7.3
import scala.compiletime.{erasedValue, summonFrom}
object test {
// This version fails with "cannot reduce summonFrom"
private inline def singletons[T, Elem <: Tuple]: Seq[T] =
inline erasedValue[Elem] match {
case _: EmptyTuple => Seq.empty
case _: (h *: t) => valueOf[`h` & T] +: singletons[T, t]
}
// This version works when wrapped in summonFrom
private inline def singletons2[T, Elem <: Tuple]: Seq[T] =
inline erasedValue[Elem] match {
case _: EmptyTuple => Seq.empty
case _: (h *: t) =>
summonFrom {
case _: ValueOf[`h`] => valueOf[`h` & T] +: singletons2[T, t]
}
}
enum A { case A1, A2, A3 }
def main(args: Array[String]): Unit =
println(singletons[A, (A.A1.type, A.A2.type, A.A3.type)]) // Fails
println(singletons2[A, (A.A1.type, A.A2.type, A.A3.type)]) // Works: List(A1, A2, A3)
}Output
Compiling project (Scala 3.7.3, JVM (21))
[error] ./bug_test.scala:22:13
[error] cannot reduce summonFrom with
[error] patterns : case given ev @ _:ValueOf[(test.A.A1 : test.A) & test.A]
[error] println(singletons[A, (A.A1.type, A.A2.type, A.A3.type)]) // cannot reduce summonFrom
[error] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error compiling project (Scala 3.7.3, JVM (21))
Compilation failed
When the line with singletons is commented out and singletons2 is used instead:
Compiling project (Scala 3.7.3, JVM (21))
Compiled project (Scala 3.7.3, JVM (21))
List(A1, A2, A3)
Expectation
The behavior feels inconsistent. Either both should work or neither.