diff --git a/compiler/src/dotty/tools/dotc/ast/tpd.scala b/compiler/src/dotty/tools/dotc/ast/tpd.scala index 4779854e51e4..80e9367f5681 100644 --- a/compiler/src/dotty/tools/dotc/ast/tpd.scala +++ b/compiler/src/dotty/tools/dotc/ast/tpd.scala @@ -1253,15 +1253,15 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { def desugarIdent(tree: Ident)(implicit ctx: Context): Tree = { val qual = desugarIdentPrefix(tree) if (qual.isEmpty) tree - else qual.select(tree.symbol) + else qual.select(tree.symbol).withSpan(tree.span) } /** Recover identifier prefix (e.g. this) if it exists */ def desugarIdentPrefix(tree: Ident)(implicit ctx: Context): Tree = tree.tpe match { case TermRef(prefix: TermRef, _) => - ref(prefix) + ref(prefix).withSpan(tree.span) case TermRef(prefix: ThisType, _) => - This(prefix.cls) + This(prefix.cls).withSpan(tree.span) case _ => EmptyTree } diff --git a/compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala b/compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala index 548dba2f4de9..a1a015c22883 100644 --- a/compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala +++ b/compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala @@ -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 @@ -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 = { @@ -306,9 +308,13 @@ 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 => desugarIdentPrefix(i) + case _ => EmptyTree } + interceptWith(expr) } } diff --git a/tests/pending/fuzzy/RE-96bd93de803119f21ab5d429b0ce0793869d86c5.scala b/tests/fuzzy/RE-96bd93de803119f21ab5d429b0ce0793869d86c5.scala similarity index 100% rename from tests/pending/fuzzy/RE-96bd93de803119f21ab5d429b0ce0793869d86c5.scala rename to tests/fuzzy/RE-96bd93de803119f21ab5d429b0ce0793869d86c5.scala diff --git a/tests/pending/fuzzy/RE-d341ba7adb385e80fb9955ca9161dd8f86ad3584.scala b/tests/fuzzy/RE-d341ba7adb385e80fb9955ca9161dd8f86ad3584.scala similarity index 100% rename from tests/pending/fuzzy/RE-d341ba7adb385e80fb9955ca9161dd8f86ad3584.scala rename to tests/fuzzy/RE-d341ba7adb385e80fb9955ca9161dd8f86ad3584.scala diff --git a/tests/pos/i5006.scala b/tests/pos/i5006.scala new file mode 100644 index 000000000000..1bd37e00d765 --- /dev/null +++ b/tests/pos/i5006.scala @@ -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 +}