diff --git a/compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala b/compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala index f66661ab8b79..12ba704eeb1e 100644 --- a/compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala +++ b/compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala @@ -169,12 +169,14 @@ object ExplicitOuter { private def newOuterSym(owner: ClassSymbol, cls: ClassSymbol, name: TermName, flags: FlagSet)(using Context) = { val outerThis = owner.owner.enclosingClass.thisType val outerCls = outerClass(cls) + val prefix = owner.thisType.baseType(cls).normalizedPrefix val target = if (owner == cls) outerCls.appliedRef else outerThis.baseType(outerCls).orElse( - outerCls.typeRef.appliedTo(outerCls.typeParams.map(_ => TypeBounds.empty))) + if prefix == NoPrefix then outerCls.typeRef.appliedTo(outerCls.typeParams.map(_ => TypeBounds.empty)) + else prefix.widen) val info = if (flags.is(Method)) ExprType(target) else target atPhaseNoEarlier(explicitOuterPhase.next) { // outer accessors are entered at explicitOuter + 1, should not be defined before. newSymbol(owner, name, Synthetic | flags, info, coord = cls.coord) diff --git a/tests/pos/i10253.scala b/tests/pos/i10253.scala new file mode 100644 index 000000000000..15f872c59be0 --- /dev/null +++ b/tests/pos/i10253.scala @@ -0,0 +1,9 @@ +object test: + def foo(qc: QC): Unit = + object treeMap extends qc.reflect.TreeMap + +trait QC: + val reflect: Reflection + trait Reflection: + trait TreeMap: + def transformTree: Unit = ??? \ No newline at end of file