Skip to content

Fix #5006: Normalize prefixes of TypeApply in Erasure #6888

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 3 commits into from
Jul 22, 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
21 changes: 15 additions & 6 deletions compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,10 @@ object TypeTestsCasts {
}

def interceptTypeApply(tree: TypeApply)(implicit ctx: Context): Tree = trace(s"transforming ${tree.show}", show = true) {
tree.fun match {
case fun @ Select(expr, selector) =>
/** Intercept `expr.xyz[XYZ]` */
def interceptWith(expr: Tree): Tree = {
if (expr.isEmpty) tree
else {
val sym = tree.symbol

def isPrimitive(tp: Type) = tp.classSymbol.isPrimitiveValueClass
Expand All @@ -172,7 +174,7 @@ object TypeTestsCasts {
def foundCls = effectiveClass(expr.tpe.widen)

def inMatch =
fun.symbol == defn.Any_typeTest || // new scheme
tree.fun.symbol == defn.Any_typeTest || // new scheme
expr.symbol.is(Case) // old scheme

def transformIsInstanceOf(expr: Tree, testType: Type, flagUnrelated: Boolean): Tree = {
Expand Down Expand Up @@ -306,9 +308,16 @@ object TypeTestsCasts {
else if (sym.isTypeCast)
transformAsInstanceOf(erasure(tree.args.head.tpe))
else tree

case _ =>
tree
}
}
val expr = tree.fun match {
case Select(expr, _) => expr
case i: Ident =>
val expr = desugarIdentPrefix(i)
if (expr.isEmpty) expr
else expr.withSpan(i.span)
case _ => EmptyTree
}
interceptWith(expr)
}
}
11 changes: 11 additions & 0 deletions tests/pos/i5006.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
object i0 {
def f: Int = asInstanceOf[Int].toInt
}

class i2 {
def f: Int = asInstanceOf[Int].toInt
}

trait i3 {
def f: Int = asInstanceOf[Int].toInt
}