summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2010-01-23 17:44:20 +0000
committerMartin Odersky <odersky@gmail.com>2010-01-23 17:44:20 +0000
commitbb6e5958e63e3d70cd1f1a86f3fa0b5f3b670d8a (patch)
tree2941d81ab43d925eb2aea53952974df576a00671
parentdaf9227e7323c31257fe34bb4f2d38c7c1abbff1 (diff)
downloadscala-bb6e5958e63e3d70cd1f1a86f3fa0b5f3b670d8a.tar.gz
scala-bb6e5958e63e3d70cd1f1a86f3fa0b5f3b670d8a.tar.bz2
scala-bb6e5958e63e3d70cd1f1a86f3fa0b5f3b670d8a.zip
Closes 2926. Review by milesabin.
-rw-r--r--src/compiler/scala/tools/nsc/Global.scala7
-rw-r--r--src/compiler/scala/tools/nsc/interactive/Global.scala16
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Namers.scala10
3 files changed, 24 insertions, 9 deletions
diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala
index 76fa2ade93..1fc6098c3f 100644
--- a/src/compiler/scala/tools/nsc/Global.scala
+++ b/src/compiler/scala/tools/nsc/Global.scala
@@ -726,6 +726,13 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable
else if (sym.isModuleClass) compiles(sym.sourceModule)
else false
+ /** Opposite of compiles, but is overridden in interactive
+ * notCompiles is used to detect double declarations in multiple source files.
+ * Since the IDE rechecks units several times in the same run, it should
+ * always return true there.
+ */
+ def notCompiles(sym: Symbol) = !compiles(sym)
+
// --------------- Compilation methods ----------------------------
/** Compile list of source files */
diff --git a/src/compiler/scala/tools/nsc/interactive/Global.scala b/src/compiler/scala/tools/nsc/interactive/Global.scala
index 0a8477a489..9ed8b5076e 100644
--- a/src/compiler/scala/tools/nsc/interactive/Global.scala
+++ b/src/compiler/scala/tools/nsc/interactive/Global.scala
@@ -467,11 +467,19 @@ self =>
class TyperRun extends Run {
// units is always empty
- //override def compiles(sym: Symbol) = false
+ /** notCompiles is used to detect double declarations in multiple source files.
+ * Since the IDE rechecks units several times in the same run, these tests
+ * are disabled by always returning true here.
+ */
+ override def notCompiles(sym: Symbol) = true
- def typeCheck(unit: CompilationUnit): Unit = applyPhase(typerPhase, unit)
+ def typeCheck(unit: CompilationUnit): Unit = {
+ applyPhase(typerPhase, unit)
+ }
- def enterNames(unit: CompilationUnit): Unit = applyPhase(namerPhase, unit)
+ def enterNames(unit: CompilationUnit): Unit = {
+ applyPhase(namerPhase, unit)
+ }
/** Return fully attributed tree at given position
* (i.e. largest tree that's contained by position)
@@ -503,7 +511,6 @@ self =>
def typedTree(unit: RichCompilationUnit): Tree = {
assert(unit.status >= JustParsed)
unit.targetPos = NoPosition
- symSource.clear()
typeCheck(unit)
unit.body
}
@@ -512,7 +519,6 @@ self =>
* @return true iff typechecked correctly
*/
private def applyPhase(phase: Phase, unit: CompilationUnit) {
- symSource.clear()
val oldSource = reporter.getSource
reporter.withSource(unit.source) {
atPhase(phase) { phase.asInstanceOf[GlobalPhase] applyPhase unit }
diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala
index abeab40991..71d325d2c5 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala
@@ -197,7 +197,7 @@ trait Namers { self: Analyzer =>
def enterClassSymbol(tree : ClassDef): Symbol = {
var c: Symbol = context.scope.lookup(tree.name)
- if (c.isType && c.owner.isPackageClass && context.scope == c.owner.info.decls && !currentRun.compiles(c)) {
+ if (c.isType && c.owner.isPackageClass && context.scope == c.owner.info.decls && currentRun.notCompiles(c)) {
updatePosFlags(c, tree.pos, tree.mods.flags)
setPrivateWithin(tree, c, tree.mods)
} else {
@@ -214,7 +214,7 @@ trait Namers { self: Analyzer =>
}
clazz.sourceFile = file
if (clazz.sourceFile ne null) {
- assert(!currentRun.compiles(clazz) || clazz.sourceFile == currentRun.symSource(c));
+ assert(currentRun.notCompiles(clazz) || clazz.sourceFile == currentRun.symSource(c));
currentRun.symSource(c) = clazz.sourceFile
}
}
@@ -229,7 +229,7 @@ trait Namers { self: Analyzer =>
var m: Symbol = context.scope.lookup(tree.name)
val moduleFlags = tree.mods.flags | MODULE | FINAL
if (m.isModule && !m.isPackage && inCurrentScope(m) &&
- (!currentRun.compiles(m) || (m hasFlag SYNTHETIC))) {
+ (currentRun.notCompiles(m) || (m hasFlag SYNTHETIC))) {
updatePosFlags(m, tree.pos, moduleFlags)
setPrivateWithin(tree, m, tree.mods)
context.unit.synthetics -= m
@@ -288,7 +288,9 @@ trait Namers { self: Analyzer =>
def ensureCompanionObject(tree: ClassDef, creator: => Tree): Symbol = {
val m: Symbol = context.scope.lookup(tree.name.toTermName).filter(! _.isSourceMethod)
if (m.isModule && inCurrentScope(m) && currentRun.compiles(m)) m
- else enterSyntheticSym(creator)
+ else
+ /*util.trace("enter synthetic companion object for "+currentRun.compiles(m)+":")*/(
+ enterSyntheticSym(creator))
}
private def enterSymFinishWith(tree: Tree, tparams: List[TypeDef]) {