@@ -667,8 +667,18 @@ object Erasure {
667
667
def mapOwner (sym : Symbol ): Symbol =
668
668
if ! sym.exists && tree.name == nme.apply then
669
669
// PolyFunction apply Selects will not have a symbol, so deduce the owner
670
- // from the typed the erasure of the original qualifier.
671
- val owner = erasure(tree.qualifier.typeOpt).typeSymbol
670
+ // from the typed tree of the erasure of the original qualifier's PolyFunction type.
671
+ // Need to sidestep information loss in the erasure of AndTypes, see pos/i13950.scala.
672
+ val polyFunctionQualType = inContext(preErasureCtx) {
673
+ def narrowToPolyFun (tp : Type )(using Context ): Type =
674
+ if tp.derivesFrom(defn.PolyFunctionClass ) then
675
+ tp match
676
+ case AndType (tp1, tp2) => narrowToPolyFun(tp1).orElse(narrowToPolyFun(tp2))
677
+ case _ => tp
678
+ else NoType
679
+ narrowToPolyFun(tree.qualifier.typeOpt.widen)
680
+ }
681
+ val owner = erasure(polyFunctionQualType).typeSymbol
672
682
if defn.isFunctionClass(owner) then owner else NoSymbol
673
683
else
674
684
val owner = sym.maybeOwner
@@ -687,7 +697,7 @@ object Erasure {
687
697
688
698
val owner = mapOwner(origSym)
689
699
val sym = if (owner eq origSym.maybeOwner) origSym else owner.info.decl(tree.name).symbol
690
- assert(sym.exists, origSym.showLocated)
700
+ assert(sym.exists, i " no owner from $owner / ${ origSym.showLocated} in $tree " )
691
701
692
702
if owner == defn.ObjectClass then checkValue(qual1)
693
703
0 commit comments