diff options
Diffstat (limited to 'src')
5 files changed, 46 insertions, 32 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala index cc9f077d0a..979f273529 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala @@ -1419,12 +1419,12 @@ trait Parsers requires SyntaxAnalyzer { /** Def ::= val PatDef * | var VarDef * | def FunDef - * | type TypeDef + * | type [NewLine] TypeDef * | TmplDef * Dcl ::= val ValDcl * | var ValDcl * | def FunDcl - * | type TypeDcl + * | type [NewLine] TypeDcl */ def defOrDcl(mods: Modifiers): List[Tree] = { in.token match { @@ -1436,6 +1436,7 @@ trait Parsers requires SyntaxAnalyzer { List(funDefOrDcl(mods)); case TYPE => in.nextToken(); + newLineOpt(); List(typeDefOrDcl(mods)) case _ => List(tmplDef(mods)) diff --git a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala index 8fd801a024..50b8a241c6 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala @@ -434,7 +434,7 @@ trait Scanners requires SyntaxAnalyzer { def inLastOfStat(token: int) = token match { case CHARLIT | INTLIT | LONGLIT | FLOATLIT | DOUBLELIT | STRINGLIT | SYMBOLLIT | - IDENTIFIER | THIS | NULL | TRUE | FALSE | RETURN | USCORE | + IDENTIFIER | THIS | NULL | TRUE | FALSE | RETURN | USCORE | TYPE | RPAREN | RBRACKET | RBRACE => true case _ => diff --git a/src/compiler/scala/tools/nsc/symtab/Symbols.scala b/src/compiler/scala/tools/nsc/symtab/Symbols.scala index 3466af4f00..cc2b25a7e7 100644 --- a/src/compiler/scala/tools/nsc/symtab/Symbols.scala +++ b/src/compiler/scala/tools/nsc/symtab/Symbols.scala @@ -545,7 +545,7 @@ trait Symbols requires SymbolTable { def thisSym: Symbol = this; /** The type of `this' in a class, or else the type of the symbol itself. */ - final def typeOfThis = thisSym.tpe; + def typeOfThis = thisSym.tpe; /** Sets the type of `this' in a class */ def typeOfThis_=(tp: Type): unit = throw new Error("typeOfThis cannot be set for " + this); @@ -747,7 +747,7 @@ trait Symbols requires SymbolTable { * E.g. $eq => =. * If settings.uniquId adds id. */ - def nameString: String = //todo: should be final + def nameString: String = simpleName.decode + idString; /** String representation of symbol's full name with `separator' @@ -758,7 +758,7 @@ trait Symbols requires SymbolTable { final def fullNameString(separator: char): String = { assert(owner != NoSymbol, this) if (owner.isRoot || owner.isEmptyPackageClass) simpleName.toString() - else owner.fullNameString(separator) + separator + simpleName; + else owner.fullNameString(separator) + separator + simpleName + idString; } final def fullNameString: String = fullNameString('.'); @@ -1015,15 +1015,7 @@ trait Symbols requires SymbolTable { val p = thisTypePhase; if (p != phase) { thisTypePhase = phase; - if (!(isValid(p) /*|| - thisTypePhase != null && thisTypePhase.erasedTypes && phase.erasedTypes*/)) { - thisTypeCache = ThisType(this) -/* - if (isModuleClass && !isRoot && !phase.erasedTypes) - singleType(owner.thisType, sourceModule); - else ThisType(this); -*/ - } + if (!isValid(p)) thisTypeCache = ThisType(this) } thisTypeCache } @@ -1031,6 +1023,11 @@ trait Symbols requires SymbolTable { /** A symbol carrying the self type of the class as its type */ override def thisSym: Symbol = thissym; + override def typeOfThis: Type = + if (getFlag(MODULE | IMPLCLASS) == MODULE && owner != NoSymbol) + singleType(owner.thisType, sourceModule) + else thissym.tpe + /** Sets the self type of the class */ override def typeOfThis_=(tp: Type): unit = thissym = newThisSym(pos).setInfo(tp); diff --git a/src/compiler/scala/tools/nsc/symtab/Types.scala b/src/compiler/scala/tools/nsc/symtab/Types.scala index bbc476889b..cbd5504388 100644 --- a/src/compiler/scala/tools/nsc/symtab/Types.scala +++ b/src/compiler/scala/tools/nsc/symtab/Types.scala @@ -552,6 +552,19 @@ trait Types requires SymbolTable { } singleDerefCache } + + override def narrow: Type = { + if (phase.erasedTypes) this + else { + val thissym = refinedType(List(this), sym.owner, EmptyScope).symbol + if (sym.owner != NoSymbol) { + //Console.println("narrowing module " + sym + thissym.owner); + thissym.typeOfThis = this + } + thissym.thisType + } + } + override def symbol = sym override def prefix: Type = pre override def prefixString: String = @@ -1500,11 +1513,13 @@ trait Types requires SymbolTable { case Pair(_, NoType) => false case Pair(_, NoPrefix) => tp1.symbol.isPackageClass - case Pair(ThisType(sym1), ThisType(sym2)) => - sym1 == sym2 + case Pair(ThisType(sym1), ThisType(sym2)) + if (sym1 == sym2) => + true case Pair(SingleType(pre1, sym1), SingleType(pre2, sym2)) if ((sym1 == sym2) && (pre1 =:= pre2)) => true +/* case Pair(SingleType(pre1, sym1), ThisType(sym2)) if (sym1.isModule && sym1.moduleClass == sym2 && @@ -1515,6 +1530,7 @@ trait Types requires SymbolTable { sym2.moduleClass == sym1 && pre2 =:= sym1.owner.thisType) => true +*/ case Pair(ConstantType(value1), ConstantType(value2)) => value1 == value2 case Pair(TypeRef(pre1, sym1, args1), TypeRef(pre2, sym2, args2)) => @@ -1544,14 +1560,14 @@ trait Types requires SymbolTable { case Pair(_, TypeVar(_, constr2)) => if (constr2.inst != NoType) tp1 =:= constr2.inst else constr2 instantiate (wildcardToTypeVarMap(tp1)) - case Pair(SingleType(_, _), _) - if (tp2.isStable && tp1.singleDeref =:= tp2) => - true - case Pair(_, SingleType(_, _)) - if (tp1.isStable && tp1 =:= tp2.singleDeref) => - true case _ => - false + if (tp1.isStable && tp2.isStable) { + var origin1 = tp1 + while (origin1.singleDeref.isStable) origin1 = origin1.singleDeref + var origin2 = tp2 + while (origin2.singleDeref.isStable) origin2 = origin2.singleDeref + ((origin1 ne tp1) || (origin2 ne tp2)) && (origin1 =:= origin2) + } else false } } @@ -1680,15 +1696,12 @@ trait Types requires SymbolTable { /** Does member `sym1' of `tp1' have a stronger type than member `sym2' of `tp2'? */ private def specializesSym(tp1: Type, sym1: Symbol, tp2: Type, sym2: Symbol): boolean = { -// System.out.println("specializes " + tp1 + " " + tp2)//DEBUG + //System.out.println("specializes "+tp1+"."+sym1+" "+tp2+"."+sym2)//DEBUG val info1 = tp1.memberInfo(sym1); val info2 = tp2.memberInfo(sym2).substThis(tp2.symbol, tp1); - (sym2.isTerm && - info1 <:< info2 || - sym2.isAbstractType && - (info2.bounds containsType info1) || - sym2.isAliasType && - tp2.memberType(sym2) =:= tp1.memberType(sym1)) + sym2.isTerm && (info1 <:< info2) || + sym2.isAbstractType && info2.bounds.containsType(info1) || + sym2.isAliasType && tp2.memberType(sym2).substThis(tp2.symbol, tp1) =:= tp1.memberType(sym1) } /** A function implementing tp1 matches tp2 */ diff --git a/src/compiler/scala/tools/nsc/transform/Mixin.scala b/src/compiler/scala/tools/nsc/transform/Mixin.scala index 6c96c3985d..4e2e504445 100644 --- a/src/compiler/scala/tools/nsc/transform/Mixin.scala +++ b/src/compiler/scala/tools/nsc/transform/Mixin.scala @@ -64,9 +64,11 @@ abstract class Mixin extends InfoTransform { member setFlag MIXEDIN } - def addLateInterfaceMembers(clazz: Symbol) = + def addLateInterfaceMembers(clazz: Symbol): unit = if (!(clazz hasFlag MIXEDIN)) { clazz setFlag MIXEDIN; + for (val bc <- clazz.info.baseClasses.reverse) + if (bc.hasFlag(lateINTERFACE)) addLateInterfaceMembers(bc) def newGetter(field: Symbol): Symbol = clazz.newMethod(field.pos, nme.getterName(field.name)) .setFlag(field.flags & ~(PRIVATE | LOCAL) | ACCESSOR | DEFERRED | SYNTHETIC) @@ -109,6 +111,7 @@ abstract class Mixin extends InfoTransform { //System.out.println("adding members of " + clazz.info.baseClasses.tail.takeWhile(superclazz !=) + " to " + clazz);//DEBUG val mixins = clazz.info.baseClasses.tail.takeWhile(superclazz !=); def mixinMembers(mixinClass: Symbol, mmap: Symbol => Symbol): unit = { + //Console.println("mixin members of "+mixinClass+" to "+clazz+" "+clazz.info.baseClasses)//DEBUG if (mixinClass.isImplClass) { addLateInterfaceMembers(mixinClass.toInterface); for (val member <- mixinClass.info.decls.toList) { |