diff --git a/tests/run/i11706.check b/tests/run/i11706.check new file mode 100644 index 000000000000..a5c8806279fa --- /dev/null +++ b/tests/run/i11706.check @@ -0,0 +1,2 @@ +3 +3 diff --git a/tests/run/i11706.scala b/tests/run/i11706.scala new file mode 100644 index 000000000000..276ee408d266 --- /dev/null +++ b/tests/run/i11706.scala @@ -0,0 +1,30 @@ +// https://github.com/lampepfl/dotty/issues/11706 +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 Test() = + println(Obj.length[(Int, Int, String)]) // OK + new Trait: + println(length[(Int, Int, String)])