diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index 185c5fad2625..9ffba313ed0f 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -2031,7 +2031,15 @@ object SymDenotations { def recur(pobjs: List[ClassDenotation], acc: PreDenotation): PreDenotation = pobjs match { case pcls :: pobjs1 => if (pcls.isCompleting) recur(pobjs1, acc) - else recur(pobjs1, acc.union(pcls.computeNPMembersNamed(name))) + else { + // A package object inherits members from `Any` and `Object` which + // should not be accessible from the package prefix. + val pmembers = pcls.computeNPMembersNamed(name).filterWithPredicate { d => + val owner = d.symbol.maybeOwner + (owner ne defn.AnyClass) && (owner ne defn.ObjectClass) + } + recur(pobjs1, acc.union(pmembers)) + } case nil => val directMembers = super.computeNPMembersNamed(name) if (acc.exists) acc.union(directMembers.filterWithPredicate(!_.symbol.isAbsent)) diff --git a/tests/neg/i6242.scala b/tests/neg/i6242.scala new file mode 100644 index 000000000000..31e8293d7f06 --- /dev/null +++ b/tests/neg/i6242.scala @@ -0,0 +1,7 @@ +package object foo { + val x = 1 +} +object Test { + foo.eq(???) // error + foo.==(???) // error +}