From 4a85ec646f5cee52693d897e4fba810868f65ef0 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 9 Feb 2023 10:18:19 +0100 Subject: [PATCH] Add regression test Fixes #15475 --- tests/pos-macros/i15475.scala | 13 +++++++++++++ tests/pos-macros/i15475a/Macro_1.scala | 17 +++++++++++++++++ tests/pos-macros/i15475a/Test_2.scala | 15 +++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 tests/pos-macros/i15475.scala create mode 100644 tests/pos-macros/i15475a/Macro_1.scala create mode 100644 tests/pos-macros/i15475a/Test_2.scala diff --git a/tests/pos-macros/i15475.scala b/tests/pos-macros/i15475.scala new file mode 100644 index 000000000000..48fd6d626515 --- /dev/null +++ b/tests/pos-macros/i15475.scala @@ -0,0 +1,13 @@ +def test = + transform { + val a: Seq[Generic[?]] = ??? + a.foreach { to => + to.mthd() + } + } + +transparent inline def transform[T](expr: T): T = ??? // if we add inline to param, it doesn't crash + +trait Generic[+T] { // both covariance and contravariance cause a crash (invariance doesn't) + def mthd(): Generic[T] = ??? // has to have a parameter list to crash +} diff --git a/tests/pos-macros/i15475a/Macro_1.scala b/tests/pos-macros/i15475a/Macro_1.scala new file mode 100644 index 000000000000..b1bd676e7e17 --- /dev/null +++ b/tests/pos-macros/i15475a/Macro_1.scala @@ -0,0 +1,17 @@ +package x + +import scala.quoted.* + + +transparent inline def xtransform[T](inline expr:T) = ${ + X.transform('expr) +} + +object X { + + def transform[T:Type](x: Expr[T])(using Quotes):Expr[T] = { + import quotes.reflect.* + x + } + +} diff --git a/tests/pos-macros/i15475a/Test_2.scala b/tests/pos-macros/i15475a/Test_2.scala new file mode 100644 index 000000000000..7757a14950de --- /dev/null +++ b/tests/pos-macros/i15475a/Test_2.scala @@ -0,0 +1,15 @@ +package x + +def hello = { + xtransform { + val a: Seq[Generic[?]] = null + a + .foreach { to => + to.mthd() + } + } +} + +trait Generic[+T] { + def mthd(): Generic[T] = this +}