@@ -639,28 +639,21 @@ object Erasure {
639639
640640 val qual1 = typed(tree.qualifier, AnySelectionProto )
641641
642- def mapOwner (sym : Symbol ): Symbol = {
643- // PolyFunction apply Selects will not have a symbol, so deduce the owner
644- // from the typed qual.
645- def polyOwner : Symbol =
646- if (sym.exists || tree.name != nme.apply) NoSymbol
647- else {
648- val owner = qual1.tpe.widen.typeSymbol
649- if (defn.isFunctionClass(owner)) owner else NoSymbol
650- }
651-
652- polyOwner orElse {
642+ def mapOwner (sym : Symbol ): Symbol =
643+ if ! sym.exists && tree.name == nme.apply then
644+ // PolyFunction apply Selects will not have a symbol, so deduce the owner
645+ // from the typed qual.
646+ val owner = qual1.tpe.widen.typeSymbol
647+ if defn.isFunctionClass(owner) then owner else NoSymbol
648+ else
653649 val owner = sym.maybeOwner
654- if ( defn.specialErasure.contains(owner)) {
650+ if defn.specialErasure.contains(owner) then
655651 assert(sym.isConstructor, s " ${sym.showLocated}" )
656652 defn.specialErasure(owner)
657- }
658- else if (defn.isSyntheticFunctionClass(owner))
653+ else if defn.isSyntheticFunctionClass(owner)
659654 defn.erasedFunctionClass(owner)
660655 else
661656 owner
662- }
663- }
664657
665658 val origSym = tree.symbol
666659
@@ -710,7 +703,11 @@ object Erasure {
710703 if (qual1.tpe.derivesFrom(sym.owner) || qual1.isInstanceOf [Super ])
711704 select(qual1, sym)
712705 else
713- recur(cast(qual1, sym.owner.typeRef))
706+ val castTarget = // Avoid inaccessible cast targets, see i8661
707+ if sym.owner.isAccessibleFrom(qual1.tpe)(using preErasureCtx)
708+ then sym.owner.typeRef
709+ else erasure(tree.qualifier.typeOpt.widen)
710+ recur(cast(qual1, castTarget))
714711 }
715712 }
716713
0 commit comments