@@ -418,7 +418,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
418
418
* the inherited member (has an overloaded alternative that) coincides with
419
419
* (an overloaded alternative of) the definition x.
420
420
*/
421
- def checkNoOuterDefs (denot : Denotation , last : Context , prevCtx : Context ): Unit =
421
+ def checkNoOuterDefs (denot : Denotation , ctx : Context , origCtx : Context ): Unit =
422
422
def sameTermOrType (d1 : SingleDenotation , d2 : Denotation ) =
423
423
d2.containsSym(d1.symbol) || d2.hasUniqueSym && {
424
424
val sym1 = d1.symbol
@@ -430,19 +430,23 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
430
430
else
431
431
(sym1.isAliasType || sym2.isAliasType) && d1.info =:= d2.info
432
432
}
433
- val outer = last .outer
434
- val owner = outer .owner
435
- if (owner eq last .owner) && (outer .scope eq last .scope) then
436
- checkNoOuterDefs(denot, outer, prevCtx )
437
- else if ! owner .isRoot then
433
+ val outerCtx = ctx .outer
434
+ val outerOwner = outerCtx .owner
435
+ if (outerOwner eq ctx .owner) && (outerCtx .scope eq ctx .scope) then
436
+ checkNoOuterDefs(denot, outerCtx, origCtx )
437
+ else if ! outerOwner .isRoot then
438
438
val found =
439
- if owner.is(Package ) then
440
- owner.denot.asClass.membersNamed(name)
439
+ if outerOwner.is(Package ) then
440
+ def notInPackageObject (sym : Symbol ) =
441
+ sym.owner == outerOwner || // sym.owner.isPackageObject is false if sym is defined in a parent of the package object
442
+ sym.owner.isPackageObject && sym.owner.name.endsWith(str.TOPLEVEL_SUFFIX ) // top-level definitions
443
+ outerOwner.denot.asClass.membersNamed(name)
441
444
.filterWithPredicate(d => ! d.symbol.is(Package )
445
+ && notInPackageObject(d.symbol)
442
446
&& d.symbol.source.exists
443
447
&& isDefinedInCurrentUnit(d))
444
448
else
445
- val scope = if owner .isClass then owner .info.decls else outer .scope
449
+ val scope = if outerOwner .isClass then outerOwner .info.decls else outerCtx .scope
446
450
scope.denotsNamed(name)
447
451
val competing = found.filterWithFlags(required, excluded | Synthetic )
448
452
if competing.exists then
@@ -451,14 +455,14 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
451
455
.exists
452
456
if ! symsMatch && ! suppressErrors then
453
457
report.errorOrMigrationWarning(
454
- AmbiguousReference (name, Definition , Inheritance , prevCtx )(using outer ),
458
+ AmbiguousReference (name, Definition , Inheritance , origCtx )(using outerCtx ),
455
459
pos, from = `3.0`)
456
460
if migrateTo3 then
457
461
patch(Span (pos.span.start),
458
- if prevCtx .owner == refctx.owner.enclosingClass then " this."
459
- else s " ${prevCtx .owner.name}.this. " )
462
+ if origCtx .owner == refctx.owner.enclosingClass then " this."
463
+ else s " ${origCtx .owner.name}.this. " )
460
464
else
461
- checkNoOuterDefs(denot, outer, prevCtx )
465
+ checkNoOuterDefs(denot, outerCtx, origCtx )
462
466
463
467
if isNewDefScope then
464
468
val defDenot = ctx.denotNamed(name, required, excluded)
0 commit comments