summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-08-06 14:24:42 +0000
committerPaul Phillips <paulp@improving.org>2011-08-06 14:24:42 +0000
commit4f4a80ad5b85ce3922c80bbc9524f2540918187e (patch)
treed56b411659069b7bcf841804875545ed0f8925da /src/compiler/scala/tools/nsc/typechecker/Contexts.scala
parent6d45fddd4c6537fb343e901d58491b81475e3786 (diff)
downloadscala-4f4a80ad5b85ce3922c80bbc9524f2540918187e.tar.gz
scala-4f4a80ad5b85ce3922c80bbc9524f2540918187e.tar.bz2
scala-4f4a80ad5b85ce3922c80bbc9524f2540918187e.zip
Don't want to chase NPEs around for the rest of...
Don't want to chase NPEs around for the rest of my life. Created "NoCompilationUnit" and "NoSourceFile" objects to represent not-present versions of these items. Seems a lot better than null. References SI-4859, got past NPE only to uncover the actual problem. No review.
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker/Contexts.scala')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Contexts.scala17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
index 96b27b58ae..44c28cf2f5 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
@@ -21,6 +21,7 @@ trait Contexts { self: Analyzer =>
val NoContext = new Context {
override def implicitss: List[List[ImplicitInfo]] = List()
outer = this
+ override def toString = "NoContext"
}
NoContext.enclClass = NoContext
NoContext.enclMethod = NoContext
@@ -89,7 +90,7 @@ trait Contexts { self: Analyzer =>
}
class Context private[typechecker] {
- var unit: CompilationUnit = _
+ var unit: CompilationUnit = NoCompilationUnit
var tree: Tree = _ // Tree associated with this context
var owner: Symbol = NoSymbol // The current owner
var scope: Scope = _ // The current scope
@@ -164,12 +165,11 @@ trait Contexts { self: Analyzer =>
*/
def make(unit: CompilationUnit, tree: Tree, owner: Symbol,
scope: Scope, imports: List[ImportInfo]): Context = {
- val c = new Context
- c.unit = unit
- c.tree = tree
+ val c = new Context
+ c.unit = unit
+ c.tree = tree
c.owner = owner
c.scope = scope
-
c.outer = this
tree match {
@@ -203,6 +203,7 @@ trait Contexts { self: Analyzer =>
c.retyping = this.retyping
c.openImplicits = this.openImplicits
registerContext(c.asInstanceOf[analyzer.Context])
+ debuglog("Created context: " + this + " ==> " + c)
c
}
@@ -364,11 +365,9 @@ trait Contexts { self: Analyzer =>
def nextEnclosing(p: Context => Boolean): Context =
if (this == NoContext || p(this)) this else outer.nextEnclosing(p)
- override def toString = (
- if (this == NoContext) "NoContext"
- else "Context(%s@%s scope=%s)".format(owner.fullName, tree.getClass.getName split "[.$]" last, scope.##)
+ override def toString = "Context(%s@%s unit=%s scope=%s)".format(
+ owner.fullName, tree.shortClass, unit, scope.##
)
-
/** Is `sub` a subclass of `base` or a companion object of such a subclass?
*/
def isSubClassOrCompanion(sub: Symbol, base: Symbol) =