diff options
author | Paul Phillips <paulp@improving.org> | 2012-10-18 13:00:19 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2012-10-23 14:24:41 -0700 |
commit | 2dc5841638f8a48bace0084ac25baaef50e865f9 (patch) | |
tree | a5faecb57a35f965b49e92fc205a4c3692de9bd7 /src | |
parent | b480d991072e6e68ed46574d87e4483da778ff0e (diff) | |
download | scala-2dc5841638f8a48bace0084ac25baaef50e865f9.tar.gz scala-2dc5841638f8a48bace0084ac25baaef50e865f9.tar.bz2 scala-2dc5841638f8a48bace0084ac25baaef50e865f9.zip |
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)
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Contexts.scala | 19 |
1 files 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 = "" |