Skip to content

Commit ca22cd8

Browse files
committed
Fix #2856: Prioritize root package members over root imports
The fix is more complex than I would like (see comment in source code). If someone can reproduce the error locally without this commit and rack it down this would help enormously. (reverted from commit f50bf57)
1 parent f50bf57 commit ca22cd8

File tree

1 file changed

+1
-20
lines changed

1 file changed

+1
-20
lines changed

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

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -243,27 +243,8 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
243243
if (ctx.scope == null) previous
244244
else {
245245
var result: Type = NoType
246-
247246
val curOwner = ctx.owner
248-
249-
// Can this scope contain new definitions? This is usually the first
250-
// context where either the scope or the owner changes wrt the
251-
// context immediately nested in it. But for package contexts, it's
252-
// the opposite: the last context before the package changes. This distinction
253-
// is made so that top-level imports following a package clause are
254-
// logically nested in that package clause. Finally, for the root package
255-
// we switch back to the original test. This means that rop-level packages in
256-
// the root package take priority over root imports. For instance,
257-
// a top-level io package takes priority over scala.io.
258-
// It would be nice if we could drop all this complication, and
259-
// always use the second condition. Unfortunately compileStdLib breaks
260-
// with an error on CI which I cannot replicate locally (not even
261-
// with the exact list of files given).
262-
val isNewDefScope =
263-
if (curOwner.is(Package) && !curOwner.isRoot) curOwner ne ctx.outer.owner
264-
else (ctx.scope ne lastCtx.scope) || (curOwner ne lastCtx.owner)
265-
266-
if (isNewDefScope) {
247+
if ((ctx.scope ne lastCtx.scope) || (curOwner ne lastCtx.owner)) {
267248
val defDenot = ctx.denotNamed(name)
268249
if (qualifies(defDenot)) {
269250
val found =

0 commit comments

Comments
 (0)