@@ -408,11 +408,16 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
408
408
// Does reference `tp` refer only to inherited symbols?
409
409
def isInherited (denot : Denotation ) =
410
410
def isCurrent (mbr : SingleDenotation ): Boolean =
411
- ! mbr.symbol.exists || mbr.symbol.owner == ctx.owner
411
+ ! mbr.symbol.exists || mbr.symbol.owner == ctx.owner || ctx.owner.is( Package )
412
412
denot match
413
413
case denot : SingleDenotation => ! isCurrent(denot)
414
414
case denot => ! denot.hasAltWith(isCurrent)
415
415
416
+ /* It is an error if an identifier x is available as an inherited member in an inner scope
417
+ * and the same name x is defined in an outer scope in the same source file, unless
418
+ * the inherited member (has an overloaded alternative that) coincides with
419
+ * (an overloaded alternative of) the definition x.
420
+ */
416
421
def checkNoOuterDefs (denot : Denotation , last : Context , prevCtx : Context ): Unit =
417
422
def sameTermOrType (d1 : SingleDenotation , d2 : Denotation ) =
418
423
d2.containsSym(d1.symbol) || d2.hasUniqueSym && {
@@ -429,9 +434,15 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
429
434
val owner = outer.owner
430
435
if (owner eq last.owner) && (outer.scope eq last.scope) then
431
436
checkNoOuterDefs(denot, outer, prevCtx)
432
- else if ! owner.is(Package ) then
433
- val scope = if owner.isClass then owner.info.decls else outer.scope
434
- val competing = scope.denotsNamed(name).filterWithFlags(required, excluded)
437
+ else if ! owner.isRoot then
438
+ val found =
439
+ if owner.is(Package ) then
440
+ owner.denot.asClass.membersNamed(name)
441
+ .filterWithPredicate(d => ! d.symbol.is(Package ) && d.symbol.source == denot.symbol.source)
442
+ else
443
+ val scope = if owner.isClass then owner.info.decls else outer.scope
444
+ scope.denotsNamed(name)
445
+ val competing = found.filterWithFlags(required, excluded | Synthetic )
435
446
if competing.exists then
436
447
val symsMatch = competing
437
448
.filterWithPredicate(sd => sameTermOrType(sd, denot))
0 commit comments