From 21fbde04b42a63f53d4839221f1fea90f329a72d Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sun, 24 Jan 2010 15:05:46 +0000 Subject: renamed notCompiles ==> canRedefine. --- src/compiler/scala/tools/nsc/Global.scala | 9 +++---- .../scala/tools/nsc/interactive/Global.scala | 29 ++++++++++++++-------- .../scala/tools/nsc/typechecker/Namers.scala | 6 ++--- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala index 1fc6098c3f..3cde4698ff 100644 --- a/src/compiler/scala/tools/nsc/Global.scala +++ b/src/compiler/scala/tools/nsc/Global.scala @@ -726,12 +726,11 @@ 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. + /** Is this run allowed to redefine the given symbol? Usually this is true + * if the run does not already compile `sym`, but for interactive mode + * we have a more liberal interpretation. */ - def notCompiles(sym: Symbol) = !compiles(sym) + def canRedefine(sym: Symbol) = !compiles(sym) // --------------- Compilation methods ---------------------------- diff --git a/src/compiler/scala/tools/nsc/interactive/Global.scala b/src/compiler/scala/tools/nsc/interactive/Global.scala index 9ed8b5076e..706d578555 100644 --- a/src/compiler/scala/tools/nsc/interactive/Global.scala +++ b/src/compiler/scala/tools/nsc/interactive/Global.scala @@ -398,18 +398,24 @@ self => } def typeMembers(pos: Position): List[TypeMember] = { - val tree1 = typedTreeAt(pos) - val tree0 = tree1 match { - case tt : TypeTree => tt.original - case t => t + var tree = typedTreeAt(pos) + tree match { + case tt : TypeTree => tree = tt.original + case _ => } - val tree = tree0 match { - case s@Select(qual, name) if s.tpe == ErrorType => qual - case t => t + + tree match { + case Select(qual, name) if tree.tpe == ErrorType => tree = qual + case _ => } - println("typeMembers at "+tree+" "+tree.tpe) val context = doLocateContext(pos) + + if (tree.tpe == null) + tree = analyzer.newTyper(context).typedQualifier(tree) + + println("typeMembers at "+tree+" "+tree.tpe) + val superAccess = tree.isInstanceOf[Super] val scope = new Scope val members = new LinkedHashMap[Symbol, TypeMember] @@ -449,7 +455,8 @@ self => addTypeMember(sym, vpre, false, view.tree.symbol) } } - members.valuesIterator.toList + //util.trace("typeMembers =")( + members.valuesIterator.toList) } // ---------------- Helper classes --------------------------- @@ -467,11 +474,11 @@ self => class TyperRun extends Run { // units is always empty - /** notCompiles is used to detect double declarations in multiple source files. + /** canRedefine 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 + override def canRedefine(sym: Symbol) = true def typeCheck(unit: CompilationUnit): Unit = { applyPhase(typerPhase, unit) diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala index 71d325d2c5..c755beb04e 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.notCompiles(c)) { + if (c.isType && c.owner.isPackageClass && context.scope == c.owner.info.decls && currentRun.canRedefine(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.notCompiles(clazz) || clazz.sourceFile == currentRun.symSource(c)); + assert(currentRun.canRedefine(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.notCompiles(m) || (m hasFlag SYNTHETIC))) { + (currentRun.canRedefine(m) || (m hasFlag SYNTHETIC))) { updatePosFlags(m, tree.pos, moduleFlags) setPrivateWithin(tree, m, tree.mods) context.unit.synthetics -= m -- cgit v1.2.3