-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Description
Compiler version
Both 3.0.0 and 3.0.1-RC1-bin-20210604-cbb1e07-NIGHTLY
Minimized code
I couldn't minimize it further. It seems that the combination of recursive inline call and inline pattern matching result being checked in inline if somehow triggers that.
package repro
import compiletime.{constValue, erasedValue}
sealed trait ValidateExprInt
class And[A <: ValidateExprInt, B <: ValidateExprInt] extends ValidateExprInt
class GreaterThan[T <: Int] extends ValidateExprInt
object Repro:
inline def validate[E <: ValidateExprInt](v: Int): String =
inline val failMsg = validateV[E](v)
inline if failMsg == "neverPass" then "neverPass"
else "something else"
transparent inline def validateV[E <: ValidateExprInt](v: Int): String =
inline erasedValue[E] match
case _: GreaterThan[t] =>
"GreaterThan"
case _: And[a, b] =>
inline validateV[a](v) match
case "" =>
validateV[b](v)
case other =>
other
// This one works fine:
transparent inline def validateV_fixed[E <: ValidateExprInt](v: Int): String =
inline erasedValue[E] match
case _: GreaterThan[t] =>
"GreaterThan"
case _: And[a, b] =>
inline val res = validateV[a](v)
inline res match
case "" =>
validateV[b](v)
case _ =>
res
@main def test(): Unit =
println(validate[And[GreaterThan[10], GreaterThan[12]]](5))
Output
Compilation fails with
41 | println(validate[And[GreaterThan[10], GreaterThan[12]]](5))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|Cannot reduce `inline if` because its condition is not a constant value: failMsg.==("neverPass")
| This location contains code that was inlined from Repro.scala:13
Expectation
I would expect the code to compile. If I use validateV_fixed
then the code compiles