Skip to content

Commit e505c88

Browse files
committed
Fix #6210: Erase type blocks in Typed trees
Type blocks of the for `{ type T1 = X1; ... ; type Tn = Xn; F[T1,..., Tn] }` are erased to `F[X1,..., Xn]`. We where erasing the type of the tree correctly but needed to drop the block as well.
1 parent abd0c56 commit e505c88

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

compiler/src/dotty/tools/dotc/transform/Erasure.scala

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,13 @@ object Erasure {
358358
/** This override is only needed to semi-erase type ascriptions */
359359
override def typedTyped(tree: untpd.Typed, pt: Type)(implicit ctx: Context): Tree = {
360360
val Typed(expr, tpt) = tree
361-
val tpt1 = promote(tpt)
362-
val expr1 = typed(expr, tpt1.tpe)
363-
assignType(untpd.cpy.Typed(tree)(expr1, tpt1), tpt1)
361+
val tpt1 = tpt match {
362+
case Block(_, tpt) => tpt // erase type aliases (statements) from type block
363+
case tpt => tpt
364+
}
365+
val tpt2 = promote(tpt1)
366+
val expr1 = typed(expr, tpt2.tpe)
367+
assignType(untpd.cpy.Typed(tree)(expr1, tpt2), tpt2)
364368
}
365369

366370
override def typedLiteral(tree: untpd.Literal)(implicit ctx: Context): Tree =

tests/pos/i6210/Macros_1.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import scala.quoted._
2+
3+
object Macro {
4+
inline def test[A, B]: Any =
5+
${ impl[A, B] }
6+
7+
def impl[A : Type, B : Type]: Expr[Any] = {
8+
val t = '[Map[A, B]]
9+
'{
10+
new Object().asInstanceOf[$t]
11+
???.asInstanceOf[$t]
12+
}
13+
}
14+
}

tests/pos/i6210/Test_2.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
object Test {
2+
type T
3+
def t1 = Macro.test[Int, String]
4+
def t2 = Macro.test[Test.type, T]
5+
}

0 commit comments

Comments
 (0)