Skip to content

Commit 860c96b

Browse files
committed
Clarify PolyFunction apply owner logic in erasure.
1 parent 956794e commit 860c96b

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -415,24 +415,28 @@ object Erasure {
415415
* e.m -> e.[]m if `m` is an array operation other than `clone`.
416416
*/
417417
override def typedSelect(tree: untpd.Select, pt: Type)(implicit ctx: Context): Tree = {
418-
419418
val qual1 = typed(tree.qualifier, AnySelectionProto)
420419

421420
def mapOwner(sym: Symbol): Symbol = {
422-
def recur(owner: Symbol): Symbol = {
423-
val owner = sym.maybeOwner
424-
if (!owner.exists) {
425-
// Hack for PolyFunction#apply
426-
qual1.tpe.widen.typeSymbol
427-
} else if (defn.specialErasure.contains(owner)) {
421+
// PolyFunction apply Selects will not have a symbol, so deduce the owner
422+
// from the typed qual.
423+
def polyOwner: Symbol =
424+
if (sym.exists || tree.name != nme.apply) NoSymbol
425+
else {
426+
val owner = qual1.tpe.widen.typeSymbol
427+
if (defn.isFunctionClass(owner)) owner else NoSymbol
428+
}
429+
430+
polyOwner orElse {
431+
val owner = sym.owner
432+
if (defn.specialErasure.contains(owner)) {
428433
assert(sym.isConstructor, s"${sym.showLocated}")
429434
defn.specialErasure(owner)
430435
} else if (defn.isSyntheticFunctionClass(owner))
431436
defn.erasedFunctionClass(owner)
432437
else
433438
owner
434439
}
435-
recur(sym.maybeOwner)
436440
}
437441

438442
val origSym = tree.symbol

0 commit comments

Comments
 (0)