diff options
Diffstat (limited to 'src')
4 files changed, 105 insertions, 92 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/Symbols.scala b/src/compiler/scala/tools/nsc/symtab/Symbols.scala index fa7ddc1ce7..c13d13d86b 100644 --- a/src/compiler/scala/tools/nsc/symtab/Symbols.scala +++ b/src/compiler/scala/tools/nsc/symtab/Symbols.scala @@ -855,6 +855,8 @@ trait Symbols requires SymbolTable { def setAlias(alias: Symbol): TermSymbol = { assert(alias != NoSymbol, this); + assert(!(alias hasFlag OVERLOADED), alias) + assert(hasFlag(SUPERACCESSOR | PARAMACCESSOR | MIXEDIN), this); referenced = alias; this diff --git a/src/compiler/scala/tools/nsc/symtab/Types.scala b/src/compiler/scala/tools/nsc/symtab/Types.scala index 6f10e487e4..a0691632b3 100644 --- a/src/compiler/scala/tools/nsc/symtab/Types.scala +++ b/src/compiler/scala/tools/nsc/symtab/Types.scala @@ -201,13 +201,21 @@ trait Types requires SymbolTable { /** The type of `sym', seen as a member of this type. */ def memberType(sym: Symbol): Type = { sym.tpe match { - case OverloadedType(pre, alts) => + case ov @ OverloadedType(pre, alts) => + OverloadedType(this, alts) +/* val pre1 = pre match { case ClassInfoType(_, _, clazz) => clazz.tpe case _ => pre } - assert(this =:= pre1); - sym.tpe + if (this =:= pre1) ov + else if (this =:= pre1.narrow) OverloadedType(this, alts) + else { + Console.println("bad memberType of overloaded symbol: "+this+"/"+pre1+"/"+pre1.narrow) + assert(false) + ov + } +*/ case _ => //System.out.println("" + this + ".memberType(" + sym +":" + sym.tpe +")");//DEBUG sym.tpe.asSeenFrom(this, sym.owner) diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/UnPickler.scala b/src/compiler/scala/tools/nsc/symtab/classfile/UnPickler.scala index d57fef08c2..7812163256 100644 --- a/src/compiler/scala/tools/nsc/symtab/classfile/UnPickler.scala +++ b/src/compiler/scala/tools/nsc/symtab/classfile/UnPickler.scala @@ -3,37 +3,37 @@ * @author Martin Odersky */ // $Id$ -package scala.tools.nsc.symtab.classfile; +package scala.tools.nsc.symtab.classfile -import scala.tools.nsc.util.Position; -import scala.tools.util.UTF8Codec; -import java.lang.{Float, Double}; +import scala.tools.nsc.util.Position +import scala.tools.util.UTF8Codec +import java.lang.{Float, Double} -import Flags._; -import PickleFormat._; -import collection.mutable.HashMap; -import java.io.IOException; +import Flags._ +import PickleFormat._ +import collection.mutable.HashMap +import java.io.IOException abstract class UnPickler { - val global: Global; - import global._; + val global: Global + import global._ def unpickle(bytes: Array[byte], offset: int, classRoot: Symbol, moduleRoot: Symbol, filename: String): unit = try { - new UnPickle(bytes, offset, classRoot, moduleRoot); + new UnPickle(bytes, offset, classRoot, moduleRoot) } catch { case ex: IOException => throw ex case ex: Throwable => - if (settings.debug.value) ex.printStackTrace(); + if (settings.debug.value) ex.printStackTrace() throw new RuntimeException("error reading Scala signature of "+filename+": "+ex.getMessage()) } private class UnPickle(bytes: Array[byte], offset: int, classRoot: Symbol, moduleRoot: Symbol) extends PickleBuffer(bytes, offset, -1) { - if (settings.debug.value) global.log("unpickle " + classRoot + " and " + moduleRoot); - checkVersion(); - private val index = createIndex; - private val entries = new Array[AnyRef](index.length); - private val symScopes = new HashMap[Symbol, Scope]; + if (settings.debug.value) global.log("unpickle " + classRoot + " and " + moduleRoot) + checkVersion() + private val index = createIndex + private val entries = new Array[AnyRef](index.length) + private val symScopes = new HashMap[Symbol, Scope] for (val i <- Iterator.range(0, index.length)) { if (isSymbolEntry(i)) { at(i, readSymbol); () } @@ -42,8 +42,8 @@ abstract class UnPickler { if (settings.debug.value) global.log("unpickled " + classRoot + ":" + classRoot.rawInfo + ", " + moduleRoot + ":" + moduleRoot.rawInfo);//debug private def checkVersion() = { - val major = readNat(); - val minor = readNat(); + val major = readNat() + val minor = readNat() if (major != MajorVersion || minor > MinorVersion) throw new IOException("Scala signature " + classRoot.name + " has wrong version\n expected: " + @@ -59,69 +59,69 @@ abstract class UnPickler { /** Does entry represent an (internal) symbol */ private def isSymbolEntry(i: int): boolean = { - val tag = bytes(index(i)) % PosOffset; + val tag = bytes(index(i)) % PosOffset (firstSymTag <= tag && tag <= lastSymTag && (tag != CLASSsym || !isRefinementSymbolEntry(i))) } /** Does entry represent an (internal or external) symbol */ private def isSymbolRef(i: int): boolean = { - val tag = bytes(index(i)) % PosOffset; + val tag = bytes(index(i)) % PosOffset (firstSymTag <= tag && tag <= lastExtSymTag) } /** Does entry represent a refinement symbol? * pre: Entry is a class symbol */ private def isRefinementSymbolEntry(i: int): boolean = { - val savedIndex = readIndex; - readIndex = index(i); - val tag = readByte(); - if (tag % PosOffset != CLASSsym) assert(false); + val savedIndex = readIndex + readIndex = index(i) + val tag = readByte() + if (tag % PosOffset != CLASSsym) assert(false) readNat(); // read length if (tag > PosOffset) readNat(); // read position - val result = readNameRef() == nme.REFINE_CLASS_NAME.toTypeName; - readIndex = savedIndex; + val result = readNameRef() == nme.REFINE_CLASS_NAME.toTypeName + readIndex = savedIndex result } /** If entry at `i' is undefined, define it by performing operation `op' with * readIndex at start of i'th entry. Restore readIndex afterwards. */ private def at[T <: AnyRef](i: int, op: () => T): T = { - var r = entries(i); + var r = entries(i) if (r == null) { - val savedIndex = readIndex; - readIndex = index(i); - r = op(); - assert(entries(i) == null, entries(i)); - entries(i) = r; - readIndex = savedIndex; + val savedIndex = readIndex + readIndex = index(i) + r = op() + assert(entries(i) == null, entries(i)) + entries(i) = r + readIndex = savedIndex } r.asInstanceOf[T] } /** Read a name */ private def readName(): Name = { - val tag = readByte(); - val len = readNat(); + val tag = readByte() + val len = readNat() tag match { case TERMname => newTermName(bytes, readIndex, len) case TYPEname => newTypeName(bytes, readIndex, len) - case _ => errorBadSignature("bad name tag: " + tag); + case _ => errorBadSignature("bad name tag: " + tag) } } /** Read a symbol */ private def readSymbol(): Symbol = { - val tag = readByte(); - val end = readNat() + readIndex; - var sym: Symbol = NoSymbol; + val tag = readByte() + val end = readNat() + readIndex + var sym: Symbol = NoSymbol tag match { case EXTref | EXTMODCLASSref => - val name = readNameRef(); - val owner = if (readIndex == end) definitions.RootClass else readSymbolRef(); + val name = readNameRef() + val owner = if (readIndex == end) definitions.RootClass else readSymbolRef() sym = if (tag == EXTref) owner.info.decl(name) else if (name.toTermName == nme.ROOT) definitions.RootClass - else owner.info.decl(name).moduleClass; + else owner.info.decl(name).moduleClass if (sym == NoSymbol) errorBadSignature( "reference " + (if (name.isTypeName) "type " else "value ") + @@ -129,21 +129,21 @@ abstract class UnPickler { case NONEsym => sym = NoSymbol case _ => - val pos = if (tag > PosOffset) readNat() else Position.NOPOS; - val name = readNameRef(); - val owner = readSymbolRef(); - val flags = readNat(); - var privateWithin: Symbol = NoSymbol; - var inforef = readNat(); + val pos = if (tag > PosOffset) readNat() else Position.NOPOS + val name = readNameRef() + val owner = readSymbolRef() + val flags = readNat() + var privateWithin: Symbol = NoSymbol + var inforef = readNat() if (isSymbolRef(inforef)) { - privateWithin = at(inforef, readSymbol); + privateWithin = at(inforef, readSymbol) inforef = readNat() } (tag % PosOffset) match { case TYPEsym => - sym = owner.newAbstractType(pos, name); + sym = owner.newAbstractType(pos, name) case ALIASsym => - sym = owner.newAliasType(pos, name); + sym = owner.newAliasType(pos, name) case CLASSsym => sym = if (name == classRoot.name && owner == classRoot.owner) @@ -151,43 +151,43 @@ abstract class UnPickler { else classRoot).setPos(pos) else if ((flags & MODULE) != 0) owner.newModuleClass(pos, name) - else owner.newClass(pos, name); + else owner.newClass(pos, name) if (readIndex != end) sym.typeOfThis = new LazyTypeRef(readNat()) case MODULEsym => - val clazz = at(inforef, readType).symbol; + val clazz = at(inforef, readType).symbol sym = if (name == moduleRoot.name && owner == moduleRoot.owner) moduleRoot else { - assert(clazz.isInstanceOf[ModuleClassSymbol], clazz); - val mclazz = clazz.asInstanceOf[ModuleClassSymbol]; - val m = owner.newModule(pos, name, mclazz); - mclazz.setSourceModule(m); + assert(clazz.isInstanceOf[ModuleClassSymbol], clazz) + val mclazz = clazz.asInstanceOf[ModuleClassSymbol] + val m = owner.newModule(pos, name, mclazz) + mclazz.setSourceModule(m) m } case VALsym => sym = if (name == moduleRoot.name && owner == moduleRoot.owner) moduleRoot.resetFlag(MODULE) else owner.newValue(pos, name) case _ => - errorBadSignature("bad symbol tag: " + tag); + errorBadSignature("bad symbol tag: " + tag) } - sym.setFlag(flags); - sym.privateWithin = privateWithin; - if (readIndex != end) assert(sym hasFlag (SUPERACCESSOR | PARAMACCESSOR)); - if (sym hasFlag SUPERACCESSOR) assert(readIndex != end); + sym.setFlag(flags) + sym.privateWithin = privateWithin + if (readIndex != end) assert(sym hasFlag (SUPERACCESSOR | PARAMACCESSOR)) + if (sym hasFlag SUPERACCESSOR) assert(readIndex != end) sym.setInfo( if (readIndex != end) new LazyTypeRefAndAlias(inforef, readNat()) - else new LazyTypeRef(inforef)); + else new LazyTypeRef(inforef)) if (sym.owner.isClass && sym != classRoot && sym != moduleRoot && !sym.isModuleClass && !sym.isRefinementClass && !sym.isTypeParameter) - symScope(sym.owner) enter sym; + symScope(sym.owner) enter sym } sym } /** Read a type */ private def readType(): Type = { - val tag = readByte(); - val end = readNat() + readIndex; + val tag = readByte() + val end = readNat() + readIndex tag match { case NOtpe => NoType @@ -204,34 +204,34 @@ abstract class UnPickler { case TYPEBOUNDStpe => TypeBounds(readTypeRef(), readTypeRef()) case REFINEDtpe => - val clazz = readSymbolRef(); + val clazz = readSymbolRef() /* - val ps = until(end, readTypeRef); - val dcls = symScope(clazz); + val ps = until(end, readTypeRef) + val dcls = symScope(clazz) new RefinedType(ps, dcls) { override def symbol = clazz } */ new RefinedType(until(end, readTypeRef), symScope(clazz)) { override def symbol = clazz } case CLASSINFOtpe => - val clazz = readSymbolRef(); + val clazz = readSymbolRef() ClassInfoType(until(end, readTypeRef), symScope(clazz), clazz) case METHODtpe => - val restpe = readTypeRef(); + val restpe = readTypeRef() MethodType(until(end, readTypeRef), restpe) case IMPLICITMETHODtpe => - val restpe = readTypeRef(); + val restpe = readTypeRef() ImplicitMethodType(until(end, readTypeRef), restpe) case POLYtpe => - val restpe = readTypeRef(); + val restpe = readTypeRef() PolyType(until(end, readSymbolRef), restpe) case _ => - errorBadSignature("bad type tag: " + tag); + errorBadSignature("bad type tag: " + tag) } } /** Read a constant */ private def readConstant(): Constant = { - val tag = readByte(); - val len = readNat(); + val tag = readByte() + val len = readNat() tag match { case LITERALunit => Constant(()) case LITERALboolean => Constant(if (readLong(len) == 0) false else true) @@ -247,22 +247,22 @@ abstract class UnPickler { case LITERALclass => Constant(readTypeRef()) case _ => errorBadSignature("bad constant tag: " + tag) } - }; + } /** Read a reference to a name, symbol, type or constant */ - private def readNameRef(): Name = at(readNat(), readName); - private def readSymbolRef(): Symbol = at(readNat(), readSymbol); - private def readTypeRef(): Type = at(readNat(), readType); - private def readConstantRef(): Constant = at(readNat(), readConstant); + private def readNameRef(): Name = at(readNat(), readName) + private def readSymbolRef(): Symbol = at(readNat(), readSymbol) + private def readTypeRef(): Type = at(readNat(), readType) + private def readConstantRef(): Constant = at(readNat(), readConstant) private def errorBadSignature(msg: String) = - throw new RuntimeException("malformed Scala signature of " + classRoot.name + " at " + readIndex + "; " + msg); + throw new RuntimeException("malformed Scala signature of " + classRoot.name + " at " + readIndex + "; " + msg) private class LazyTypeRef(i: int) extends LazyType { - private val definedAtRun = currentRun; + private val definedAtRun = currentRun override def complete(sym: Symbol): unit = { - val tp = at(i, readType); - sym setInfo tp; + val tp = at(i, readType) + sym setInfo tp if (currentRun != definedAtRun) tp.complete(sym) } override def load(sym: Symbol): unit = complete(sym) @@ -270,8 +270,11 @@ abstract class UnPickler { private class LazyTypeRefAndAlias(i: int, j: int) extends LazyTypeRef(i) { override def complete(sym: Symbol): unit = { - super.complete(sym); - sym.asInstanceOf[TermSymbol].setAlias(at(j, readSymbol)); + super.complete(sym) + var alias = at(j, readSymbol) + if (alias hasFlag OVERLOADED) + alias = alias suchThat (alt => sym.tpe =:= sym.owner.thisType.memberType(alt)) + sym.asInstanceOf[TermSymbol].setAlias(alias) } } } diff --git a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala index eb528c8eae..a7c9206711 100644 --- a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala +++ b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala @@ -54,8 +54,8 @@ abstract class SuperAccessors extends transform.Transform { superAcc = clazz.newMethod(tree.pos, supername) .setFlag(SUPERACCESSOR | PRIVATE) + .setInfo(clazz.thisType.memberType(tree.symbol)) .setAlias(tree.symbol) - .setInfo(clazz.thisType.memberType(tree.symbol)); clazz.info.decls enter superAcc; accDefBuf(clazz) += typed(DefDef(superAcc, vparamss => EmptyTree)) } |