aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/typer/Typer.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2013-07-23 15:18:32 +0200
committerMartin Odersky <odersky@gmail.com>2013-07-23 15:18:32 +0200
commit0a86c0ae8668070f62df25c7a4ba12369f23b216 (patch)
tree635a6479b1b68ecf1a08c6393bbb89e591db2b14 /src/dotty/tools/dotc/typer/Typer.scala
parenta2c0e29c9e2f8f06e9499c02ebd6e2c3666a0709 (diff)
downloaddotty-0a86c0ae8668070f62df25c7a4ba12369f23b216.tar.gz
dotty-0a86c0ae8668070f62df25c7a4ba12369f23b216.tar.bz2
dotty-0a86c0ae8668070f62df25c7a4ba12369f23b216.zip
Added scheme to disabled implicit imports (not just Predef) if an explicit one is given for the same package or object.
Diffstat (limited to 'src/dotty/tools/dotc/typer/Typer.scala')
-rw-r--r--src/dotty/tools/dotc/typer/Typer.scala37
1 files changed, 31 insertions, 6 deletions
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala
index 8d936743f..f99c08ecb 100644
--- a/src/dotty/tools/dotc/typer/Typer.scala
+++ b/src/dotty/tools/dotc/typer/Typer.scala
@@ -53,6 +53,12 @@ class Typer extends Namer with Applications with Implicits {
import tpd._
import Typer._
+ /** A temporary data item valid for a single typed ident:
+ * The set of all root import symbols that have been
+ * encountered as a qualifier of an import so far.
+ */
+ private var importedFromRoot: Set[Symbol] = Set()
+
def typedSelection(site: Type, name: Name, pos: Position)(implicit ctx: Context): Type = {
val ref = site.member(name)
if (ref.exists) NamedType(site, name).withDenot(ref)
@@ -99,6 +105,18 @@ class Typer extends Namer with Applications with Implicits {
def typedIdent(tree: untpd.Ident)(implicit ctx: Context): Tree = {
val name = tree.name
+ /** Is this import a root import that has been shadowed by an explicit
+ * import in the same program?
+ */
+ def isDisabled(imp: ImportInfo, site: Type): Boolean = {
+ val qualSym = site.termSymbol
+ if (defn.RootImports contains qualSym) {
+ if (imp.rootImport && (importedFromRoot contains qualSym)) return true
+ importedFromRoot += qualSym
+ }
+ false
+ }
+
/** Does this identifier appear as a constructor of a pattern? */
def isPatternConstr =
if (ctx.mode.isExpr && (ctx.outer.mode is Mode.Pattern))
@@ -181,14 +199,16 @@ class Typer extends Namer with Applications with Implicits {
/** The type representing a wildcard import with enclosing name when imported
* from given import info
*/
- def wildImportRef(imp: ImportInfo): Type =
+ def wildImportRef(imp: ImportInfo): Type = {
if (imp.wildcardImport && !(imp.excluded contains name.toTermName)) {
val pre = imp.site
- val denot = pre.member(name)
- if (denot.exists) return NamedType(pre, name).withDenot(denot)
- else NoType
+ if (!isDisabled(imp, pre)) {
+ val denot = pre.member(name)
+ if (denot.exists) return NamedType(pre, name).withDenot(denot)
+ }
}
- else NoType
+ NoType
+ }
/** Is (some alternative of) the given predenotation `denot`
* defined in current compilation unit?
@@ -232,8 +252,13 @@ class Typer extends Namer with Applications with Implicits {
// begin typedIdent
val startingContext = // ignore current variable scope in patterns to enforce linearity
if (ctx.mode is Mode.Pattern) ctx.outer else ctx
+ val saved = importedFromRoot
+ importedFromRoot = Set()
- val rawType = findRef(NoType, BindingPrec.nothingBound, NoContext)
+ val rawType =
+ try findRef(NoType, BindingPrec.nothingBound, NoContext)
+ finally importedFromRoot = saved
+
val ownType =
if (rawType.exists) checkAccessible(rawType, superAccess = false, tree.pos)
else {