aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/typer/Typer.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2014-01-13 19:15:31 +0100
committerMartin Odersky <odersky@gmail.com>2014-01-13 19:15:31 +0100
commit3affebe539b3461e7ea84411fe0a3943ccf35b4b (patch)
treee8cdacdc7136713c28a82e7c899edb305d8a1fdf /src/dotty/tools/dotc/typer/Typer.scala
parent607033b8127c249b2eda95da2341a7e98f4063b4 (diff)
downloaddotty-3affebe539b3461e7ea84411fe0a3943ccf35b4b.tar.gz
dotty-3affebe539b3461e7ea84411fe0a3943ccf35b4b.tar.bz2
dotty-3affebe539b3461e7ea84411fe0a3943ccf35b4b.zip
Refined handling of imports
Three changes: 1) Named imports beat wildcard imports in same scope, no matter what the relative order is 2) Named/named imports and wildcard/wildcard imports in the same scope of the same name but different symbols give an error 3) An error is not reported if two imported termRefs or typeRefs are equal wrt =:=.
Diffstat (limited to 'src/dotty/tools/dotc/typer/Typer.scala')
-rw-r--r--src/dotty/tools/dotc/typer/Typer.scala16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala
index a416d734a..772c65ac3 100644
--- a/src/dotty/tools/dotc/typer/Typer.scala
+++ b/src/dotty/tools/dotc/typer/Typer.scala
@@ -224,9 +224,12 @@ class Typer extends Namer with Applications with Implicits {
* does properly shadow the new one from an outer context.
*/
def checkNewOrShadowed(found: Type, newPrec: Int): Type =
- if (!previous.exists || (previous == found)) found
- else if (newPrec == definition && (prevCtx.scope eq ctx.scope)) {
- // special case: definitions beat imports if both are in contexts with same scope
+ if (!previous.exists || (previous =:= found)) found
+ else if ((prevCtx.scope eq ctx.scope) &&
+ (newPrec == definition ||
+ newPrec == namedImport && prevPrec == wildImport)) {
+ // special cases: definitions beat imports, and named imports beat
+ // wildcard imports, provided both are in contexts with same scope
found
}
else {
@@ -312,11 +315,14 @@ class Typer extends Namer with Applications with Implicits {
}
val curImport = ctx.importInfo
if (curImport != null && curImport.isRootImport && previous.exists) return previous
- if (prevPrec < namedImport && (curImport ne outer.importInfo) && !curImport.sym.isCompleting) {
+ // would import of kind `prec` be not shadowed by a nested higher-precedence definition?
+ def isPossibleImport(prec: Int) =
+ prevPrec < prec || prevPrec == prec && (prevCtx.scope eq ctx.scope)
+ if (isPossibleImport(namedImport) && (curImport ne outer.importInfo) && !curImport.sym.isCompleting) {
val namedImp = namedImportRef(curImport.site, curImport.selectors)
if (namedImp.exists)
return findRef(checkNewOrShadowed(namedImp, namedImport), namedImport, ctx)(outer)
- if (prevPrec < wildImport) {
+ if (isPossibleImport(wildImport)) {
val wildImp = wildImportRef(curImport)
if (wildImp.exists)
return findRef(checkNewOrShadowed(wildImp, wildImport), wildImport, ctx)(outer)