You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
packagereproimportcompiletime.{constValue, erasedValue}
sealedtraitValidateExprIntclassAnd[A<:ValidateExprInt, B<:ValidateExprInt] extendsValidateExprIntclassGreaterThan[T<:Int] extendsValidateExprIntobjectRepro:inlinedefvalidate[E<:ValidateExprInt](v: Int):String=inlinevalfailMsg= validateV[E](v)
inlineif failMsg =="neverPass"then"neverPass"else"something else"transparentinlinedefvalidateV[E<:ValidateExprInt](v: Int):String=inline erasedValue[E] matchcase_: GreaterThan[t] =>"GreaterThan"case_: And[a, b] =>inline validateV[a](v) matchcase""=>
validateV[b](v)
case other =>
other
// This one works fine:transparentinlinedefvalidateV_fixed[E<:ValidateExprInt](v: Int):String=inline erasedValue[E] matchcase_: GreaterThan[t] =>"GreaterThan"case_: And[a, b] =>inlinevalres= validateV[a](v)
inline res matchcase""=>
validateV[b](v)
case _ =>
res
@main deftest():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
The text was updated successfully, but these errors were encountered:
transparentinlinedeff:String=inline10matchcase _ =>inline"foo"matchcase x => x
deftest=inlinevalfailMsg= f
Error:
-- Error: /Users/kmetiuk/Projects/scala3/playground/wip/Bad.scala:8:23 ---------
8 | inline val failMsg = f
| ^
| inline value must have a literal constant type
1 error found
Compiling example:
transparentinlinedeff:String=inline10matchcase _ =>inlinevalx="foo"inline x matchcase _ => x
deftest=inlinevalfailMsg= f
Apparently the case x => x loses the precise type of x and hence the compiler doesn't know that the result of that transparent inline is a "literal constant type".
Uh oh!
There was an error while loading. Please reload this page.
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.
Output
Compilation fails with
Expectation
I would expect the code to compile. If I use
validateV_fixed
then the code compilesThe text was updated successfully, but these errors were encountered: