From 2dc5841638f8a48bace0084ac25baaef50e865f9 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Thu, 18 Oct 2012 13:00:19 -0700 Subject: Introduces some structure for name lookups. Too many unrelated things are intermingled. If you want to know what symbol corresponds to a particular name in a particular context, you shouldn't have to involve either a Tree or a Typer to find that out. I toiled line by line over typedIdent until it had shed its redundancies and freed itself from the bowels of typed1. The mechanism of name lookup is such that adding a qualifier when the occasion calls for it is inseperable without a lot more effort. So to preserve a sane interface I devised this small partitioning of outcomes. case class LookupSucceeded(qualifier, symbol) case class LookupAmbiguous(msg) case class LookupInaccessible(symbol, msg) case class LookupNotFound(msg) --- .../scala/tools/nsc/typechecker/Contexts.scala | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala index 211da044e6..0abd8c188e 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala @@ -35,6 +35,22 @@ trait Contexts { self: Analyzer => val completeList = JavaLangPackage :: ScalaPackage :: PredefModule :: Nil } + sealed abstract class NameLookup { def symbol: Symbol } + case class LookupSucceeded(qualifier: Tree, symbol: Symbol) extends NameLookup + case class LookupAmbiguous(msg: String) extends NameLookup { def symbol = NoSymbol } + case class LookupInaccessible(symbol: Symbol, msg: String) extends NameLookup + case class LookupNotFound() extends NameLookup { def symbol = NoSymbol } + // case object LookupNotFound extends NameLookup { def symbol = NoSymbol } + // + // !!! Bug - case object LookupNotFound does not match - we get an + // "impossible" MatchError. case class LookupNotFound() matches in + // the same spot. + + def ambiguousImports(imp1: ImportInfo, imp2: ImportInfo) = + LookupAmbiguous(s"it is imported twice in the same scope by\n$imp1\nand $imp2") + def ambiguousDefnAndImport(owner: Symbol, imp: ImportInfo) = + LookupAmbiguous(s"it is both defined in $owner and imported subsequently by \n$imp") + private val startContext = { NoContext.make( Template(List(), emptyValDef, List()) setSymbol global.NoSymbol setType global.NoType, @@ -480,8 +496,7 @@ trait Contexts { self: Analyzer => c } - /** Is `sym` accessible as a member of tree `site` with type - * `pre` in current context? + /** Is `sym` accessible as a member of `pre` in current context? */ def isAccessible(sym: Symbol, pre: Type, superAccess: Boolean = false): Boolean = { lastAccessCheckDetails = "" -- cgit v1.2.3