diff options
author | Sean McDirmid <sean.mcdirmid@gmail.com> | 2008-06-01 08:04:19 +0000 |
---|---|---|
committer | Sean McDirmid <sean.mcdirmid@gmail.com> | 2008-06-01 08:04:19 +0000 |
commit | ba33786e9b0247bc8c796dddbbed1c69905c667e (patch) | |
tree | 5babffd217565e5b12048a8fad063e582adfa4cd | |
parent | 7569442847c4d34e02e915125c475cc5449f12d9 (diff) | |
download | scala-ba33786e9b0247bc8c796dddbbed1c69905c667e.tar.gz scala-ba33786e9b0247bc8c796dddbbed1c69905c667e.tar.bz2 scala-ba33786e9b0247bc8c796dddbbed1c69905c667e.zip |
Various bugfixes and upgrades to IDE support de...
Various bugfixes and upgrades to IDE support dealing with case
classes/companion objects, lazy val's, and dependency tracking.
13 files changed, 168 insertions, 58 deletions
diff --git a/src/compiler/scala/tools/nsc/CompilationUnits.scala b/src/compiler/scala/tools/nsc/CompilationUnits.scala index 48026e3b4a..3bac2f7525 100644 --- a/src/compiler/scala/tools/nsc/CompilationUnits.scala +++ b/src/compiler/scala/tools/nsc/CompilationUnits.scala @@ -26,6 +26,9 @@ trait CompilationUnits { self: Global => * To get their sourcefiles, you need to dereference with .sourcefile */ val depends = new HashSet[Symbol] + /** so we can relink + */ + val defined = new HashSet[Symbol] /** Synthetic definitions generated by namer, eliminated by typer. */ @@ -79,6 +82,7 @@ trait CompilationUnits { self: Global => body = null depends.clear errorPositions.clear + defined.clear } } } diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala index 254b34a2ee..7c85d198f3 100644 --- a/src/compiler/scala/tools/nsc/Global.scala +++ b/src/compiler/scala/tools/nsc/Global.scala @@ -221,7 +221,7 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable getSourceFile(ret.sourceFile) } - val loaders = new SymbolLoaders { + val loaders : SymbolLoaders { val global : Global.this.type } = new SymbolLoaders { lazy val global: Global.this.type = Global.this } @@ -229,7 +229,7 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable if (forMSIL) new loaders.NamespaceLoader(classPath.root) else new loaders.PackageLoader(classPath.root /* getRoot() */) -// Phases ------------------------------------------------------------ +// Phases ------------------------------------------------------------} var globalPhase: Phase = NoPhase @@ -611,7 +611,6 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable } } for ((sym, file) <- symSource.elements) resetPackageClass(sym.owner) - //units foreach (.clear()) informTime("total", startTime) } diff --git a/src/compiler/scala/tools/nsc/IdeSupport.scala b/src/compiler/scala/tools/nsc/IdeSupport.scala index c424255d7e..ac80997f18 100644 --- a/src/compiler/scala/tools/nsc/IdeSupport.scala +++ b/src/compiler/scala/tools/nsc/IdeSupport.scala @@ -28,6 +28,8 @@ trait IdeSupport extends Global with symtab.IdeSupport { import global._ protected override def completeClassfile(root : global.Symbol, loader : ClassfileLoader)(f : => Unit) : Unit = global.normalCompile(f) + override def computeDepends(from : PackageLoader) : global.PackageScopeDependMap = IdeSupport.this.computeDepends(from.asInstanceOf[IdeSupport.this.loaders.PackageLoader]) } + def computeDepends(from : loaders.PackageLoader) : PackageScopeDependMap = null override lazy val loaders = loaders1 } diff --git a/src/compiler/scala/tools/nsc/symtab/IdeSupport.scala b/src/compiler/scala/tools/nsc/symtab/IdeSupport.scala index 2743b78c3f..f8e74a2610 100644 --- a/src/compiler/scala/tools/nsc/symtab/IdeSupport.scala +++ b/src/compiler/scala/tools/nsc/symtab/IdeSupport.scala @@ -94,10 +94,25 @@ trait IdeSupport extends SymbolTable { // added to global, not analyzers. e = scope.lookupEntry(name) while (e != null && !e.sym.hasFlag(MODULE)) e = scope.lookupNextEntry(e) if (e != null) { - list += e.sym - scope unlink e.sym - } else Console.println("XXX: module " + name + " does not exist anymore") - //Console.println("RS-UNLINK: " + factory) + // try to find apply method. + e.sym.moduleClass.rawInfo match { + case ClassInfoType(_,decls : PersistentScope,_) => + val list = reuseMap.get(decls) match { + case Some(list) => list + case None => + val list = new jcl.LinkedList[Symbol] + reuseMap(decls) = list; list + } + decls.toList.foreach{ae=> + if (ae.hasFlag(CASE) && ae.hasFlag(SYNTHETIC)) { + list += ae + decls unlink ae + } + } + case eee => + assert(eee != null) + } + } } // if def is abstract, will only unlink its name if (sym.isGetter) { @@ -128,6 +143,12 @@ trait IdeSupport extends SymbolTable { // added to global, not analyzers. //Console.println("RS-UNLINK: " + setter) } } + } else if (sym.hasFlag(Flags.LAZY)) { + val getter = sym.lazyAccessor + if (getter != NoSymbol) { + list += getter + scope unlink getter + } } //Console.println("RS-UNLINK: " + sym) list += sym @@ -137,17 +158,24 @@ trait IdeSupport extends SymbolTable { // added to global, not analyzers. private def reuse(scope : PersistentScope) : PersistentScope = { if (currentClient.makeNoChanges) return scope val buf = new jcl.LinkedList[Symbol] - buf addAll scope.toList - buf.foreach(sym => assert(!sym.isPackage)) - scope.clear + scope.toList.foreach{sym => + if (sym.hasFlag(Flags.CASE) && sym.hasFlag(Flags.SYNTHETIC)) { + assert(sym != null) + } else { + buf add sym + scope unlink sym + } + } if (!buf.isEmpty) { assert(true) - reuseMap(scope) = buf + reuseMap.get(scope) match { + case Some(buf0) => buf.foreach(buf0.+=) + case None => reuseMap(scope) = buf + } } scope } - // TODO: implement a good compile late for the IDE. def reloadSource(file : AbstractFile) = { assert(true) if (!currentClient.makeNoChanges) topDefs.removeKey(file) match { @@ -180,7 +208,7 @@ trait IdeSupport extends SymbolTable { // added to global, not analyzers. case sym => // note that we didn't unlink them val scope0 = scope - Console.println("RECYCLE: " + sym + ":" + sym.id + " in " + sym.owner + " " + scope0 + " " + scope0.key); + Console.println("RECYCLE: " + sym + ":" + sym.id + " in " + sym.owner); // + " " + scope0 + " " + scope0.key); scope0.invalidate(sym.name) }} reuseMap.clear @@ -540,6 +568,16 @@ trait IdeSupport extends SymbolTable { // added to global, not analyzers. object owner extends ReallyHasClients new PersistentScope(null, owner) } + import scala.collection.jcl + override def newPackageScope(depends0 : PackageScopeDependMap) : PackageScope = { + object owner extends ReallyHasClients + object myPackageScope extends PersistentScope(null, owner) with PackageScope { + val depends = depends0 + } + myPackageScope + } + + override def newTempScope : Scope = new TemporaryScope private class TemporaryScope extends HookedScope(null) { override def hashCode = toList.map(_.hashCode).foldLeft(0)(_ + _) diff --git a/src/compiler/scala/tools/nsc/symtab/Scopes.scala b/src/compiler/scala/tools/nsc/symtab/Scopes.scala index f53e61319b..38cd2c5cc1 100644 --- a/src/compiler/scala/tools/nsc/symtab/Scopes.scala +++ b/src/compiler/scala/tools/nsc/symtab/Scopes.scala @@ -42,6 +42,17 @@ trait Scopes { */ def newScope(initElems: ScopeEntry): Scope = new NormalScope(initElems) final def newScope: Scope = newScope(null: ScopeEntry) + trait PackageScopeDependMap { + def createDepend(from : Symbol, name : Name) : Unit + } + + def newPackageScope(depends0 : PackageScopeDependMap) : PackageScope = { + object MyPackageScope extends NormalScope(null : ScopeEntry) with PackageScope { + val depends = depends0 + } + MyPackageScope + } + def newTempScope = newScope(null : ScopeEntry) class ScopeKind(name : String) { override def toString = name } def allocateScopeKind(name : String) = new ScopeKind(name) @@ -79,6 +90,22 @@ trait Scopes { private class NormalScope(initElems: ScopeEntry) extends Scope(initElems) + trait PackageScope extends Scope { + val depends : PackageScopeDependMap + override def lookupEntryWithContext(name : Name)(from : Symbol) = { + if (from != NoSymbol && depends != null) { + depends.createDepend(from,name) + } + super.lookupEntryWithContext(name)(from) + } + override def lookupWithContext(name : Name)(from : Symbol) = { + if (from != NoSymbol && depends != null) { + depends.createDepend(from,name) + } + super.lookupWithContext(name)(from) + } + } + abstract class Scope(initElems: ScopeEntry) { var elems: ScopeEntry = initElems @@ -265,6 +292,10 @@ trait Scopes { val e = lookupEntry(name) if (e eq null) NoSymbol else e.sym } + /** Can lookup symbols and trace who the client is. + */ + def lookupEntryWithContext(name : Name)(from : Symbol) : ScopeEntry = lookupEntry(name) + def lookupWithContext(name : Name)(from : Symbol) : Symbol = lookup(name) /** lookup a symbol entry matching given name. * diff --git a/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala b/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala index cf9d635596..2b5f147c67 100644 --- a/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala +++ b/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala @@ -111,8 +111,9 @@ abstract class SymbolLoaders { /** Load contents of a package */ - class PackageLoader(directory: global.classPath0.Context) extends SymbolLoader { + class PackageLoader(val directory: global.classPath0.Context) extends SymbolLoader { + // XXX: for IDE. protected def sourceString = directory.toString() protected def kindString: String = "directory path" @@ -122,7 +123,7 @@ abstract class SymbolLoaders { protected def checkSource(name: String, source: AbstractFile): Boolean = true - protected var root: Symbol = _ + var root: Symbol = _ def enterPackage(name: String, completer: SymbolLoader) { if (inIDE && root.info.decls.lookup(newTermName(name)) != NoSymbol) { @@ -155,10 +156,10 @@ abstract class SymbolLoaders { name = name.substring(0, name indexOf '$') } } + lazy val scope = newPackageScope(computeDepends(this)) protected def doComplete(root: Symbol) { assert(root.isPackageClass, root) this.root = root - val scope = newScope root.setInfo(new PackageClassInfoType(scope, root, this)) refresh } @@ -276,6 +277,11 @@ abstract class SymbolLoaders { } // IDE hook. protected def completeClassfile(root : Symbol, loader : ClassfileLoader)(f : => Unit) : Unit = f + import scala.collection.jcl + // incremental builder hook + protected def computeDepends(loader : PackageLoader) : PackageScopeDependMap = { + null + } class ClassfileLoader(val classFile: AbstractFile, override val sourceFile: AbstractFile, sourcePath0: AbstractFile) extends SymbolLoader { private object classfileParser extends ClassfileParser { diff --git a/src/compiler/scala/tools/nsc/symtab/Types.scala b/src/compiler/scala/tools/nsc/symtab/Types.scala index 8b1abc27a0..d508635983 100644 --- a/src/compiler/scala/tools/nsc/symtab/Types.scala +++ b/src/compiler/scala/tools/nsc/symtab/Types.scala @@ -353,29 +353,29 @@ trait Types { * Members appear in linearization order of their owners. * Members with the same owner appear in reverse order of their declarations. */ - def members: List[Symbol] = findMember(nme.ANYNAME, 0, 0, false).alternatives + def members: List[Symbol] = findMember(nme.ANYNAME, 0, 0, false)(NoSymbol).alternatives /** A list of all non-private members of this type (defined or inherited) */ def nonPrivateMembers: List[Symbol] = - findMember(nme.ANYNAME, PRIVATE | BRIDGE, 0, false).alternatives + findMember(nme.ANYNAME, PRIVATE | BRIDGE, 0, false)(NoSymbol).alternatives /** A list of all implicit symbols of this type (defined or inherited) */ def implicitMembers: List[Symbol] = - findMember(nme.ANYNAME, BRIDGE, IMPLICIT, false).alternatives + findMember(nme.ANYNAME, BRIDGE, IMPLICIT, false)(NoSymbol).alternatives /** The member with given name, * an OverloadedSymbol if several exist, NoSymbol if none exist */ - def member(name: Name): Symbol = findMember(name, BRIDGE, 0, false) + def member(name: Name): Symbol = findMember(name, BRIDGE, 0, false)(NoSymbol) /** The non-private member with given name, * an OverloadedSymbol if several exist, NoSymbol if none exist */ def nonPrivateMember(name: Name): Symbol = - findMember(name, PRIVATE | BRIDGE, 0, false) + findMember(name, PRIVATE | BRIDGE, 0, false)(NoSymbol) /** The non-local member with given name, * an OverloadedSymbol if several exist, NoSymbol if none exist */ - def nonLocalMember(name: Name): Symbol = - findMember(name, LOCAL | BRIDGE, 0, false) + def nonLocalMember(name: Name)(from : Symbol): Symbol = + findMember(name, LOCAL | BRIDGE, 0, false)(from) /** The least type instance of given class which is a supertype * of this type */ @@ -628,7 +628,7 @@ trait Types { * @return ... */ //TODO: use narrow only for modules? (correct? efficiency gain?) - def findMember(name: Name, excludedFlags: Int, requiredFlags: Long, stableOnly: Boolean): Symbol = { + def findMember(name: Name, excludedFlags: Int, requiredFlags: Long, stableOnly: Boolean)(from:Symbol): Symbol = { if (inIDE) trackTypeIDE(typeSymbol) if (util.Statistics.enabled) findMemberCount += 1 val startTime = if (util.Statistics.enabled) currentTime else 0l @@ -648,7 +648,7 @@ trait Types { while (!bcs.isEmpty) { val decls = bcs.head.info.decls var entry = - if (name == nme.ANYNAME) decls.elems else decls lookupEntry name + if (name == nme.ANYNAME) decls.elems else decls.lookupEntryWithContext(name)(from) while (entry ne null) { val sym = entry.sym if (sym.getFlag(requiredFlags) == requiredFlags) { @@ -676,7 +676,7 @@ trait Types { members = newThrowAwayScope(List(member, sym)) } } else { - var prevEntry = members lookupEntry sym.name + var prevEntry = members.lookupEntryWithContext(sym.name)(from) while ((prevEntry ne null) && !(prevEntry.sym == sym || prevEntry.sym.owner != sym.owner && @@ -824,7 +824,7 @@ trait Types { override def isError: Boolean = true override def decls: Scope = new ErrorScope(NoSymbol) override def findMember(name: Name, excludedFlags: Int, - requiredFlags: Long, stableOnly: Boolean): Symbol = { + requiredFlags: Long, stableOnly: Boolean)(from : Symbol): Symbol = { var sym = decls lookup name if (sym == NoSymbol) { sym = NoSymbol.newErrorSymbol(name) @@ -1290,8 +1290,10 @@ trait Types { override def kind = "ClassInfoType" } - class PackageClassInfoType(decls: Scope, clazz: Symbol, val loader : LazyType) - extends ClassInfoType(List(), decls, clazz) + class PackageClassInfoType(decls: Scope, clazz: Symbol, val lazyLoader : LazyType) + extends ClassInfoType(List(), decls, clazz) { + def reset = clazz.setInfo(lazyLoader) + } /** A class representing a constant type. * @@ -3068,7 +3070,7 @@ A type's typeSymbol should never be inspected directly. } else if ((pre eq NoPrefix) || (pre eq NoType) || sym.owner.isPackageClass) { sym } else { - var rebind0 = pre.findMember(sym.name, BRIDGE, 0, true) + var rebind0 = pre.findMember(sym.name, BRIDGE, 0, true)(NoSymbol) /* if (rebind0 == NoSymbol && (sym hasFlag EXPANDEDNAME)) { // problem is that symbols with expanded names might be in the wrong hash bucket diff --git a/src/compiler/scala/tools/nsc/transform/Mixin.scala b/src/compiler/scala/tools/nsc/transform/Mixin.scala index ad41f64e72..f78228888a 100644 --- a/src/compiler/scala/tools/nsc/transform/Mixin.scala +++ b/src/compiler/scala/tools/nsc/transform/Mixin.scala @@ -205,7 +205,7 @@ abstract class Mixin extends InfoTransform { val imember = member.overriddenSymbol(iface) //Console.println("mixin member "+member+":"+member.tpe+member.locationString+" "+imember+" "+imember.overridingSymbol(clazz)+" to "+clazz+" with scope "+clazz.info.decls)//DEBUG if (imember.overridingSymbol(clazz) == NoSymbol && - clazz.info.findMember(member.name, 0, lateDEFERRED, false).alternatives.contains(imember)) { + clazz.info.findMember(member.name, 0, lateDEFERRED, false)(NoSymbol).alternatives.contains(imember)) { val member1 = addMember( clazz, member.cloneSymbol(clazz) setPos clazz.pos resetFlag (DEFERRED | lateDEFERRED)) @@ -590,7 +590,7 @@ abstract class Mixin extends InfoTransform { /** Complete lazy field accessors. Applies only to classes, for it's own (non inherited) lazy fields. */ def lazifyOwnFields(clazz: Symbol, stats: List[Tree]): List[Tree] = { - var offset = clazz.info.findMember(nme.ANYNAME, 0, METHOD | LAZY, false).alternatives.filter(_.owner != clazz).length + var offset = clazz.info.findMember(nme.ANYNAME, 0, METHOD | LAZY, false)(NoSymbol).alternatives.filter(_.owner != clazz).length val stats1 = for (stat <- stats; sym = stat.symbol) yield stat match { case DefDef(mods, name, tp, vp, tpt, rhs) if sym.hasFlag(LAZY) && rhs != EmptyTree && !clazz.isImplClass => @@ -609,7 +609,7 @@ abstract class Mixin extends InfoTransform { // the number of inherited lazy fields that are not mixed in - offset = (clazz.info.findMember(nme.ANYNAME, 0, METHOD | LAZY, false) + offset = (clazz.info.findMember(nme.ANYNAME, 0, METHOD | LAZY, false)(NoSymbol) .alternatives filter { f => f.owner != clazz || !f.hasFlag(MIXEDIN)}).length // begin addNewDefs var stats1 = lazifyOwnFields(clazz, stats) diff --git a/src/compiler/scala/tools/nsc/typechecker/IdeSupport.scala b/src/compiler/scala/tools/nsc/typechecker/IdeSupport.scala index 97205e8f76..32bc7511a6 100644 --- a/src/compiler/scala/tools/nsc/typechecker/IdeSupport.scala +++ b/src/compiler/scala/tools/nsc/typechecker/IdeSupport.scala @@ -189,15 +189,24 @@ trait IdeSupport extends Analyzer { if (sym != tree.symbol) { assert(true) assert(true) - Console.println("SCREWED: " + sym + " " + sym.id + " vs. " + tree.symbol.id) + Console.println("BAD: " + sym + " " + sym.id + " vs. " + tree.symbol.id) } import symtab.Flags._ val set = reuseMap.get(namer.context.scope.asInstanceOf[PersistentScope]) - if (set.isDefined && sym.isClass && sym.hasFlag(CASE)) { + if (sym.isClass && sym.hasFlag(CASE)) { + // case class, re-add apply unapply methods to module scope val name = sym.name.toTermName - val factory = set.get.find(_.name == name).get - val sym0 = namer.enterInScope(factory) - assert(sym0 == factory) + var e = namer.context.scope.lookupEntry(name) + while (e != null && !e.sym.hasFlag(MODULE)) e = namer.context.scope.lookupNextEntry(e) + if (e != null) e.sym.rawInfo match { + case ClassInfoType(_,decls: PersistentScope,_) => + val set = reuseMap.get(decls) + set.foreach(_.foreach{sym=> + if (sym.hasFlag(CASE) && sym.hasFlag(SYNTHETIC)) + decls enter sym + }) + case _ => + } } // could be getter or local, then we need to re-add getter/setter if (sym.isGetter && set.isDefined) @@ -222,6 +231,11 @@ trait IdeSupport extends Analyzer { val setter0 = namer.enterInScope(setter) assert(setter0 == setter) } + } else if (sym.hasFlag(symtab.Flags.LAZY) && sym.lazyAccessor != NoSymbol) { + if (set.get.find(sym0 => sym0 == sym.lazyAccessor).isDefined) { + assert(true) + namer.enterInScope(sym.lazyAccessor) + } } } case _ => @@ -260,6 +274,19 @@ trait IdeSupport extends Analyzer { } catch { case te : TypeError => typeError(te.getMessage) }) + use.foreach{tree=> + if (tree.symbol.isClass && tree.symbol.hasFlag(symtab.Flags.CASE) && tree.symbol.owner.rawInfo.isComplete) { + var e = tree.symbol.owner.info.decls.lookupEntry(tree.symbol.name.toTermName) + if (e != null) e.sym.pos match { + case pos : TrackedPosition if pos.owner != null => + assert(true) + pos.owner.dirtyTyped + pos.owner.doTyper + case _ => + } + () + } + } if (makeNoChanges) {} else if (hasTypeErrors && lastSymbol != null && lastSymbol != NoSymbol && use.last.symbol != lastSymbol) { if (use.last.symbol != null && use.last.symbol != NoSymbol) { diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala index e31571e8bf..5887938753 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala @@ -330,6 +330,7 @@ trait Infer { (if (sym.isClassConstructor) context.enclClass.owner else pre.widen) + explanation) + val topClass = context.owner.toplevelClass if (context.unit != null) context.unit.depends += sym.toplevelClass diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala index 5ac2f17e93..2a1bbe1001 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala @@ -145,7 +145,7 @@ trait Namers { self: Analyzer => def enterInScope(sym: Symbol): Symbol = { // allow for overloaded methods if (!(sym.isSourceMethod && sym.owner.isClass && !sym.owner.isPackageClass)) { - var prev = context.scope.lookupEntry(sym.name); + var prev = context.scope.lookupEntryWithContext(sym.name)(context.owner); if ((prev ne null) && inIDE) { var guess = prev while ((guess ne null) && (guess.sym ne sym)) guess = context.scope.lookupNextEntry(guess) @@ -179,7 +179,7 @@ trait Namers { self: Analyzer => def enterPackageSymbol(pos: Position, name: Name): Symbol = { val cscope = if (context.owner == EmptyPackageClass) RootClass.info.decls else context.scope - val p: Symbol = cscope.lookup(name) + val p: Symbol = cscope.lookupWithContext(name)(context.owner) if (p.isPackage && cscope == p.owner.info.decls) { p } else { @@ -194,7 +194,7 @@ trait Namers { self: Analyzer => } def enterClassSymbol(tree : ClassDef): Symbol = { - var c: Symbol = context.scope.lookup(tree.name); + var c: Symbol = context.scope.lookupWithContext(tree.name)(context.owner); if (!inIDE && c.isType && c.owner.isPackageClass && context.scope == c.owner.info.decls && !currentRun.compiles(c)) { updatePosFlags(c, tree.pos, tree.mods.flags) setPrivateWithin(tree, c, tree.mods) @@ -224,7 +224,7 @@ trait Namers { self: Analyzer => * or a class definition */ def enterModuleSymbol(tree : ModuleDef): Symbol = { // .pos, mods.flags | MODULE | FINAL, name - var m: Symbol = context.scope.lookup(tree.name) + var m: Symbol = context.scope.lookupWithContext(tree.name)(context.owner) val moduleFlags = tree.mods.flags | MODULE | FINAL if (!inIDE && m.isModule && !m.isPackage && inCurrentScope(m) && (!currentRun.compiles(m) || (m hasFlag SYNTHETIC))) { @@ -313,8 +313,8 @@ trait Namers { self: Analyzer => tree.symbol = enterClassSymbol(tree) finishWith(tparams) if ((mods.flags & CASE) != 0) { - var m: Symbol = context.scope.lookup(tree.name.toTermName).filter(! _.isSourceMethod) - if (!(m.isModule && inCurrentScope(m) && currentRun.compiles(m))) { + var m: Symbol = context.scope.lookupWithContext(tree.name.toTermName)(context.owner).filter(! _.isSourceMethod) + if (!(m.isModule && inCurrentScope(m) && (inIDE || currentRun.compiles(m)))) { m = enterSyntheticSym(caseModuleDef(tree)) } caseClassOfModuleClass(m.moduleClass) = tree @@ -544,7 +544,7 @@ trait Namers { self: Analyzer => } // add apply and unapply methods to companion objects of case classes, // unless they exist already - caseClassOfModuleClass get clazz match { + Namers.this.caseClassOfModuleClass get clazz match { case Some(cdef) => addApplyUnapply(cdef, templateNamer) caseClassOfModuleClass -= clazz @@ -867,7 +867,7 @@ trait Namers { self: Analyzer => if (!tree.symbol.hasFlag(SYNTHETIC) && !((expr1.symbol ne null) && expr1.symbol.isInterpreterWrapper) && base.member(from) != NoSymbol) { - val e = context.scope.lookupEntry(to) + val e = context.scope.lookupEntryWithContext(to)(context.owner) def warnRedundant(sym: Symbol) = context.unit.warning(pos, "imported `"+to+ "' is permanently hidden by definition of "+sym+ diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala index c8dad51275..55728ec70f 100644 --- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala +++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala @@ -256,7 +256,7 @@ abstract class RefChecks extends InfoTransform { // Bridge symbols qualify. // Used as a fall back if no overriding symbol of a Java abstract method can be found def javaErasedOverridingSym(sym: Symbol): Symbol = - clazz.tpe.findMember(sym.name, PRIVATE, 0, false).filter(other => + clazz.tpe.findMember(sym.name, PRIVATE, 0, false)(NoSymbol).filter(other => !other.isDeferred && (other hasFlag JAVA) && { val tp1 = erasure.erasure(clazz.thisType.memberType(sym)) diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index be25970027..dbcc130e03 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -400,7 +400,7 @@ trait Typers { self: Analyzer => o = o.owner if (o == sym.owner) addHidden(sym) } else if (sym.owner.isTerm && !sym.isTypeParameterOrSkolem) { - var e = scope.lookupEntry(sym.name) + var e = scope.lookupEntryWithContext(sym.name)(context.owner) var found = false while (!found && (e ne null) && e.owner == scope) { if (e.sym == sym) { @@ -556,12 +556,12 @@ trait Typers { self: Analyzer => } /** The member with given name of given qualifier tree */ - def member(qual: Tree, name: Name) = qual.tpe match { + def member(qual: Tree, name: Name)(from : Symbol) = qual.tpe match { case ThisType(clazz) if (context.enclClass.owner.hasTransOwner(clazz)) => qual.tpe.member(name) case _ => if (phase.next.erasedTypes) qual.tpe.member(name) - else qual.tpe.nonLocalMember(name) + else qual.tpe.nonLocalMember(name)(from) } def silent(op: Typer => Tree): AnyRef /* in fact, TypeError or Tree */ = try { @@ -673,7 +673,7 @@ trait Typers { self: Analyzer => } case _ => def applyPossible = { - def applyMeth = member(adaptToName(tree, nme.apply), nme.apply) + def applyMeth = member(adaptToName(tree, nme.apply), nme.apply)(context.owner) if ((mode & TAPPmode) != 0) tree.tpe.typeParams.isEmpty && applyMeth.filter(! _.tpe.typeParams.isEmpty) != NoSymbol else @@ -857,7 +857,7 @@ trait Typers { self: Analyzer => } def adaptToName(qual: Tree, name: Name) = - if (member(qual, name) != NoSymbol) qual + if (member(qual, name)(context.owner) != NoSymbol) qual else adaptToMember(qual, name, WildcardType) private def typePrimaryConstrBody(clazz : Symbol, cbody: Tree, tparams: List[Symbol], enclTparams: List[Symbol], vparamss: List[List[ValDef]]): Tree = { @@ -1979,7 +1979,7 @@ trait Typers { self: Analyzer => } val nvPairs = annot.elements map { case vd @ ValDef(_, name, _, rhs) => { - val sym = attrScope.lookup(name); + val sym = attrScope.lookupWithContext(name)(context.owner); if (sym == NoSymbol) { error(vd.pos, "unknown attribute element name: " + name) } else if (!names.contains(sym)) { @@ -2737,8 +2737,8 @@ trait Typers { self: Analyzer => } tree.symbol } else { - if (!inIDE) member(qual, name) - else verifyAndPrioritize(_ filter (alt => context.isAccessible(alt, qual.tpe, qual.isInstanceOf[Super])))(pt)(member(qual,name)) + if (!inIDE) member(qual, name)(context.owner) + else verifyAndPrioritize(_ filter (alt => context.isAccessible(alt, qual.tpe, qual.isInstanceOf[Super])))(pt)(member(qual,name)(context.owner)) } if (sym == NoSymbol && name != nme.CONSTRUCTOR && (mode & EXPRmode) != 0) { val qual1 = adaptToName(qual, name) @@ -2781,7 +2781,7 @@ trait Typers { self: Analyzer => var cx = context while (cx != NoContext) { val pre = cx.enclClass.prefix - val defEntry = cx.scope.lookupEntry(name) + val defEntry = cx.scope.lookupEntryWithContext(name)(context.owner) if ((defEntry ne null) && defEntry.sym.exists) return true cx = cx.enclClass if ((pre.member(name) filter ( @@ -2828,8 +2828,8 @@ trait Typers { self: Analyzer => while (defSym == NoSymbol && cx != NoContext) { pre = cx.enclClass.prefix - defEntry = if (!inIDE) cx.scope.lookupEntry(name) - else verifyAndPrioritize(sym => sym)(pt)(cx.scope.lookupEntry(name)) + defEntry = if (!inIDE) cx.scope.lookupEntryWithContext(name)(context.owner) + else verifyAndPrioritize(sym => sym)(pt)(cx.scope.lookupEntryWithContext(name)(context.owner)) if ((defEntry ne null) && qualifies(defEntry.sym)) { defSym = defEntry.sym } else if (inIDE) { // IDE: cannot rely on linked scopes. |