aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-11-03 20:29:13 +0100
committerMartin Odersky <odersky@gmail.com>2016-11-03 20:29:21 +0100
commit8c857cd29f48c3c2badfd37a7f22e8a24929d796 (patch)
tree10ad861352bb6db2159896236c06262ec1cdea16 /src
parent98a92c6f4ec743edb9465071dcfd43f17dbf054b (diff)
downloaddotty-8c857cd29f48c3c2badfd37a7f22e8a24929d796.tar.gz
dotty-8c857cd29f48c3c2badfd37a7f22e8a24929d796.tar.bz2
dotty-8c857cd29f48c3c2badfd37a7f22e8a24929d796.zip
Fix #1638: Don't import when typing a package clause
When typing the first identifier of a package clause, disable imports, as package clauses are never imported. Fixes #1638.
Diffstat (limited to 'src')
-rw-r--r--src/dotty/tools/dotc/core/Mode.scala5
-rw-r--r--src/dotty/tools/dotc/typer/Typer.scala6
2 files changed, 9 insertions, 2 deletions
diff --git a/src/dotty/tools/dotc/core/Mode.scala b/src/dotty/tools/dotc/core/Mode.scala
index 7a9bb0572..8dda88789 100644
--- a/src/dotty/tools/dotc/core/Mode.scala
+++ b/src/dotty/tools/dotc/core/Mode.scala
@@ -93,4 +93,9 @@ object Mode {
val ReadPositions = newMode(16, "ReadPositions")
val PatternOrType = Pattern | Type
+
+ /** We are elaborating the fully qualified name of a package clause.
+ * In this case, identifiers should never be imported.
+ */
+ val InPackageClauseName = newMode(17, "InPackageClauseName")
}
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala
index 56c04c063..8be537ac4 100644
--- a/src/dotty/tools/dotc/typer/Typer.scala
+++ b/src/dotty/tools/dotc/typer/Typer.scala
@@ -95,6 +95,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
def typedIdent(tree: untpd.Ident, pt: Type)(implicit ctx: Context): Tree = track("typedIdent") {
val refctx = ctx
val name = tree.name
+ val noImports = ctx.mode.is(Mode.InPackageClauseName)
/** Method is necessary because error messages need to bind to
* 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
/** Would import of kind `prec` be not shadowed by a nested higher-precedence definition? */
def isPossibleImport(prec: Int)(implicit ctx: Context) =
- prevPrec < prec || prevPrec == prec && (prevCtx.scope eq ctx.scope)
+ !noImports &&
+ (prevPrec < prec || prevPrec == prec && (prevCtx.scope eq ctx.scope))
@tailrec def loop(implicit ctx: Context): Type = {
if (ctx.scope == null) previous
@@ -1335,7 +1337,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
}
def typedPackageDef(tree: untpd.PackageDef)(implicit ctx: Context): Tree = track("typedPackageDef") {
- val pid1 = typedExpr(tree.pid, AnySelectionProto)
+ val pid1 = typedExpr(tree.pid, AnySelectionProto)(ctx.addMode(Mode.InPackageClauseName))
val pkg = pid1.symbol
val packageContext =
if (pkg is Package) ctx.fresh.setOwner(pkg.moduleClass).setTree(tree)