@@ -366,11 +366,16 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
366366 // Does reference `tp` refer only to inherited symbols?
367367 def isInherited (denot : Denotation ) =
368368 def isCurrent (mbr : SingleDenotation ): Boolean =
369- ! mbr.symbol.exists || mbr.symbol.owner == ctx.owner
369+ ! mbr.symbol.exists || mbr.symbol.owner == ctx.owner || ctx.owner.is( Package )
370370 denot match
371371 case denot : SingleDenotation => ! isCurrent(denot)
372372 case denot => ! denot.hasAltWith(isCurrent)
373373
374+ /* It is an error if an identifier x is available as an inherited member in an inner scope
375+ * and the same name x is defined in an outer scope in the same source file, unless
376+ * the inherited member (has an overloaded alternative that) coincides with
377+ * (an overloaded alternative of) the definition x.
378+ */
374379 def checkNoOuterDefs (denot : Denotation , last : Context , prevCtx : Context ): Unit =
375380 def sameTermOrType (d1 : SingleDenotation , d2 : Denotation ) =
376381 d2.containsSym(d1.symbol) || d2.hasUniqueSym && {
@@ -387,9 +392,15 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
387392 val owner = outer.owner
388393 if (owner eq last.owner) && (outer.scope eq last.scope) then
389394 checkNoOuterDefs(denot, outer, prevCtx)
390- else if ! owner.is(Package ) then
391- val scope = if owner.isClass then owner.info.decls else outer.scope
392- val competing = scope.denotsNamed(name).filterWithFlags(required, excluded)
395+ else if ! owner.isRoot then
396+ val found =
397+ if owner.is(Package ) then
398+ owner.denot.asClass.membersNamed(name)
399+ .filterWithPredicate(d => ! d.symbol.is(Package ) && d.symbol.source == denot.symbol.source)
400+ else
401+ val scope = if owner.isClass then owner.info.decls else outer.scope
402+ scope.denotsNamed(name)
403+ val competing = found.filterWithFlags(required, excluded | Synthetic )
393404 if competing.exists then
394405 val symsMatch = competing
395406 .filterWithPredicate(sd => sameTermOrType(sd, denot))
0 commit comments