Skip to content

Commit a55a260

Browse files
authored
Merge pull request #1657 from dotty-staging/fix-#1638
Fix #1638: Don't import when typing a package clause
2 parents 56f6933 + 8c857cd commit a55a260

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

src/dotty/tools/dotc/core/Mode.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,9 @@ object Mode {
8181
val ReadPositions = newMode(16, "ReadPositions")
8282

8383
val PatternOrType = Pattern | Type
84+
85+
/** We are elaborating the fully qualified name of a package clause.
86+
* In this case, identifiers should never be imported.
87+
*/
88+
val InPackageClauseName = newMode(17, "InPackageClauseName")
8489
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
9595
def typedIdent(tree: untpd.Ident, pt: Type)(implicit ctx: Context): Tree = track("typedIdent") {
9696
val refctx = ctx
9797
val name = tree.name
98+
val noImports = ctx.mode.is(Mode.InPackageClauseName)
9899

99100
/** Method is necessary because error messages need to bind to
100101
* to typedIdent's context which is lost in nested calls to findRef
@@ -240,7 +241,8 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
240241

241242
/** Would import of kind `prec` be not shadowed by a nested higher-precedence definition? */
242243
def isPossibleImport(prec: Int)(implicit ctx: Context) =
243-
prevPrec < prec || prevPrec == prec && (prevCtx.scope eq ctx.scope)
244+
!noImports &&
245+
(prevPrec < prec || prevPrec == prec && (prevCtx.scope eq ctx.scope))
244246

245247
@tailrec def loop(implicit ctx: Context): Type = {
246248
if (ctx.scope == null) previous
@@ -1330,7 +1332,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
13301332
}
13311333

13321334
def typedPackageDef(tree: untpd.PackageDef)(implicit ctx: Context): Tree = track("typedPackageDef") {
1333-
val pid1 = typedExpr(tree.pid, AnySelectionProto)
1335+
val pid1 = typedExpr(tree.pid, AnySelectionProto)(ctx.addMode(Mode.InPackageClauseName))
13341336
val pkg = pid1.symbol
13351337
val packageContext =
13361338
if (pkg is Package) ctx.fresh.setOwner(pkg.moduleClass).setTree(tree)

tests/pos/i1638.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package util.util
2+
3+
class C

0 commit comments

Comments
 (0)