diff --git a/compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala b/compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala index 9bd48b7560b5..8d7b074f9b73 100644 --- a/compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala +++ b/compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala @@ -139,15 +139,15 @@ object PickledQuotes { (tdef.symbol, tree.tpe) }.toMap class ReplaceSplicedTyped extends TypeMap() { - override def apply(tp: Type): Type = { - val tp1 = tp match { - case tp: TypeRef => - typeSpliceMap.get(tp.symbol) match - case Some(t) if tp.typeSymbol.hasAnnotation(defn.InternalQuoted_QuoteTypeTagAnnot) => t - case _ => tp - case _ => tp - } - mapOver(tp1) + override def apply(tp: Type): Type = tp match { + case tp: ClassInfo => + tp.derivedClassInfo(classParents = tp.classParents.map(apply)) + case tp: TypeRef => + typeSpliceMap.get(tp.symbol) match + case Some(t) if tp.typeSymbol.hasAnnotation(defn.InternalQuoted_QuoteTypeTagAnnot) => mapOver(t) + case _ => mapOver(tp) + case _ => + mapOver(tp) } } val expansion2 = new TreeTypeMap(new ReplaceSplicedTyped).transform(expr1) diff --git a/tests/pos-macros/i9020-a/Macro_1.scala b/tests/pos-macros/i9020-a/Macro_1.scala new file mode 100644 index 000000000000..b26764654570 --- /dev/null +++ b/tests/pos-macros/i9020-a/Macro_1.scala @@ -0,0 +1,15 @@ +trait Show[T] { + def show(t: T): String +} + +object Show { + inline def deriveWithMacro[T]: Show[T] = ${ impl[T] } + + import quoted._ + def impl[T](using ctx: QuoteContext, tpe: Type[T]): Expr[Show[T]] = + '{ + new Show[T] { + def show(t: T): String = "TODO" + } + } +} diff --git a/tests/pos-macros/i9020-a/Test_2.scala b/tests/pos-macros/i9020-a/Test_2.scala new file mode 100644 index 000000000000..e266eddf54c0 --- /dev/null +++ b/tests/pos-macros/i9020-a/Test_2.scala @@ -0,0 +1,5 @@ +case class Foo(x: String) + +object Bar { + println(Show.deriveWithMacro[Foo].show(Foo(""))) +} diff --git a/tests/pos-macros/i9020-b/Macro_1.scala b/tests/pos-macros/i9020-b/Macro_1.scala new file mode 100644 index 000000000000..2062988d3f00 --- /dev/null +++ b/tests/pos-macros/i9020-b/Macro_1.scala @@ -0,0 +1,15 @@ +trait Show[T] { + def show(t: T): String +} + +object Show { + inline def deriveWithMacro[T]: Show[T] = ${ impl[T] } + + import quoted._ + def impl[T](using ctx: QuoteContext, tpe: Type[T]): Expr[Show[T]] = + '{ + new Show[$tpe] { + def show(t: $tpe): String = "TODO" + } + } +} diff --git a/tests/pos-macros/i9020-b/Test_2.scala b/tests/pos-macros/i9020-b/Test_2.scala new file mode 100644 index 000000000000..e266eddf54c0 --- /dev/null +++ b/tests/pos-macros/i9020-b/Test_2.scala @@ -0,0 +1,5 @@ +case class Foo(x: String) + +object Bar { + println(Show.deriveWithMacro[Foo].show(Foo(""))) +}