Skip to content

Commit f4b576b

Browse files
Merge pull request #6888 from dotty-staging/fix-#5006-2
Fix #5006: Normalize prefixes of TypeApply in Erasure
2 parents 54b08e1 + 499fae2 commit f4b576b

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,10 @@ object TypeTestsCasts {
156156
}
157157

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

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

174176
def inMatch =
175-
fun.symbol == defn.Any_typeTest || // new scheme
177+
tree.fun.symbol == defn.Any_typeTest || // new scheme
176178
expr.symbol.is(Case) // old scheme
177179

178180
def transformIsInstanceOf(expr: Tree, testType: Type, flagUnrelated: Boolean): Tree = {
@@ -306,9 +308,16 @@ object TypeTestsCasts {
306308
else if (sym.isTypeCast)
307309
transformAsInstanceOf(erasure(tree.args.head.tpe))
308310
else tree
309-
310-
case _ =>
311-
tree
311+
}
312+
}
313+
val expr = tree.fun match {
314+
case Select(expr, _) => expr
315+
case i: Ident =>
316+
val expr = desugarIdentPrefix(i)
317+
if (expr.isEmpty) expr
318+
else expr.withSpan(i.span)
319+
case _ => EmptyTree
312320
}
321+
interceptWith(expr)
313322
}
314323
}

tests/pos/i5006.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
object i0 {
2+
def f: Int = asInstanceOf[Int].toInt
3+
}
4+
5+
class i2 {
6+
def f: Int = asInstanceOf[Int].toInt
7+
}
8+
9+
trait i3 {
10+
def f: Int = asInstanceOf[Int].toInt
11+
}

0 commit comments

Comments
 (0)