Closed
Description
Compiler version
3.0.0
Minimized code
package bugreport
import scala.compiletime.erasedValue
object Obj:
inline def length[Tuple]: Int = loop[Tuple]
private inline def loop[Tuple]: Int =
inline erasedValue[Tuple] match
case _: EmptyTuple => 0
case _: (head *: tail) => 1 + loop[tail]
end Obj
// Same code, but in a trait instead of an object
trait Trait:
inline def length[Tuple]: Int = loop[Tuple]
private inline final def loop[Tuple]: Int =
inline erasedValue[Tuple] match
case _: EmptyTuple => 0
case _: (head *: tail) => 1 + loop[tail]
end Trait
@main def run() =
println(Obj.length[(Int, Int, String)]) // OK
new Trait:
println(length[(Int, Int, String)]) // ERROR
Output
[error] -- Error: bugreport.scala:18:38
[error] 18 | inline def length[Tuple]: Int = loop[Tuple]
[error] | ^^^^^^^^^^^
[error] |undefined: Trait_this.loop # -1: TermRef(TermRef(NoPrefix,val Trait_this),loop) at inlining
When I call the variant in the trait, I get this error. But the same code works fine with an object.
Expectation
Both versions work.