diff --git a/tests/neg-macros/i14001/Macro_1.scala b/tests/neg-macros/i14001/Macro_1.scala new file mode 100644 index 000000000000..d1d413b32b37 --- /dev/null +++ b/tests/neg-macros/i14001/Macro_1.scala @@ -0,0 +1,16 @@ +package test +import scala.quoted.* +object Y { + inline def testStuff[T]: T = + ${testStuffImpl} // problem: T inferred to Nothing + // solution add T explicitly + + def testStuffImpl[T: Type](using Quotes): Expr[T] = { + import quotes.reflect.* + + Apply( + Ref(Symbol.requiredMethod("test.A.C.apply")), + List(Literal(IntConstant(1))) + ).asExprOf[T] + } +} diff --git a/tests/neg-macros/i14001/Test_2.scala b/tests/neg-macros/i14001/Test_2.scala new file mode 100644 index 000000000000..a6a613edf8ef --- /dev/null +++ b/tests/neg-macros/i14001/Test_2.scala @@ -0,0 +1,10 @@ +package test +trait B { + case class C(i: Int) +} + +object A extends B + +object X { + val z = Y.testStuff[A.C] // error: Expr cast exception +}