@@ -408,11 +408,16 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
408408 // Does reference `tp` refer only to inherited symbols?
409409 def isInherited (denot : Denotation ) =
410410 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 )
412412 denot match
413413 case denot : SingleDenotation => ! isCurrent(denot)
414414 case denot => ! denot.hasAltWith(isCurrent)
415415
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+ */
416421 def checkNoOuterDefs (denot : Denotation , last : Context , prevCtx : Context ): Unit =
417422 def sameTermOrType (d1 : SingleDenotation , d2 : Denotation ) =
418423 d2.containsSym(d1.symbol) || d2.hasUniqueSym && {
@@ -429,9 +434,15 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
429434 val owner = outer.owner
430435 if (owner eq last.owner) && (outer.scope eq last.scope) then
431436 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 )
435446 if competing.exists then
436447 val symsMatch = competing
437448 .filterWithPredicate(sd => sameTermOrType(sd, denot))
0 commit comments