Skip to content

Fix #6210: Erase type blocks in Typed trees #6221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions compiler/src/dotty/tools/dotc/transform/Erasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,13 @@ object Erasure {
/** This override is only needed to semi-erase type ascriptions */
override def typedTyped(tree: untpd.Typed, pt: Type)(implicit ctx: Context): Tree = {
val Typed(expr, tpt) = tree
val tpt1 = promote(tpt)
val expr1 = typed(expr, tpt1.tpe)
assignType(untpd.cpy.Typed(tree)(expr1, tpt1), tpt1)
val tpt1 = tpt match {
case Block(_, tpt) => tpt // erase type aliases (statements) from type block
case tpt => tpt
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problematic Typed.tpt is inserted in TypeTestsCasts.scala#L236, this case could also be handled there.

val tpt2 = promote(tpt1)
val expr1 = typed(expr, tpt2.tpe)
assignType(untpd.cpy.Typed(tree)(expr1, tpt2), tpt2)
}

override def typedLiteral(tree: untpd.Literal)(implicit ctx: Context): Tree =
Expand Down
14 changes: 14 additions & 0 deletions tests/pos/i6210/Macros_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import scala.quoted._

object Macro {
inline def test[A, B]: Any =
${ impl[A, B] }

def impl[A : Type, B : Type]: Expr[Any] = {
val t = '[Map[A, B]]
'{
new Object().asInstanceOf[$t]
???.asInstanceOf[$t]
}
}
}
5 changes: 5 additions & 0 deletions tests/pos/i6210/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
object Test {
type T
def t1 = Macro.test[Int, String]
def t2 = Macro.test[Test.type, T]
}