@@ -153,19 +153,32 @@ class Typer extends Namer
153
153
if ! suppressErrors then report.error(msg, pos)
154
154
155
155
/** A symbol qualifies if it really exists and is not a package class.
156
- * In addition, if we are in a constructor of a pattern, we ignore all definitions
157
- * which are methods and not accessors (note: if we don't do that
158
- * case x :: xs in class List would return the :: method).
159
- *
160
156
* Package classes are part of their parent's scope, because otherwise
161
157
* we could not reload them via `_.member`. On the other hand, accessing a
162
158
* package as a type from source is always an error.
159
+
160
+ * In addition:
161
+ * - if we are in a constructor of a pattern, we ignore all definitions
162
+ * which are methods and not accessors (note: if we don't do that
163
+ * case x :: xs in class List would return the :: method).
164
+ * - Members of the empty package can be accessed only from within the empty package.
165
+ * Note: it would be cleaner to never nest package definitions in empty package definitions,
166
+ * but then we'd have to give up the fiction that a compilation unit consists of
167
+ * a single tree (because a source file may have both toplevel classes which go
168
+ * into the empty package and package definitions, which would have to stay outside).
169
+ * Since the principle of a single tree per compilation unit is assumed by many
170
+ * tools, we did not want to take that step.
163
171
*/
164
172
def qualifies (denot : Denotation ): Boolean =
165
173
reallyExists(denot)
166
174
&& (! pt.isInstanceOf [UnapplySelectionProto ]
167
175
|| denot.hasAltWith(sd => ! sd.symbol.is(Method , butNot = Accessor )))
168
176
&& ! denot.symbol.is(PackageClass )
177
+ && {
178
+ var owner = denot.symbol.maybeOwner
179
+ if owner.isPackageObject then owner = owner.owner
180
+ ! owner.isEmptyPackage || ctx.owner.enclosingPackageClass.isEmptyPackage
181
+ }
169
182
170
183
/** Find the denotation of enclosing `name` in given context `ctx`.
171
184
* @param previous A denotation that was found in a more deeply nested scope,
0 commit comments