Skip to content

Fix #7650: Don't load toplevel definitions in the empty package #7651

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
@@ -2122,11 +2122,20 @@ object SymDenotations {
case pcls :: pobjs1 =>
if (pcls.isCompleting) recur(pobjs1, acc)
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 =>
// Drop members of `Any` and `Object`, as well as top-level definitions
// in the empty package that are not defined in the current run.
val owner = d.symbol.maybeOwner
(owner ne defn.AnyClass) && (owner ne defn.ObjectClass)
(owner ne defn.AnyClass)
&& (owner ne defn.ObjectClass)
&& (
(symbol ne defn.EmptyPackageClass)
|| d.symbol.isDefinedInCurrentRun
|| d.symbol.associatedFile == null
// if a symbol does not have an associated file, assume it is defined
// in the current run anyway. This typically happens for pickling and from
// tasty tests that generate a fresh symbol and then re-use it in the next run.
)
}
recur(pobjs1, acc.union(pmembers))
}
1 change: 1 addition & 0 deletions compiler/test/dotc/run-test-pickling.blacklist
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@ typeclass-derivation2d.scala
typeclass-derivation3.scala
derive-generic.scala
mixin-forwarder-overload
toplevel-defs
t8905
t10889
macros-in-same-project1
1 change: 1 addition & 0 deletions tests/pos/i7650/Test_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@main def Test() = println("hi")
1 change: 1 addition & 0 deletions tests/pos/i7650/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
object Test
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.