diff options
author | odersky <odersky@gmail.com> | 2016-11-05 13:36:29 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-05 13:36:29 +0100 |
commit | a55a2607c7376ed81141ef958d6a8eeaeea8fd72 (patch) | |
tree | d872141dd714f4e9426891f82269d4c11d42f6bb | |
parent | 56f6933c7d164a446daa90099ffd3ce31647f6e0 (diff) | |
parent | 8c857cd29f48c3c2badfd37a7f22e8a24929d796 (diff) | |
download | dotty-a55a2607c7376ed81141ef958d6a8eeaeea8fd72.tar.gz dotty-a55a2607c7376ed81141ef958d6a8eeaeea8fd72.tar.bz2 dotty-a55a2607c7376ed81141ef958d6a8eeaeea8fd72.zip |
Merge pull request #1657 from dotty-staging/fix-#1638
Fix #1638: Don't import when typing a package clause
-rw-r--r-- | src/dotty/tools/dotc/core/Mode.scala | 5 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Typer.scala | 6 | ||||
-rw-r--r-- | tests/pos/i1638.scala | 3 |
3 files changed, 12 insertions, 2 deletions
diff --git a/src/dotty/tools/dotc/core/Mode.scala b/src/dotty/tools/dotc/core/Mode.scala index c16c3f15b..406a84af6 100644 --- a/src/dotty/tools/dotc/core/Mode.scala +++ b/src/dotty/tools/dotc/core/Mode.scala @@ -81,4 +81,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 c283f43cf..899b857ae 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 @@ -1330,7 +1332,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) diff --git a/tests/pos/i1638.scala b/tests/pos/i1638.scala new file mode 100644 index 000000000..299905aea --- /dev/null +++ b/tests/pos/i1638.scala @@ -0,0 +1,3 @@ +package util.util + +class C |