Skip to content

Commit 4f1dd8f

Browse files
Merge pull request #9198 from dotty-staging/fix-#9020
Fix #9020: Handle spliced types in parents
2 parents e0de959 + 8198f1f commit 4f1dd8f

File tree

5 files changed

+49
-9
lines changed

5 files changed

+49
-9
lines changed

compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,15 @@ object PickledQuotes {
139139
(tdef.symbol, tree.tpe)
140140
}.toMap
141141
class ReplaceSplicedTyped extends TypeMap() {
142-
override def apply(tp: Type): Type = {
143-
val tp1 = tp match {
144-
case tp: TypeRef =>
145-
typeSpliceMap.get(tp.symbol) match
146-
case Some(t) if tp.typeSymbol.hasAnnotation(defn.InternalQuoted_QuoteTypeTagAnnot) => t
147-
case _ => tp
148-
case _ => tp
149-
}
150-
mapOver(tp1)
142+
override def apply(tp: Type): Type = tp match {
143+
case tp: ClassInfo =>
144+
tp.derivedClassInfo(classParents = tp.classParents.map(apply))
145+
case tp: TypeRef =>
146+
typeSpliceMap.get(tp.symbol) match
147+
case Some(t) if tp.typeSymbol.hasAnnotation(defn.InternalQuoted_QuoteTypeTagAnnot) => mapOver(t)
148+
case _ => mapOver(tp)
149+
case _ =>
150+
mapOver(tp)
151151
}
152152
}
153153
val expansion2 = new TreeTypeMap(new ReplaceSplicedTyped).transform(expr1)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
trait Show[T] {
2+
def show(t: T): String
3+
}
4+
5+
object Show {
6+
inline def deriveWithMacro[T]: Show[T] = ${ impl[T] }
7+
8+
import quoted._
9+
def impl[T](using ctx: QuoteContext, tpe: Type[T]): Expr[Show[T]] =
10+
'{
11+
new Show[T] {
12+
def show(t: T): String = "TODO"
13+
}
14+
}
15+
}

tests/pos-macros/i9020-a/Test_2.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
case class Foo(x: String)
2+
3+
object Bar {
4+
println(Show.deriveWithMacro[Foo].show(Foo("")))
5+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
trait Show[T] {
2+
def show(t: T): String
3+
}
4+
5+
object Show {
6+
inline def deriveWithMacro[T]: Show[T] = ${ impl[T] }
7+
8+
import quoted._
9+
def impl[T](using ctx: QuoteContext, tpe: Type[T]): Expr[Show[T]] =
10+
'{
11+
new Show[$tpe] {
12+
def show(t: $tpe): String = "TODO"
13+
}
14+
}
15+
}

tests/pos-macros/i9020-b/Test_2.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
case class Foo(x: String)
2+
3+
object Bar {
4+
println(Show.deriveWithMacro[Foo].show(Foo("")))
5+
}

0 commit comments

Comments
 (0)