From 05d95dde9ac448928e3b6973e21a0f7748c1016f Mon Sep 17 00:00:00 2001 From: Chris Kipp Date: Sun, 14 May 2023 13:00:48 +0200 Subject: [PATCH 1/2] test: add in a regression test for #11706 [skip community_build] closes #11706 --- tests/run/i11706.check | 2 ++ tests/run/i11706.scala | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 tests/run/i11706.check create mode 100644 tests/run/i11706.scala 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..2ba291f74a46 --- /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)]) // ERROR From e657ac837510f5d9a8993a3c3a7f0afde4dfe9bf Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 15 May 2023 08:55:04 +0200 Subject: [PATCH 2/2] Update tests/run/i11706.scala --- tests/run/i11706.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/run/i11706.scala b/tests/run/i11706.scala index 2ba291f74a46..276ee408d266 100644 --- a/tests/run/i11706.scala +++ b/tests/run/i11706.scala @@ -27,4 +27,4 @@ end Trait @main def Test() = println(Obj.length[(Int, Int, String)]) // OK new Trait: - println(length[(Int, Int, String)]) // ERROR + println(length[(Int, Int, String)])