diff options
author | Martin Odersky <odersky@gmail.com> | 2005-09-30 18:40:06 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2005-09-30 18:40:06 +0000 |
commit | e572f2935c648a123386b0479eb3b1f1262df2b5 (patch) | |
tree | 5aeffba5aee21125cb2cee9cf028beaab63c510c | |
parent | 43b0ce3c5dbae86c308652625ad2f61e225d6c12 (diff) | |
download | scala-e572f2935c648a123386b0479eb3b1f1262df2b5.tar.gz scala-e572f2935c648a123386b0479eb3b1f1262df2b5.tar.bz2 scala-e572f2935c648a123386b0479eb3b1f1262df2b5.zip |
*** empty log message ***
41 files changed, 240 insertions, 159 deletions
diff --git a/sources/scala/collection/BitSet.scala b/sources/scala/collection/BitSet.scala index 5b6fa9568a..bd047bcc2c 100644 --- a/sources/scala/collection/BitSet.scala +++ b/sources/scala/collection/BitSet.scala @@ -14,7 +14,7 @@ package scala.collection; * @author Burak Emir, Stephane Micheloud * @version 1.0 */ -abstract class BitSet extends AnyRef with Function1[Int,Boolean] { +[_trait_] abstract class BitSet extends AnyRef with Function1[Int,Boolean] { /** number of bits in this bitset */ def size: Int; diff --git a/sources/scala/collection/mutable/HashTable.scala b/sources/scala/collection/mutable/HashTable.scala index adcbc5aec5..984f33f561 100644 --- a/sources/scala/collection/mutable/HashTable.scala +++ b/sources/scala/collection/mutable/HashTable.scala @@ -28,7 +28,7 @@ import Predef._; * @author Matthias Zenger * @version 1.0, 08/07/2003 */ -abstract class HashTable[A] extends AnyRef { +[_trait_] abstract class HashTable[A] extends AnyRef { /** The load factor for the hash table. */ diff --git a/sources/scala/collection/mutable/MutableList.scala b/sources/scala/collection/mutable/MutableList.scala index 46513634f0..37bb9ada63 100644 --- a/sources/scala/collection/mutable/MutableList.scala +++ b/sources/scala/collection/mutable/MutableList.scala @@ -17,7 +17,7 @@ package scala.collection.mutable; * @author Matthias Zenger * @version 1.0, 08/07/2003 */ -abstract class MutableList[A] extends Seq[A] with PartialFunction[Int, A] { +[_trait_] abstract class MutableList[A] extends Seq[A] with PartialFunction[Int, A] { protected var first: LinkedList[A] = null; protected var last: LinkedList[A] = null; diff --git a/sources/scala/collection/mutable/ObservableBuffer.scala b/sources/scala/collection/mutable/ObservableBuffer.scala index c51384f0dc..e3439b1dff 100644 --- a/sources/scala/collection/mutable/ObservableBuffer.scala +++ b/sources/scala/collection/mutable/ObservableBuffer.scala @@ -18,7 +18,7 @@ package scala.collection.mutable; * @author Matthias Zenger * @version 1.0, 08/07/2003 */ -abstract class ObservableBuffer[A, This <: ObservableBuffer[A, This]]: This +[_trait_] abstract class ObservableBuffer[A, This <: ObservableBuffer[A, This]]: This extends Buffer[A] with Publisher[Message[Pair[Location, A]] with Undoable, This] { diff --git a/sources/scala/collection/mutable/ObservableMap.scala b/sources/scala/collection/mutable/ObservableMap.scala index 1b682573ae..207a294753 100644 --- a/sources/scala/collection/mutable/ObservableMap.scala +++ b/sources/scala/collection/mutable/ObservableMap.scala @@ -18,7 +18,7 @@ package scala.collection.mutable; * @author Matthias Zenger * @version 1.0, 08/07/2003 */ -abstract class ObservableMap[A, B, This <: ObservableMap[A, B, This]]: This +[_trait_] abstract class ObservableMap[A, B, This <: ObservableMap[A, B, This]]: This extends scala.collection.mutable.Map[A, B] with Publisher[Message[Pair[A, B]] with Undoable, This] { diff --git a/sources/scala/collection/mutable/ObservableSet.scala b/sources/scala/collection/mutable/ObservableSet.scala index 2d0437f8c9..656545d78e 100644 --- a/sources/scala/collection/mutable/ObservableSet.scala +++ b/sources/scala/collection/mutable/ObservableSet.scala @@ -18,7 +18,7 @@ package scala.collection.mutable; * @author Matthias Zenger * @version 1.0, 08/07/2003 */ -abstract class ObservableSet[A, This <: ObservableSet[A, This]]: This +[_trait_] abstract class ObservableSet[A, This <: ObservableSet[A, This]]: This extends scala.collection.mutable.Set[A] with Publisher[Message[A] with Undoable, This] { diff --git a/sources/scala/collection/mutable/Publisher.scala b/sources/scala/collection/mutable/Publisher.scala index 7042c63289..ee442eccd2 100644 --- a/sources/scala/collection/mutable/Publisher.scala +++ b/sources/scala/collection/mutable/Publisher.scala @@ -20,7 +20,7 @@ package scala.collection.mutable; * @author Matthias Zenger * @version 1.0, 08/07/2003 */ -abstract class Publisher[A, This <: Publisher[A, This]]: This { +[_trait_] abstract class Publisher[A, This <: Publisher[A, This]]: This { private val filters = new HashMap[Subscriber[A, This], scala.collection.mutable.Set[A => Boolean]] with MultiMap[Subscriber[A, This], A => Boolean]; diff --git a/sources/scala/collection/mutable/ResizableArray.scala b/sources/scala/collection/mutable/ResizableArray.scala index 410722c56d..5f1c5f053c 100644 --- a/sources/scala/collection/mutable/ResizableArray.scala +++ b/sources/scala/collection/mutable/ResizableArray.scala @@ -17,7 +17,7 @@ package scala.collection.mutable; * @version 1.0, 03/05/2004 */ [serializable] -abstract class ResizableArray[A] extends AnyRef with Iterable[A] { +[_trait_] abstract class ResizableArray[A] extends AnyRef with Iterable[A] { import scala.runtime.compat.Platform.arraycopy; protected val initialSize: Int = 16; diff --git a/sources/scala/concurrent/MailBox.scala b/sources/scala/concurrent/MailBox.scala index 573b05a7a0..74935cf638 100644 --- a/sources/scala/concurrent/MailBox.scala +++ b/sources/scala/concurrent/MailBox.scala @@ -11,7 +11,7 @@ package scala.concurrent; //class MailBox with Monitor with LinkedListQueueCreator { -abstract class MailBox extends AnyRef with ListQueueCreator { +[_trait_] abstract class MailBox extends AnyRef with ListQueueCreator { type Message = AnyRef; diff --git a/sources/scala/tools/nsc/CompilationUnits.scala b/sources/scala/tools/nsc/CompilationUnits.scala index c3320d22d9..f211bab1c1 100644 --- a/sources/scala/tools/nsc/CompilationUnits.scala +++ b/sources/scala/tools/nsc/CompilationUnits.scala @@ -8,7 +8,7 @@ package scala.tools.nsc; import scala.tools.util.{SourceFile, Position}; import scala.tools.nsc.util.FreshNameCreator; -abstract class CompilationUnits: Global { +[_trait_] abstract class CompilationUnits: Global { class CompilationUnit(val source: SourceFile, val mixinOnly: boolean) { diff --git a/sources/scala/tools/nsc/ast/TreePrinters.scala b/sources/scala/tools/nsc/ast/TreePrinters.scala index 07623404ee..509ad67d62 100644 --- a/sources/scala/tools/nsc/ast/TreePrinters.scala +++ b/sources/scala/tools/nsc/ast/TreePrinters.scala @@ -97,7 +97,8 @@ abstract class TreePrinters { print("<empty>"); case ClassDef(mods, name, tparams, tp, impl) => - printFlags(tree, mods); print("class " + symName(tree, name)); + printFlags(tree, mods); + print((if ((mods & TRAIT) != 0) "trait " else "class ") + symName(tree, name)); printTypeParams(tparams); printOpt(": ", tp); print(" extends "); print(impl); diff --git a/sources/scala/tools/nsc/ast/Trees.scala b/sources/scala/tools/nsc/ast/Trees.scala index 80a8216c5f..357aeae666 100644 --- a/sources/scala/tools/nsc/ast/Trees.scala +++ b/sources/scala/tools/nsc/ast/Trees.scala @@ -10,7 +10,7 @@ import java.io.PrintWriter; import scala.tools.util.Position; import symtab.Flags._; -abstract class Trees: Global { +[_trait_] abstract class Trees: Global { //statistics var nodeCount = 0; @@ -60,20 +60,20 @@ abstract class Trees: Global { } } - abstract class SymTree extends Tree { + [_trait_] abstract class SymTree extends Tree { override def hasSymbol = true; override var symbol: Symbol = NoSymbol; } - abstract class DefTree extends SymTree { + trait DefTree extends SymTree { override def isDef = true } - abstract class TermTree extends Tree { + trait TermTree extends Tree { override def isTerm = true } - abstract class TypTree extends Tree { + trait TypTree extends Tree { override def isType = true } @@ -172,6 +172,7 @@ abstract class Trees: Global { def DefDef(sym: Symbol, vparamss: List[List[ValDef]], rhs: Tree): DefDef = posAssigner.atPos(sym.pos) { + assert(sym != NoSymbol); DefDef(flags2mods(sym.flags), sym.name, sym.typeParams map AbsTypeDef, diff --git a/sources/scala/tools/nsc/ast/parser/Parsers.scala b/sources/scala/tools/nsc/ast/parser/Parsers.scala index 450a32f737..90b383f59c 100755 --- a/sources/scala/tools/nsc/ast/parser/Parsers.scala +++ b/sources/scala/tools/nsc/ast/parser/Parsers.scala @@ -38,7 +38,7 @@ import Tokens._; * (4) Wraps naked case definitions in a match as follows: * { cases } ==> (x => x.match {cases}), except when already argument to match */ -abstract class Parsers: SyntaxAnalyzer { +[_trait_] abstract class Parsers: SyntaxAnalyzer { import global._; import posAssigner.atPos; @@ -1470,7 +1470,7 @@ abstract class Parsers: SyntaxAnalyzer { */ def tmplDef(mods: int): Tree = in.token match { case TRAIT => - classDef(mods | Flags.ABSTRACT); + classDef(mods | Flags.TRAIT | Flags.ABSTRACT); case CLASS => classDef(mods); case CASECLASS => @@ -1495,11 +1495,8 @@ abstract class Parsers: SyntaxAnalyzer { if ((mods & Flags.CASE) != 0 && in.token != LPAREN) accept(LPAREN); val vparamss = paramClauses(name, implicitViews.toList, (mods & Flags.CASE) != 0); val thistpe = simpleTypedOpt(); - val mods1 = if (vparamss.isEmpty && (mods & Flags.ABSTRACT) != 0) { - mods | Flags.TRAIT - } else mods; - val template = classTemplate(mods1, name, vparamss); - ClassDef(mods1, name, tparams, thistpe, template) + val template = classTemplate(mods, name, vparamss); + ClassDef(mods, name, tparams, thistpe, template) } /** ObjectDef ::= Id ClassTemplate @@ -1600,8 +1597,9 @@ abstract class Parsers: SyntaxAnalyzer { in.token == CASEOBJECT || in.token == LBRACKET || isModifier) { + val attrs = attributeClauses(); stats ++ - joinAttributes(attributeClauses(), joinComment(List(tmplDef(modifiers())))) + joinAttributes(attrs, joinComment(List(tmplDef(modifiers() | traitAttribute(attrs))))) } else if (in.token != SEMI) { syntaxError("illegal start of class or object definition", true); } @@ -1625,8 +1623,9 @@ abstract class Parsers: SyntaxAnalyzer { } else if (isExprIntro) { stats += expr() } else if (isDefIntro || isModifier || in.token == LBRACKET) { + val attrs = attributeClauses(); stats ++ - joinAttributes(attributeClauses(), joinComment(defOrDcl(modifiers()))) + joinAttributes(attrs, joinComment(defOrDcl(modifiers() | traitAttribute(attrs)))) } else if (in.token != SEMI) { syntaxError("illegal start of definition", true); } @@ -1663,6 +1662,16 @@ abstract class Parsers: SyntaxAnalyzer { atPos(pos) { New(t, List(args)) } } + def traitAttribute(attrs: List[Tree]) = { + def isTraitAttribute(attr: Tree) = attr match { + case Apply(Select(New(Ident(name)), constr), List()) if (name.toString() == "_trait_") => + true + case _ => + false + } + if (attrs exists isTraitAttribute) Flags.TRAIT else 0 + } + def joinAttributes(attrs: List[Tree], defs: List[Tree]): List[Tree] = defs map (defn => (attrs :\ defn) ((attr, tree) => Attributed(attr, tree) setPos attr.pos)); diff --git a/sources/scala/tools/nsc/ast/parser/Scanners.scala b/sources/scala/tools/nsc/ast/parser/Scanners.scala index 6a015a4d64..3cda4e3a83 100755 --- a/sources/scala/tools/nsc/ast/parser/Scanners.scala +++ b/sources/scala/tools/nsc/ast/parser/Scanners.scala @@ -10,7 +10,7 @@ import scala.tools.util.{Position, SourceFile} import SourceFile.{LF, FF, CR, SU} import scala.tools.nsc.util.CharArrayReader; -abstract class Scanners: SyntaxAnalyzer { +[_trait_] abstract class Scanners: SyntaxAnalyzer { import global._; diff --git a/sources/scala/tools/nsc/backend/icode/Opcodes.scala b/sources/scala/tools/nsc/backend/icode/Opcodes.scala index 7013e1b965..2c5e3e73a6 100644 --- a/sources/scala/tools/nsc/backend/icode/Opcodes.scala +++ b/sources/scala/tools/nsc/backend/icode/Opcodes.scala @@ -47,7 +47,7 @@ import scala.tools.nsc.ast._; * erased types of Scala and references Symbols to refer named entities * in the source files. */ -abstract class Opcodes: ICodes { +[_trait_] abstract class Opcodes: ICodes { import global.{Symbol, NoSymbol, Type, Name, Constant}; /** This class represents an instruction of the intermediate code. diff --git a/sources/scala/tools/nsc/backend/icode/Primitives.scala b/sources/scala/tools/nsc/backend/icode/Primitives.scala index 9cb2a0ca72..6f77b21bc4 100644 --- a/sources/scala/tools/nsc/backend/icode/Primitives.scala +++ b/sources/scala/tools/nsc/backend/icode/Primitives.scala @@ -9,7 +9,7 @@ package scala.tools.nsc.backend.icode; import java.io.PrintWriter; -abstract class Primitives: ICodes { +[_trait_] abstract class Primitives: ICodes { /** This class represents a primitive operation. */ class Primitive { diff --git a/sources/scala/tools/nsc/backend/icode/TypeKinds.scala b/sources/scala/tools/nsc/backend/icode/TypeKinds.scala index 7d67b682cc..6b23b8c082 100644 --- a/sources/scala/tools/nsc/backend/icode/TypeKinds.scala +++ b/sources/scala/tools/nsc/backend/icode/TypeKinds.scala @@ -25,7 +25,7 @@ package scala.tools.nsc.backend.icode; import scala.collection.mutable.{Map, HashMap}; -abstract class TypeKinds: ICodes { +[_trait_] abstract class TypeKinds: ICodes { import global._; /** This class represents a type kind. Type kinds diff --git a/sources/scala/tools/nsc/matching/CodeFactory.scala b/sources/scala/tools/nsc/matching/CodeFactory.scala index a28d76178c..0bf42a838e 100644 --- a/sources/scala/tools/nsc/matching/CodeFactory.scala +++ b/sources/scala/tools/nsc/matching/CodeFactory.scala @@ -5,7 +5,7 @@ package scala.tools.nsc.matching ; import scala.tools.util.Position; -abstract class CodeFactory: TransMatcher { +[_trait_] abstract class CodeFactory: TransMatcher { import global._ ; diff --git a/sources/scala/tools/nsc/matching/MatcherLabels.scala b/sources/scala/tools/nsc/matching/MatcherLabels.scala index ebf8dfc2cb..d1b8592e3f 100644 --- a/sources/scala/tools/nsc/matching/MatcherLabels.scala +++ b/sources/scala/tools/nsc/matching/MatcherLabels.scala @@ -1,6 +1,6 @@ package scala.tools.nsc.matching ; -abstract class MatcherLabels: TransMatcher { +[_trait_] abstract class MatcherLabels: TransMatcher { import global._ ; diff --git a/sources/scala/tools/nsc/symtab/Constants.scala b/sources/scala/tools/nsc/symtab/Constants.scala index 42bba1f735..165ff705d4 100755 --- a/sources/scala/tools/nsc/symtab/Constants.scala +++ b/sources/scala/tools/nsc/symtab/Constants.scala @@ -9,7 +9,7 @@ package scala.tools.nsc.symtab; import classfile.PickleFormat._; -abstract class Constants: SymbolTable { +[_trait_] abstract class Constants: SymbolTable { import definitions._; diff --git a/sources/scala/tools/nsc/symtab/Definitions.scala b/sources/scala/tools/nsc/symtab/Definitions.scala index 37b4330575..b5a572d19a 100755 --- a/sources/scala/tools/nsc/symtab/Definitions.scala +++ b/sources/scala/tools/nsc/symtab/Definitions.scala @@ -9,7 +9,7 @@ import scala.tools.util.Position; import collection.mutable.HashMap; import Flags._; -abstract class Definitions: SymbolTable { +[_trait_] abstract class Definitions: SymbolTable { object definitions { @@ -78,6 +78,7 @@ abstract class Definitions: SymbolTable { def SeqFactory = getMember(ScalaRunTimeModule, "Seq"); var RepeatedParamClass: Symbol = _; var ByNameParamClass: Symbol = _; + var TraitClass: Symbol = _; val MaxTupleArity = 9; val MaxFunctionArity = 9; @@ -331,6 +332,7 @@ abstract class Definitions: SymbolTable { tparam => typeRef(SeqClass.typeConstructor.prefix, SeqClass, List(tparam.typeConstructor))); ByNameParamClass = newCovariantPolyClass( ScalaPackageClass, nme.BYNAME_PARAM_CLASS_NAME, tparam => AnyClass.typeConstructor); + TraitClass = getClass("scala._trait_"); TupleClass = new Array(MaxTupleArity + 1); for (val i <- List.range(1, MaxTupleArity + 1)) TupleClass(i) = getClass("scala.Tuple" + i); diff --git a/sources/scala/tools/nsc/symtab/InfoTransformers.scala b/sources/scala/tools/nsc/symtab/InfoTransformers.scala index 6489302aeb..e1ff9bbac5 100644 --- a/sources/scala/tools/nsc/symtab/InfoTransformers.scala +++ b/sources/scala/tools/nsc/symtab/InfoTransformers.scala @@ -5,7 +5,7 @@ // $Id$ package scala.tools.nsc.symtab; -abstract class InfoTransformers: SymbolTable { +[_trait_] abstract class InfoTransformers: SymbolTable { abstract class InfoTransformer { var prev: InfoTransformer = this; diff --git a/sources/scala/tools/nsc/symtab/Scopes.scala b/sources/scala/tools/nsc/symtab/Scopes.scala index 634fd280ed..fe8ffaa47b 100755 --- a/sources/scala/tools/nsc/symtab/Scopes.scala +++ b/sources/scala/tools/nsc/symtab/Scopes.scala @@ -5,7 +5,7 @@ // $Id$ package scala.tools.nsc.symtab; -abstract class Scopes: SymbolTable { +[_trait_] abstract class Scopes: SymbolTable { class ScopeEntry(val sym: Symbol, val owner: Scope) { diff --git a/sources/scala/tools/nsc/symtab/StdNames.scala b/sources/scala/tools/nsc/symtab/StdNames.scala index 1bade64f38..4dbf4d8850 100755 --- a/sources/scala/tools/nsc/symtab/StdNames.scala +++ b/sources/scala/tools/nsc/symtab/StdNames.scala @@ -7,7 +7,7 @@ package scala.tools.nsc.symtab; import scala.tools.nsc.util.NameTransformer; -abstract class StdNames: SymbolTable { +[_trait_] abstract class StdNames: SymbolTable { object nme { diff --git a/sources/scala/tools/nsc/symtab/Symbols.scala b/sources/scala/tools/nsc/symtab/Symbols.scala index 626ed445f3..f4459cd4d8 100755 --- a/sources/scala/tools/nsc/symtab/Symbols.scala +++ b/sources/scala/tools/nsc/symtab/Symbols.scala @@ -8,7 +8,7 @@ package scala.tools.nsc.symtab; import scala.tools.util.{AbstractFile, Position} import Flags._; -abstract class Symbols: SymbolTable { +[_trait_] abstract class Symbols: SymbolTable { import definitions._; private var ids = 0; @@ -194,7 +194,7 @@ abstract class Symbols: SymbolTable { * A class is local, if * - it is anonymous, or * - its owner is a value - * - it is defined within a local class + * - it is defined within a local class214 */ final def isLocalClass: boolean = isClass && (isAnonymousClass || isRefinementClass || isLocal || @@ -207,9 +207,11 @@ abstract class Symbols: SymbolTable { * (2) it is abstract override and its super symbol in `base' is nonexistent or inclomplete. */ final def isIncompleteIn(base: Symbol): boolean = - (base == NoSymbol) || (this hasFlag DEFERRED) || - (this hasFlag ABSOVERRIDE) && isIncompleteIn(superSymbol(base)); + (this hasFlag ABSOVERRIDE) && { + val supersym = superSymbol(base); + supersym == NoSymbol || supersym.isIncompleteIn(base) + } final def isInitialized: boolean = validForRun == currentRun; @@ -545,7 +547,7 @@ abstract class Symbols: SymbolTable { /** The symbol overridden by this symbol in given base class */ final def overriddenSymbol(base: Symbol): Symbol = base.info.nonPrivateDecl(name).suchThat(sym => - !sym.isTerm || (owner.thisType.memberType(sym) matches tpe)); + !sym.isTerm || (tpe matches owner.thisType.memberType(sym))); /** The symbol overriding this symbol in given subclass */ final def overridingSymbol(base: Symbol): Symbol = @@ -560,7 +562,8 @@ abstract class Symbols: SymbolTable { var bcs = base.info.baseClasses.dropWhile(owner !=).tail; var sym: Symbol = NoSymbol; while (!bcs.isEmpty && sym == NoSymbol) { - sym = overriddenSymbol(bcs.head).suchThat(sym => !sym.hasFlag(DEFERRED)); + if (!bcs.head.isImplClass) + sym = overriddenSymbol(bcs.head).suchThat(sym => !sym.hasFlag(DEFERRED)); bcs = bcs.tail } sym diff --git a/sources/scala/tools/nsc/symtab/Types.scala b/sources/scala/tools/nsc/symtab/Types.scala index cf8e81b6e2..2d89000518 100755 --- a/sources/scala/tools/nsc/symtab/Types.scala +++ b/sources/scala/tools/nsc/symtab/Types.scala @@ -28,7 +28,7 @@ import Flags._; case TypeVar(_, _) => */ -abstract class Types: SymbolTable { +[_trait_] abstract class Types: SymbolTable { import definitions._; //statistics @@ -178,8 +178,11 @@ abstract class Types: SymbolTable { sym.info.asSeenFrom(this, sym.owner); /** The type of `sym', seen as a memeber of this type. */ - def memberType(sym: Symbol): Type = - sym.tpe.asSeenFrom(this, sym.owner); + def memberType(sym: Symbol): Type = { + val result = sym.tpe.asSeenFrom(this, sym.owner); + /*System.out.println("" + this + ".memberType(" + sym + ") = " + result);*/ + result + } /** Substitute types `to' for occurrences of references to symbols `from' * in this type. */ @@ -295,9 +298,7 @@ abstract class Types: SymbolTable { def complete(sym: Symbol): unit = { if (sym == NoSymbol || sym.isPackageClass) sym.validForRun = currentRun else { - /*if (sym.owner.isClass) complete(sym.owner);*/ val this1 = adaptToNewRunMap(this); - //System.out.println("adapting " + sym);//DEBUG if (this1 eq this) sym.validForRun = currentRun else { //System.out.println("new type of " + sym + "=" + this1);//DEBUG @@ -403,7 +404,7 @@ abstract class Types: SymbolTable { // Subclasses ------------------------------------------------------------ - abstract class UniqueType { + [_trait_] abstract class UniqueType { private val hashcode = { val h = super.hashCode(); if (h < 0) -h else h } override def hashCode() = hashcode; } @@ -765,6 +766,8 @@ abstract class Types: SymbolTable { override def toString(): String = paramTypes.mkString("(implicit ", ",", ")") + resultType; } + class JavaMethodType(pts: List[Type], rt: Type) extends MethodType(pts, rt); + /** A class representing a polymorphic type or, if tparams.length == 0, * a parameterless method type. */ @@ -918,6 +921,10 @@ abstract class Types: SymbolTable { def ImplicitMethodType(paramTypes: List[Type], resultType: Type): ImplicitMethodType = new ImplicitMethodType(paramTypes, resultType); // don't unique this! + /** The canonical creator for implicit method types */ + def JavaMethodType(paramTypes: List[Type], resultType: Type): JavaMethodType = + new JavaMethodType(paramTypes, resultType); // don't unique this! + /** A creator for intersection type where intersections of a single type are * replaced by the type itself. */ def intersectionType(tps: List[Type], owner: Symbol): Type = tps match { @@ -1071,6 +1078,7 @@ abstract class Types: SymbolTable { val result1 = this(result); if ((paramtypes1 eq paramtypes) && (result1 eq result)) tp else if (tp.isInstanceOf[ImplicitMethodType]) ImplicitMethodType(paramtypes1, result1) + else if (tp.isInstanceOf[JavaMethodType]) JavaMethodType(paramtypes1, result1) else MethodType(paramtypes1, result1) case PolyType(tparams, result) => val tparams1 = mapOver(tparams); @@ -1145,7 +1153,8 @@ abstract class Types: SymbolTable { if (symclazz == clazz && (pre.widen.symbol isSubClass symclazz)) pre.baseType(symclazz) match { case TypeRef(_, basesym, baseargs) => - assert(basesym.typeParams.length == baseargs.length);//debug + if (basesym.typeParams.length != baseargs.length) + assert(false, "asSeenFrom(" + pre + "," + clazz + ")" + sym + " " + basesym + " " + baseargs); //debug instParam(basesym.typeParams, baseargs); case _ => throwError @@ -1447,7 +1456,7 @@ abstract class Types: SymbolTable { sym1 == AllRefClass && sym2 != AllClass && tp2 <:< AnyRefClass.tpe case Pair(MethodType(pts1, res1), MethodType(pts2, res2)) => pts1.length == pts2.length && - isSameTypes(pts1, pts2) && + matchingParams(pts1, pts2, tp2.isInstanceOf[JavaMethodType]) && (res1 <:< res2) && tp1.isInstanceOf[ImplicitMethodType] == tp2.isInstanceOf[ImplicitMethodType] case Pair(PolyType(tparams1, res1), PolyType(tparams2, res2)) => @@ -1496,7 +1505,7 @@ abstract class Types: SymbolTable { * we might return false negatives */ def specializesSym(tp: Type, sym: Symbol): boolean = tp.symbol == AllClass || - tp.symbol == AllRefClass && (sym.owner isSubClass AnyRefClass) || + tp.symbol == AllRefClass && (sym.owner isSubClass ObjectClass) || (tp.nonPrivateMember(sym.name).alternatives exists (alt => sym == alt || specializesSym(tp.narrow, alt, sym.owner.thisType, sym))); @@ -1515,7 +1524,7 @@ abstract class Types: SymbolTable { /** A function implementing tp1 matches tp2 */ private def matchesType(tp1: Type, tp2: Type): boolean = Pair(tp1, tp2) match { case Pair(MethodType(pts1, res1), MethodType(pts2, res2)) => - isSameTypes(pts1, pts2) && (res1 matches res2) && + matchingParams(pts1, pts2, tp2.isInstanceOf[JavaMethodType]) && (res1 matches res2) && tp1.isInstanceOf[ImplicitMethodType] == tp2.isInstanceOf[ImplicitMethodType] case Pair(PolyType(tparams1, res1), PolyType(tparams2, res2)) => tparams1.length == tparams2.length && @@ -1530,6 +1539,12 @@ abstract class Types: SymbolTable { !phase.erasedTypes || tp1 =:= tp2 } + /** Are tps1 and tps2 lists of pairwise equivalent types? */ + private def matchingParams(tps1: List[Type], tps2: List[Type], tps2isJava: boolean): boolean = + tps1.length == tps2.length && + List.forall2(tps1, tps2)((tp1, tp2) => + (tp1 =:= tp2) || tps2isJava & tp1.symbol == ObjectClass && tp2.symbol == AnyClass); + /** Prepend type `tp' to closure `cl' */ private def addClosure(tp: Type, cl: Array[Type]): Array[Type] = { val cl1 = new Array[Type](cl.length + 1); diff --git a/sources/scala/tools/nsc/symtab/classfile/ClassfileParser.scala b/sources/scala/tools/nsc/symtab/classfile/ClassfileParser.scala index beb70991a5..ff61c0cb9f 100755 --- a/sources/scala/tools/nsc/symtab/classfile/ClassfileParser.scala +++ b/sources/scala/tools/nsc/symtab/classfile/ClassfileParser.scala @@ -213,7 +213,7 @@ abstract class ClassfileParser { while ('0' <= name(index) && name(index) <= '9') index = index + 1; appliedType(definitions.ArrayClass.tpe, List(sig2type)) case '(' => - MethodType(paramsigs2types, sig2type) + JavaMethodType(paramsigs2types, sig2type) } } sig2type diff --git a/sources/scala/tools/nsc/symtab/classfile/PickleFormat.scala b/sources/scala/tools/nsc/symtab/classfile/PickleFormat.scala index 76b75356e1..30967e2e9f 100755 --- a/sources/scala/tools/nsc/symtab/classfile/PickleFormat.scala +++ b/sources/scala/tools/nsc/symtab/classfile/PickleFormat.scala @@ -44,7 +44,7 @@ object PickleFormat { * | 33 LITERALstring len_Nat name_Ref * | 34 LITERALnull len_Nat * | 35 LITERALzero len_Nat - * | 36 ATTRIBUTE sym_Ref type_Ref {constant_Ref} + * | 36 ATTRIBUTE sym_Ref type_Ref {constant_Ref} <not yet> * SymbolInfo = name_Ref owner_Ref flags_Nat info_Ref * NameInfo = <character sequence of length len_Nat in Utf8 format> * NumInfo = <len_Nat-byte signed number in big endian format> diff --git a/sources/scala/tools/nsc/symtab/classfile/Pickler.scala b/sources/scala/tools/nsc/symtab/classfile/Pickler.scala index 6efdc34a37..3e7df0a315 100755 --- a/sources/scala/tools/nsc/symtab/classfile/Pickler.scala +++ b/sources/scala/tools/nsc/symtab/classfile/Pickler.scala @@ -86,6 +86,7 @@ abstract class Pickler extends SubComponent { if (sym.thisSym != sym) putType(sym.typeOfThis); putSymbol(sym.alias); + //for (val attr <- sym.attributes) putAttribute(sym, attr); } else if (sym != NoSymbol) { putEntry(if (sym.isModuleClass) sym.name.toTermName else sym.name); if (!sym.owner.isRoot) putSymbol(sym.owner); @@ -125,6 +126,12 @@ abstract class Pickler extends SubComponent { private def putConstant(c: Constant) = if (putEntry(c) && c.tag == StringTag) putEntry(newTermName(c.stringValue)); +/* + private def putAttribute(attr: AttrInfo): unit = if (putEntry(attr)) { + putType(attr._1); + for (val c <- attr._2) putConstant(c); + } +*/ // Phase 2 methods: Write all entries to byte array ------------------------------ private val buf = new PickleBuffer(new Array[byte](4096), -1, 0); @@ -207,6 +214,12 @@ abstract class Pickler extends SubComponent { else if (c.tag == DoubleTag) writeLong(Double.doubleToLongBits(c.doubleValue)); else if (c.tag == StringTag) writeRef(newTermName(c.stringValue)); LITERAL + c.tag +/* + case Pair(tp, cs) => + writeRef(tp); + for (val c <- cs) writeRef(cs); + ATTRIBUTE +*/ case _ => throw new FatalError("bad entry: " + entry + " " + entry.getClass());//debug } diff --git a/sources/scala/tools/nsc/transform/Mixin.scala b/sources/scala/tools/nsc/transform/Mixin.scala index bf8c94e572..6e70bfc31a 100755 --- a/sources/scala/tools/nsc/transform/Mixin.scala +++ b/sources/scala/tools/nsc/transform/Mixin.scala @@ -27,21 +27,23 @@ abstract class Mixin extends InfoTransform { private def toInterface(tp: Type): Type = tp.symbol.toInterface.tpe; - private def rebindSuper(base: Symbol, member: Symbol, prevowner: Symbol): Symbol = { - var bcs = base.info.baseClasses.dropWhile(prevowner !=).tail; - assert(!bcs.isEmpty, "" + prevowner + " " + base.info.baseClasses);//debug - var sym: Symbol = NoSymbol; - while (!bcs.isEmpty && sym == NoSymbol) { - if (settings.debug.value) { - val other = bcs.head.info.nonPrivateDecl(member.name); - log("rebindsuper " + bcs.head + " " + other + " " + other.tpe + " " + sym.tpe + " " + other.hasFlag(DEFERRED)); + private def rebindSuper(base: Symbol, member: Symbol, prevowner: Symbol): Symbol = + atPhase(currentRun.refchecksPhase) { + var bcs = base.info.baseClasses.dropWhile(prevowner !=).tail; + assert(!bcs.isEmpty/*, "" + prevowner + " " + base.info.baseClasses*/);//DEBUG + var sym: Symbol = NoSymbol; + if (settings.debug.value) log("starting rebindsuper " + base + " " + member + ":" + member.tpe + " " + prevowner + " " + base.info.baseClasses); + while (!bcs.isEmpty && sym == NoSymbol) { + if (settings.debug.value) { + val other = bcs.head.info.nonPrivateDecl(member.name); + log("rebindsuper " + bcs.head + " " + other + " " + other.tpe + " " + other.hasFlag(DEFERRED)); + } + sym = member.overridingSymbol(bcs.head).suchThat(sym => !sym.hasFlag(DEFERRED)); + bcs = bcs.tail } - sym = member.overridingSymbol(bcs.head).suchThat(sym => !sym.hasFlag(DEFERRED)); - bcs = bcs.tail + assert(sym != NoSymbol, member); + sym } - assert(sym != NoSymbol, member); - sym - } private def implClass(iface: Symbol): Symbol = erasure.implClass(iface); @@ -121,7 +123,8 @@ abstract class Mixin extends InfoTransform { } else if (member hasFlag SUPERACCESSOR) { val member1 = addMember(clazz, member.cloneSymbol(clazz)) setFlag MIXEDIN; assert(member1.alias != NoSymbol, member1); - member1.asInstanceOf[TermSymbol] setAlias rebindSuper(clazz, member.alias, bc); + val alias1 = rebindSuper(clazz, member.alias, bc); + member1.asInstanceOf[TermSymbol] setAlias alias1; } else if (member.isMethod && member.isModule && !(member hasFlag (LIFTED | BRIDGE))) { addMember(clazz, member.cloneSymbol(clazz) setFlag MIXEDIN) } @@ -235,15 +238,17 @@ abstract class Mixin extends InfoTransform { if (stat.symbol hasFlag SUPERACCESSOR) => assert(stat.symbol hasFlag MIXEDIN, stat); val rhs1 = - localTyper.typed { - atPos(stat.pos) { - Apply(Select(Super(clazz, nme.EMPTY.toTypeName), stat.symbol.alias), - vparams map (vparam => Ident(vparam.symbol))) + postTransform { + localTyper.typed { + atPos(stat.pos) { + Apply(Select(Super(clazz, nme.EMPTY.toTypeName), stat.symbol.alias), + vparams map (vparam => Ident(vparam.symbol))) + } } } - copy.DefDef(stat, mods, name, tparams, List(vparams), tpt, rhs1) + //System.out.println("complete super acc " + stat.symbol + stat.symbol.locationString + " " + rhs1 + " " + stat.symbol.alias + stat.symbol.alias.locationString);//DEBUG + copy.DefDef(stat, mods, name, tparams, List(vparams), tpt, localTyper.typed(rhs1)) case _ => - assert(!(stat.symbol hasFlag SUPERACCESSOR), stat); stat } var stats1 = stats; @@ -252,6 +257,7 @@ abstract class Mixin extends InfoTransform { if ((sym hasFlag SYNTHETIC) && (sym hasFlag ACCESSOR)) addDefDef(sym, vparamss => EmptyTree) } + if (newDefs.hasNext) stats1 = stats1 ::: newDefs.toList; } else if (!clazz.isTrait) { for (val sym <- clazz.info.decls.toList) { if (sym hasFlag MIXEDIN) { @@ -268,19 +274,21 @@ abstract class Mixin extends InfoTransform { addDef(position(sym), refchecks.newModuleAccessDef(sym, vdef.symbol)); } else if (!sym.isMethod) { addDef(position(sym), ValDef(sym)) - } else if (!(sym hasFlag SUPERACCESSOR)) { + } else if (sym hasFlag SUPERACCESSOR) { + addDefDef(sym, vparams => EmptyTree) + } else { assert(sym.alias != NoSymbol, sym); addDefDef(sym, vparams => Apply(staticRef(sym.alias), gen.This(clazz) :: (vparams map Ident))) } } } - stats1 = stats map completeSuperAccessor; + if (newDefs.hasNext) stats1 = stats1 ::: newDefs.toList; } - if (newDefs.hasNext) stats1 ::: newDefs.toList else stats1 + if (clazz.isTrait) stats1 else stats1 map completeSuperAccessor; } - private def postTransform(tree: Tree): Tree = atPhase(phase.next) { + private def postTransform(tree: Tree): Tree = { val sym = tree.symbol; tree match { case Template(parents, body) => @@ -296,7 +304,17 @@ abstract class Mixin extends InfoTransform { Apply(staticRef(sym), qual :: args) } } - } else tree + } else if (qual.isInstanceOf[Super] && (sym.owner hasFlag lateINTERFACE)) { + val sym1 = atPhase(phase.prev)(sym.overridingSymbol(sym.owner.implClass)); + assert(sym1 != NoSymbol, sym); + localTyper.typed { + atPos(tree.pos) { + Apply(staticRef(sym1), gen.This(currentOwner.enclClass) :: args) + } + } + } else { + tree + } case This(_) if tree.symbol.isImplClass => assert(tree.symbol == currentOwner.enclClass, "" + tree + " " + tree.symbol + " " + currentOwner.enclClass); selfRef(tree.pos) @@ -314,6 +332,7 @@ abstract class Mixin extends InfoTransform { } else { copy.Select(tree, selfRef(qual.pos), name) } + } else { if (mix == nme.EMPTY.toTypeName) tree else copy.Select(tree, gen.This(currentOwner.enclClass) setPos qual.pos, name) @@ -355,7 +374,8 @@ abstract class Mixin extends InfoTransform { override def transform(tree: Tree): Tree = { try { //debug - postTransform(super.transform(preTransform(tree))) + val tree1 = super.transform(preTransform(tree)); + atPhase(phase.next)(postTransform(tree1)) } catch { case ex: Throwable => System.out.println("exception when traversing " + tree); diff --git a/sources/scala/tools/nsc/typechecker/Analyzer.scala b/sources/scala/tools/nsc/typechecker/Analyzer.scala index 5c974bbb7a..5789f5fe86 100644 --- a/sources/scala/tools/nsc/typechecker/Analyzer.scala +++ b/sources/scala/tools/nsc/typechecker/Analyzer.scala @@ -7,7 +7,7 @@ package scala.tools.nsc.typechecker; /** The main attribution phase. */ -abstract class Analyzer +[_trait_] abstract class Analyzer extends AnyRef with Contexts with Namers diff --git a/sources/scala/tools/nsc/typechecker/Contexts.scala b/sources/scala/tools/nsc/typechecker/Contexts.scala index 0a32baab75..e27af37e13 100755 --- a/sources/scala/tools/nsc/typechecker/Contexts.scala +++ b/sources/scala/tools/nsc/typechecker/Contexts.scala @@ -8,7 +8,7 @@ package scala.tools.nsc.typechecker; import symtab.Flags._; import scala.tools.util.Position; -abstract class Contexts: Analyzer { +[_trait_] abstract class Contexts: Analyzer { import global._; val NoContext = new Context { @@ -153,7 +153,7 @@ abstract class Contexts: Analyzer { override def toString(): String = { if (this == NoContext) "NoContext"; - else owner.toString() + " @ " + tree.getClass() + " " + tree.toString() + ", scope = " + scope.hashCode() + "\n:: " + outer.toString() + else owner.toString() + " @ " + tree.getClass() + " " + tree.toString() + ", scope = " + scope.hashCode() + " " + scope.toList + "\n:: " + outer.toString() } /** Is `sym' accessible as a member of tree `site' with type `pre' in current context? diff --git a/sources/scala/tools/nsc/typechecker/EtaExpansion.scala b/sources/scala/tools/nsc/typechecker/EtaExpansion.scala index 27bc991283..3d1bc528ec 100644 --- a/sources/scala/tools/nsc/typechecker/EtaExpansion.scala +++ b/sources/scala/tools/nsc/typechecker/EtaExpansion.scala @@ -8,7 +8,7 @@ package scala.tools.nsc.typechecker; import util.ListBuffer; import symtab.Flags._; -abstract class EtaExpansion: Analyzer { +[_trait_] abstract class EtaExpansion: Analyzer { import global._; import posAssigner.atPos; diff --git a/sources/scala/tools/nsc/typechecker/Infer.scala b/sources/scala/tools/nsc/typechecker/Infer.scala index 580dd3b20b..1b0ca1097f 100755 --- a/sources/scala/tools/nsc/typechecker/Infer.scala +++ b/sources/scala/tools/nsc/typechecker/Infer.scala @@ -5,7 +5,7 @@ // $Id$ package scala.tools.nsc.typechecker; -abstract class Infer: Analyzer { +[_trait_] abstract class Infer: Analyzer { import symtab.Flags._; import global._; import definitions._; @@ -491,11 +491,12 @@ abstract class Infer: Analyzer { /** Assign `tree' the symbol and type of the alternative which matches * prototype `pt', if it exists. * If several alternatives match `pt', take parameterless one. - * Error if no or several such alternatives exist. + * If no alternative matches `pt', take the parameterless one anyway. */ def inferExprAlternative(tree: Tree, pt: Type): unit = tree.tpe match { case OverloadedType(pre, alts) => tryTwice { - val alts1 = alts filter (alt => isCompatible(pre.memberType(alt), pt)); + var alts1 = alts filter (alt => isCompatible(pre.memberType(alt), pt)); + if (alts1.isEmpty) alts1 = alts; def improves(sym1: Symbol, sym2: Symbol): boolean = sym2 == NoSymbol || ((sym1.owner isSubClass sym2.owner) && diff --git a/sources/scala/tools/nsc/typechecker/Namers.scala b/sources/scala/tools/nsc/typechecker/Namers.scala index 9fe435c167..9219ae330a 100755 --- a/sources/scala/tools/nsc/typechecker/Namers.scala +++ b/sources/scala/tools/nsc/typechecker/Namers.scala @@ -70,36 +70,39 @@ trait Namers: Analyzer { } private def enterClassSymbol(pos: int, mods: int, name: Name): Symbol = { - val c: Symbol = context.scope.lookup(name); + var c: Symbol = context.scope.lookup(name); if (c.isType && c.isExternal && context.scope == c.owner.info.decls) { - currentRun.symSource(c) = context.unit.source.getFile(); updatePosFlags(c, pos, mods); } else { - enterInScope(context.owner.newClass(pos, name).setFlag(mods)) + c = enterInScope(context.owner.newClass(pos, name).setFlag(mods)) } + if (c.owner.isPackageClass) currentRun.symSource(c) = context.unit.source.getFile(); + c } private def enterModuleSymbol(pos: int, mods: int, name: Name): Symbol = { - val m: Symbol = context.scope.lookup(name); + var m: Symbol = context.scope.lookup(name); if (m.isTerm && !m.isPackage && m.isExternal && (context.scope == m.owner.info.decls)) { - currentRun.symSource(m) = context.unit.source.getFile(); updatePosFlags(m, pos, mods) } else { - val newm = context.owner.newModule(pos, name); - newm.setFlag(mods); - newm.moduleClass.setFlag(mods); - enterInScope(newm) + m = context.owner.newModule(pos, name); + m.setFlag(mods); + m.moduleClass.setFlag(mods); + enterInScope(m) } + if (m.owner.isPackageClass) currentRun.symSource(m) = context.unit.source.getFile(); + m } private def enterCaseFactorySymbol(pos: int, mods: int, name: Name): Symbol = { - val m: Symbol = context.scope.lookup(name); + var m: Symbol = context.scope.lookup(name); if (m.isTerm && !m.isPackage && m.isExternal && context.scope == m.owner.info.decls) { - currentRun.symSource(m) = context.unit.source.getFile(); updatePosFlags(m, pos, mods) } else { - enterInScope(context.owner.newMethod(pos, name).setFlag(mods)) + m = enterInScope(context.owner.newMethod(pos, name).setFlag(mods)) } + if (m.owner.isPackageClass) currentRun.symSource(m) = context.unit.source.getFile(); + m } def enterSyms(trees: List[Tree]): Namer = @@ -177,8 +180,8 @@ trait Namers: Analyzer { case AliasTypeDef(mods, name, tparams, _) => tree.symbol = enterInScope(owner.newAliasType(tree.pos, name)).setFlag(mods); finishWith(tparams) - case Attributed(_, defn) => - enterSym(defn) + case Attributed(attr, defn) => + enterSym(defn); case DocDef(_, defn) => enterSym(defn) case imp @ Import(_, _) => @@ -419,6 +422,8 @@ trait Namers: Analyzer { "\nit should be omitted for abstract members"); if (sym.hasFlag(OVERRIDE | ABSOVERRIDE) && sym.isClass) context.error(sym.pos, "`override' modifier not allowed for classes"); + if (sym.hasFlag(ABSOVERRIDE) && !sym.owner.isTrait) + context.error(sym.pos, "`abstract override' modifier only allowed for members of traits"); if (sym.info.symbol == FunctionClass(0) && sym.isValueParameter && sym.owner.isClass && sym.owner.hasFlag(CASE)) context.error(sym.pos, "pass-by-name arguments not allowed for case class parameters"); diff --git a/sources/scala/tools/nsc/typechecker/RefChecks.scala b/sources/scala/tools/nsc/typechecker/RefChecks.scala index 8a908a6304..376ae0b09c 100755 --- a/sources/scala/tools/nsc/typechecker/RefChecks.scala +++ b/sources/scala/tools/nsc/typechecker/RefChecks.scala @@ -163,6 +163,8 @@ abstract class RefChecks extends InfoTransform { overrideError("cannot override final member"); } else if (!(other hasFlag DEFERRED) && !(member hasFlag (OVERRIDE | ABSOVERRIDE))) { // (1.3) overrideError("needs `override' modifier"); + } else if ((other hasFlag ABSOVERRIDE) && other.isIncompleteIn(clazz) && !(member hasFlag ABSOVERRIDE)) { + overrideError("needs `abstract override' modifiers"); } else if (other.isStable && !member.isStable) { // (1.4) overrideError("needs to be an immutable value"); } else { @@ -176,7 +178,7 @@ abstract class RefChecks extends InfoTransform { } else if (other.isAbstractType) { if (!member.typeParams.isEmpty) // (1.7) overrideError("may not be parameterized"); - if (!(self.memberInfo(other).bounds containsType self.memberInfo(member))) // (1.7) + if (!(self.memberInfo(other).bounds containsType self.memberType(member))) // (1.7) overrideTypeError(); } else if (other.isTerm) { if (!(self.memberInfo(member) <:< (self.memberInfo(other)))) // 8 @@ -216,22 +218,23 @@ abstract class RefChecks extends InfoTransform { } */ // 2. Check that only abstract classes have deferred members - if (clazz.isClass && !(clazz hasFlag ABSTRACT)) { - def abstractClassError(msg: String): unit = { + if (clazz.isClass && !clazz.isTrait) { + def abstractClassError(mustBeTrait: boolean, msg: String): unit = { unit.error(clazz.pos, (if (clazz.isAnonymousClass || clazz.isModuleClass) "object creation impossible" + else if (mustBeTrait) clazz.toString() + " needs to be a trait" else clazz.toString() + " needs to be abstract") + ", since " + msg); clazz.setFlag(ABSTRACT); } for (val member <- clazz.tpe.members) - if (member hasFlag DEFERRED) { - abstractClassError( + if ((member hasFlag DEFERRED) && !(clazz hasFlag ABSTRACT)) { + abstractClassError(false, infoString(member) + " is not defined" + (if (member.isVariable) "\n(Note that variables need to be initialized to be defined)" else "")) - } else if (member.isIncompleteIn(clazz)) { + } else if ((member hasFlag ABSOVERRIDE) && member.isIncompleteIn(clazz)) { val other = member.superSymbol(clazz); - abstractClassError( + abstractClassError(true, infoString(member) + " is marked `abstract' and `override'" + (if (other != NoSymbol) " and overrides incomplete superclass member " + infoString(other) @@ -243,7 +246,8 @@ abstract class RefChecks extends InfoTransform { for (val member <- clazz.info.decls.toList) if ((member hasFlag (OVERRIDE | ABSOVERRIDE)) && (clazz.info.baseClasses.tail forall (bc => member.overriddenSymbol(bc) == NoSymbol))) { - System.out.println(clazz.info.baseClasses.tail);//debug + for (val bc <- clazz.info.baseClasses.tail) + System.out.println("" + bc + " has " + bc.info.decl(member.name) + ":" + bc.info.decl(member.name).tpe);//debug unit.error(member.pos, member.toString() + " overrides nothing"); member resetFlag OVERRIDE } @@ -391,9 +395,12 @@ abstract class RefChecks extends InfoTransform { for (val stat <- stats) { index = index + 1; stat match { - case ClassDef(_, _, _, _, _) | DefDef(_, _, _, _, _, _) if (stat.symbol.isLocal) => - currentLevel.scope.enter(newScopeEntry(stat.symbol, currentLevel.scope)); - symIndex(stat.symbol) = index; + case ClassDef(_, _, _, _, _) | DefDef(_, _, _, _, _, _) => + assert(stat.symbol != NoSymbol, stat);//debug + if (stat.symbol.isLocal) { + currentLevel.scope.enter(newScopeEntry(stat.symbol, currentLevel.scope)); + symIndex(stat.symbol) = index; + } case _ => } } diff --git a/sources/scala/tools/nsc/typechecker/SyntheticMethods.scala b/sources/scala/tools/nsc/typechecker/SyntheticMethods.scala index 937c2419a9..0667124eef 100755 --- a/sources/scala/tools/nsc/typechecker/SyntheticMethods.scala +++ b/sources/scala/tools/nsc/typechecker/SyntheticMethods.scala @@ -8,7 +8,7 @@ package scala.tools.nsc.typechecker; import symtab.Flags._; import util.ListBuffer; -abstract class SyntheticMethods: Analyzer { +[_trait_] abstract class SyntheticMethods: Analyzer { import global._; // the global environment import definitions._; // standard classes and methods import typer.{typed}; // methods to type trees diff --git a/sources/scala/tools/nsc/typechecker/Typers.scala b/sources/scala/tools/nsc/typechecker/Typers.scala index 0ecbab0c53..867c8d6b43 100755 --- a/sources/scala/tools/nsc/typechecker/Typers.scala +++ b/sources/scala/tools/nsc/typechecker/Typers.scala @@ -12,7 +12,7 @@ import scala.tools.util.Position; import collection.mutable.HashMap; /** Methods to create symbols and to enter them into scopes. */ -abstract class Typers: Analyzer { +[_trait_] abstract class Typers: Analyzer { import global._; import definitions._; import posAssigner.atPos; @@ -379,8 +379,8 @@ abstract class Typers: Analyzer { // adapt(tree, mode, pt) // } - private def completeSuperType(supertpt: Tree, tparams: List[Symbol], vparamss: List[List[ValDef]], superargs: List[Tree]): Type = { - tparams foreach context.scope.enter; + private def completeSuperType(supertpt: Tree, tparams: List[Symbol], enclTparams: List[Symbol], vparamss: List[List[ValDef]], superargs: List[Tree]): Type = { + enclTparams foreach context.scope.enter; namer.enterValueParams(context.owner, vparamss); val newTree = New(supertpt) setType PolyType(tparams, appliedType(supertpt.tpe, tparams map (.tpe))); @@ -404,12 +404,13 @@ abstract class Typers: Analyzer { if (!tparams.isEmpty) { val constr @ DefDef(_, _, _, vparamss, _, Apply(_, superargs)) = treeInfo.firstConstructor(templ.body); - val outercontext = context.outer.outer; + val outercontext = context.outer; supertpt = TypeTree( - newTyper(context.outer.outer.makeNewScope(constr, context.outer.outer.owner)) + newTyper(outercontext.makeNewScope(constr, outercontext.owner/*.newValue(templ.pos, newTermName("<dummy>"))*/)) .completeSuperType( supertpt, - tparams, + tparams, + context.owner.unsafeTypeParams, vparamss map (.map(.duplicate.asInstanceOf[ValDef])), superargs map (.duplicate))) setPos supertpt.pos; } @@ -476,7 +477,7 @@ abstract class Typers: Analyzer { val tparams1 = List.mapConserve(cdef.tparams)(typedAbsTypeDef); val tpt1 = checkNoEscaping.privates(clazz.thisSym, typedType(cdef.tpt)); val impl1 = newTyper(context.make(cdef.impl, clazz, new Scope())) - .typedTemplate(cdef.impl); + .typedTemplate(cdef.impl, parentTypes(cdef.impl)); copy.ClassDef(cdef, cdef.mods, cdef.name, tparams1, tpt1, addSyntheticMethods(impl1, clazz)) setType NoType } @@ -484,7 +485,7 @@ abstract class Typers: Analyzer { def typedModuleDef(mdef: ModuleDef): Tree = { val clazz = mdef.symbol.moduleClass; val impl1 = newTyper(context.make(mdef.impl, clazz, new Scope())) - .typedTemplate(mdef.impl); + .typedTemplate(mdef.impl, parentTypes(mdef.impl)); copy.ModuleDef(mdef, mdef.mods, mdef.name, impl1) setType NoType } @@ -492,9 +493,9 @@ abstract class Typers: Analyzer { case ValDef(mods, name, tpe, rhs) if (mods & LOCAL) == 0 && !stat.symbol.isModuleVar => val vdef = copy.ValDef(stat, mods | PRIVATE | LOCAL, nme.getterToLocal(name), tpe, rhs); val value = vdef.symbol; + val getter = if ((mods & DEFERRED) != 0) value else value.getter(value.owner); + assert(getter != NoSymbol, value);//debug val getterDef: DefDef = { - val getter = if ((mods & DEFERRED) != 0) value else value.getter(value.owner); - assert(getter != NoSymbol, value); val result = atPos(vdef.pos)( DefDef(getter, vparamss => if ((mods & DEFERRED) != 0) EmptyTree @@ -503,7 +504,8 @@ abstract class Typers: Analyzer { result } def setterDef: DefDef = { - val setter = value.setter(value.owner); + val setter = value.owner.info.decl(nme.getterToSetter(getter.name)); + assert(setter != NoSymbol, getter);//debug atPos(vdef.pos)( DefDef(setter, vparamss => if ((mods & DEFERRED) != 0) EmptyTree @@ -521,10 +523,9 @@ abstract class Typers: Analyzer { List(stat) } - def typedTemplate(templ: Template): Template = { + def typedTemplate(templ: Template, parents1: List[Tree]): Template = { val clazz = context.owner; if (templ.symbol == NoSymbol) templ setSymbol clazz.newLocalDummy(templ.pos); - val parents1 = parentTypes(templ); val selfType = if (clazz.isAnonymousClass && !phase.erasedTypes) intersectionType(clazz.info.parents, clazz.owner) @@ -556,7 +557,7 @@ abstract class Typers: Analyzer { copy.ValDef(vdef, vdef.mods, vdef.name, tpt1, rhs1) setType NoType } - /** Enter in global.aliases all aliases of local parameter accessors. */ + /** Enter all aliases of local parameter accessors. */ def computeParamAliases(clazz: Symbol, vparamss: List[List[ValDef]], rhs: Tree): unit = { if (settings.debug.value) log("computing param aliases for " + clazz + ":" + clazz.primaryConstructor.tpe + ":" + rhs);//debug def decompose(call: Tree): Pair[Tree, List[Tree]] = call match { @@ -576,32 +577,34 @@ abstract class Typers: Analyzer { assert(superConstr.symbol != null, superConstr);//debug if (superConstr.symbol.isPrimaryConstructor) { val superClazz = superConstr.symbol.owner; - val superParamAccessors = superClazz.constrParamAccessors; - if (superParamAccessors.length != superArgs.length) { - System.out.println("" + superClazz + ":" + superClazz.info.decls.toList.filter(.hasFlag(PARAMACCESSOR))); - assert(false, "mismatch: " + superParamAccessors + ";" + rhs + ";" + superClazz.info.decls); //debug - } - List.map2(superParamAccessors, superArgs) { (superAcc, superArg) => - superArg match { - case Ident(name) => - if (vparamss.exists(.exists(vp => vp.symbol == superArg.symbol))) { - var alias = superAcc.initialize.alias; - if (alias == NoSymbol) - alias = superAcc.getter(superAcc.owner); - if (alias != NoSymbol && - superClazz.info.nonPrivateMember(alias.name) != alias) - alias = NoSymbol; - if (alias != NoSymbol) { - var ownAcc = clazz.info.decl(name); - if (ownAcc hasFlag ACCESSOR) ownAcc = ownAcc.accessed; - if (settings.debug.value) log("" + ownAcc + " has alias " + alias + alias.locationString);//debug - ownAcc.asInstanceOf[TermSymbol].setAlias(alias) - } - } - case _ => + if (!superClazz.hasFlag(JAVA)) { + val superParamAccessors = superClazz.constrParamAccessors; + if (superParamAccessors.length != superArgs.length) { + System.out.println("" + superClazz + ":" + superClazz.info.decls.toList.filter(.hasFlag(PARAMACCESSOR))); + assert(false, "mismatch: " + superParamAccessors + ";" + rhs + ";" + superClazz.info.decls); //debug } - } - () + List.map2(superParamAccessors, superArgs) { (superAcc, superArg) => + superArg match { + case Ident(name) => + if (vparamss.exists(.exists(vp => vp.symbol == superArg.symbol))) { + var alias = superAcc.initialize.alias; + if (alias == NoSymbol) + alias = superAcc.getter(superAcc.owner); + if (alias != NoSymbol && + superClazz.info.nonPrivateMember(alias.name) != alias) + alias = NoSymbol; + if (alias != NoSymbol) { + var ownAcc = clazz.info.decl(name); + if (ownAcc hasFlag ACCESSOR) ownAcc = ownAcc.accessed; + if (settings.debug.value) log("" + ownAcc + " has alias " + alias + alias.locationString);//debug + ownAcc.asInstanceOf[TermSymbol].setAlias(alias) + } + } + case _ => + } + } + () + } } } @@ -1053,7 +1056,7 @@ abstract class Typers: Analyzer { newTyper(context.makeNewScope(tree, sym)).typedClassDef(cdef) case mdef @ ModuleDef(_, _, _) => - typedModuleDef(mdef) + newTyper(context.make(tree, sym.moduleClass)).typedModuleDef(mdef) case vdef @ ValDef(_, _, _, _) => typedValDef(vdef) @@ -1079,7 +1082,8 @@ abstract class Typers: Analyzer { case Attributed(attr, defn) => val attr1 = typed(attr, AttributeClass.tpe); val defn1 = typed(defn, mode, pt); - defn1.symbol.attributes = defn1.symbol.attributes ::: List(attrInfo(attr1)); + val ai = attrInfo(attr1); + if (ai != null) defn1.symbol.attributes = defn1.symbol.attributes ::: List(ai); defn1 case DocDef(comment, defn) => @@ -1156,7 +1160,7 @@ abstract class Typers: Analyzer { case Match(selector, cases) => val selector1 = typed(selector); - val cases1 = typedCases(tree, cases, selector1.tpe, pt); + val cases1 = typedCases(tree, cases, selector1.tpe.widen, pt); copy.Match(tree, selector1, cases1) setType ptOrLub(cases1 map (.tpe)) case Return(expr) => @@ -1298,7 +1302,7 @@ abstract class Typers: Analyzer { else { val decls = new Scope(); val self = refinedType(parents1 map (.tpe), context.enclClass.owner, decls); - newTyper(context.make(tree, self.symbol, new Scope())).typedRefinement(templ.body); + newTyper(context.make(templ, self.symbol, decls)).typedRefinement(templ.body); self } } diff --git a/sources/scala/tools/nsc/typechecker/Variances.scala b/sources/scala/tools/nsc/typechecker/Variances.scala index 9425e3ce04..ca7c52d242 100755 --- a/sources/scala/tools/nsc/typechecker/Variances.scala +++ b/sources/scala/tools/nsc/typechecker/Variances.scala @@ -9,7 +9,7 @@ import symtab.Flags._; /** Variances form a lattice, 0 <= COVARIANT <= Variances, 0 <= CONTRAVARIANT <= VARIANCES */ -abstract class Variances { +[_trait_] abstract class Variances { val global: Global; import global._; diff --git a/sources/scala/xml/factory/NodeFactory.scala b/sources/scala/xml/factory/NodeFactory.scala index ed9caa1f42..6a28ec825a 100644 --- a/sources/scala/xml/factory/NodeFactory.scala +++ b/sources/scala/xml/factory/NodeFactory.scala @@ -12,7 +12,7 @@ package scala.xml.factory; import scala.collection.Map ; import scala.collection.mutable ; -abstract class NodeFactory[A <: Node] { +[_trait_] abstract class NodeFactory[A <: Node] { val ignoreComments = false; val ignoreProcInstr = false; diff --git a/sources/scala/xml/parsing/MarkupParser.scala b/sources/scala/xml/parsing/MarkupParser.scala index e1cfe86e77..2ff647738d 100644 --- a/sources/scala/xml/parsing/MarkupParser.scala +++ b/sources/scala/xml/parsing/MarkupParser.scala @@ -23,7 +23,7 @@ import scala.xml.dtd._ ; * While XML elements are returned, DTD declarations - if handled - are * collected using side-effects. */ -abstract class MarkupParser: (MarkupParser with MarkupHandler) extends AnyRef with TokenTests { +[_trait_] abstract class MarkupParser: (MarkupParser with MarkupHandler) extends AnyRef with TokenTests { val input: Source; |