Skip to content

Commit 402d71c

Browse files
committed
Also make non-class definitions invisible
Also make toplevel non-class definitions in the empty package invisible from nested packages.
1 parent e7671a9 commit 402d71c

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,19 @@ class Typer extends Namer
166166
* but then we'd have to give up the fiction that a compilation unit consists of
167167
* a single tree (because a source file may have both toplevel classes which go
168168
* into the empty package and package definitions, which would have to stay outside).
169-
* Since the concept of a single tree per compilation unit is known to many
169+
* Since the principle of a single tree per compilation unit is assumed by many
170170
* tools, we did not want to take that step.
171171
*/
172172
def qualifies(denot: Denotation): Boolean =
173173
reallyExists(denot)
174174
&& (!pt.isInstanceOf[UnapplySelectionProto]
175175
|| denot.hasAltWith(sd => !sd.symbol.is(Method, butNot = Accessor)))
176176
&& !denot.symbol.is(PackageClass)
177-
&& (!denot.symbol.maybeOwner.isEmptyPackage || ctx.owner.enclosingPackageClass.isEmptyPackage)
177+
&& {
178+
var owner = denot.symbol.maybeOwner
179+
if owner.isPackageObject then owner = owner.owner
180+
!owner.isEmptyPackage || ctx.owner.enclosingPackageClass.isEmptyPackage
181+
}
178182

179183
/** Find the denotation of enclosing `name` in given context `ctx`.
180184
* @param previous A denotation that was found in a more deeply nested scope,

tests/neg/i7891.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// was previously ok in one compilation unit
2+
def f22 = "hello, world"
3+
4+
package p {
5+
@main def m = println(f22) // error
6+
}

0 commit comments

Comments
 (0)