From 17d05259cdaaad94b0c7ef9387fe63cd849b15a7 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 9 Apr 2008 09:57:10 +0000 Subject: fixed #654 and #688 --- .../scala/tools/nsc/ast/parser/Parsers.scala | 74 ++++++++-------------- .../scala/tools/nsc/matching/TransMatcher.scala | 2 +- src/compiler/scala/tools/nsc/symtab/Symbols.scala | 20 +++++- src/compiler/scala/tools/nsc/symtab/Types.scala | 11 +++- .../scala/tools/nsc/symtab/clr/CLRTypes.scala | 14 +--- .../scala/tools/nsc/typechecker/Infer.scala | 3 +- .../scala/tools/nsc/typechecker/Namers.scala | 2 +- 7 files changed, 61 insertions(+), 65 deletions(-) diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala index e7c33cc426..8c2c0685ab 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala @@ -788,7 +788,7 @@ trait Parsers extends NewScanners with MarkupParsers { } } - /** AnnotType ::= SimpleType Annotations + /** AnnotType ::= SimpleType {Annotation} * SimpleType ::= SimpleType TypeArgs * | SimpleType `#' Id * | StableId @@ -797,13 +797,6 @@ trait Parsers extends NewScanners with MarkupParsers { * | WildcardType */ def annotType(isPattern: Boolean): Tree = placeholderTypeBoundary { - val annots1 = annotations() - if (!annots1.isEmpty) - deprecationWarning( - annots1.head.pos, - "Type annotations should now follow the type") - // deprecated on August 13, 2007 - val pos = inCurrentPos val t: Tree = annotTypeRest(pos, isPattern, @@ -821,10 +814,7 @@ trait Parsers extends NewScanners with MarkupParsers { case _ => convertToTypeId(r) } }) - - val annots2 = annotations() - val annots = annots1 ::: annots2 - (t /: annots) (makeAnnotated) + (t /: annotations(false)) (makeAnnotated) } def annotTypeRest(pos: Int, isPattern: Boolean, t: Tree): Tree = @@ -1038,8 +1028,8 @@ trait Parsers extends NewScanners with MarkupParsers { } else if (inToken == COLON) { t = stripParens(t) val pos = inSkipToken - val annots = annotations() if (inToken == USCORE) { + //todo: need to handle case where USCORE is a wildcard in a type val pos1 = inSkipToken if (isIdent && inName == nme.STAR) { inNextToken @@ -1049,7 +1039,9 @@ trait Parsers extends NewScanners with MarkupParsers { } else { syntaxErrorOrIncomplete("`*' expected", true) } - } else if (annots.isEmpty || isTypeIntro) { + } else if (in.token == AT) { + t = (t /: annotations(false)) (makeAnnotated) + } else { t = atPos(pos) { val tpt = if (location != Local) compoundType(false) else typ() if (isWildcard(t)) @@ -1059,10 +1051,8 @@ trait Parsers extends NewScanners with MarkupParsers { } // this does not correspond to syntax, but is necessary to // accept closures. We might restrict closures to be between {...} only! - Typed(t, (tpt /: annots) (makeAnnotated)) + Typed(t, tpt) } - } else { - t = (t /: annots) (makeAnnotated) } } else if (inToken == MATCH) { t = atPos(inSkipToken) { @@ -1280,6 +1270,8 @@ trait Parsers extends NewScanners with MarkupParsers { */ def enumerators(): List[Enumerator] = { val newStyle = inToken != VAL // todo: deprecate old style + //if (!newStyle) + // deprecationWarning(inCurrentPos, "for (val x <- ... ) has been deprecated; use for (x <- ... ) instead") val enums = new ListBuffer[Enumerator] generator(enums, false) while (isStatSep) { @@ -1576,29 +1568,15 @@ trait Parsers extends NewScanners with MarkupParsers { loop(NoMods) } - /** Annotations ::= {Annotation} - * Annotation ::= `@' AnnotationExpr [nl] + /** Annotations ::= {Annotation [nl]} + * Annotation ::= `@' AnnotationExpr */ - def annotations(): List[Annotation] = { + def annotations(skipNewLines: Boolean): List[Annotation] = { var annots = new ListBuffer[Annotation] - if (inToken == LBRACKET) { - deprecationWarning(in.currentPos, "The [attribute] syntax has been deprecated; use @annotation instead") - while (inToken == LBRACKET) { - inNextToken - annots += annotation() - while (inToken == COMMA) { - inNextToken - annots += annotation() - } - accept(RBRACKET) - newLineOpt() - } - } else { - while (inToken == AT) { - inNextToken - annots += annotation() - newLineOpt() - } + while (inToken == AT) { + inNextToken + annots += annotationExpr() + if (skipNewLines) newLineOpt() } annots.toList } @@ -1617,10 +1595,10 @@ trait Parsers extends NewScanners with MarkupParsers { exps.toList } - /** Annotation ::= StableId [TypeArgs] [`(' [Exprs] `)'] [[nl] `{' {NameValuePair} `}'] + /** AnnotationExpr ::= StableId [TypeArgs] [`(' [Exprs] `)'] [[nl] `{' {NameValuePair} `}'] * NameValuePair ::= val id `=' PrefixExpr */ - def annotation(): Annotation = { + def annotationExpr(): Annotation = { def nameValuePair(): Tree = { var pos = inCurrentPos accept(VAL) @@ -1654,11 +1632,11 @@ trait Parsers extends NewScanners with MarkupParsers { /** ParamClauses ::= {ParamClause} [[nl] `(' implicit Params `)'] * ParamClause ::= [nl] `(' [Params] ')' * Params ::= Param {`,' Param} - * Param ::= Annotations Id [`:' ParamType] + * Param ::= {Annotation} Id [`:' ParamType] * ClassParamClauses ::= {ClassParamClause} [[nl] `(' implicit ClassParams `)'] * ClassParamClause ::= [nl] `(' [ClassParams] ')' * ClassParams ::= ClassParam {`,' ClassParam} - * ClassParam ::= Annotations [{Modifier} (`val' | `var')] Id [`:' ParamType] + * ClassParam ::= {Annotation} [{Modifier} (`val' | `var')] Id [`:' ParamType] */ def paramClauses(owner: Name, implicitViews: List[Tree], ofCaseClass: Boolean): List[List[ValDef]] = { var implicitmod = 0 @@ -1667,7 +1645,7 @@ trait Parsers extends NewScanners with MarkupParsers { var pos = inCurrentPos { - val annots = annotations() + val annots = annotations(false) var mods = Modifiers(Flags.PARAM) if (owner.isTypeName) { mods = modifiers() | Flags.PARAMACCESSOR @@ -1945,7 +1923,7 @@ trait Parsers extends NewScanners with MarkupParsers { } /** IDE hook: for non-local defs or dcls with modifiers and annotations */ def nonLocalDefOrDcl : List[Tree] = { - val annots = annotations() + val annots = annotations(true) defOrDcl(modifiers() withAnnotations annots) } @@ -2142,7 +2120,7 @@ trait Parsers extends NewScanners with MarkupParsers { /** Hook for IDE, for top-level classes/objects */ def topLevelTmplDef: Tree = { - val annots = annotations() + val annots = annotations(true) val mods = modifiers() withAnnotations annots tmplDef(mods) } @@ -2170,7 +2148,7 @@ trait Parsers extends NewScanners with MarkupParsers { } } - /** ClassDef ::= Id [TypeParamClause] Annotations + /** ClassDef ::= Id [TypeParamClause] {Annotation} [AccessModifier] ClassParamClauses RequiresTypeOpt ClassTemplateOpt * TraitDef ::= Id [TypeParamClause] RequiresTypeOpt TraitTemplateOpt */ @@ -2188,7 +2166,7 @@ trait Parsers extends NewScanners with MarkupParsers { syntaxError("traits cannot have type parameters with <% bounds", false) implicitClassViews = List() } - val constrAnnots = annotations() + val constrAnnots = annotations(false) val (constrMods, vparamss) = if (mods.hasFlag(Flags.TRAIT)) (Modifiers(Flags.TRAIT), List()) else (accessModifierOpt(), paramClauses(name, implicitClassViews, mods.hasFlag(Flags.CASE))) @@ -2444,7 +2422,7 @@ trait Parsers extends NewScanners with MarkupParsers { /** overridable IDE hook for local definitions of blockStatSeq */ def localDef : List[Tree] = { - val annots = annotations() + val annots = annotations(true) val mods = localModifiers() withAnnotations annots if (!(mods hasFlag ~(Flags.IMPLICIT | Flags.LAZY))) defOrDcl(mods) else List(tmplDef(mods)) diff --git a/src/compiler/scala/tools/nsc/matching/TransMatcher.scala b/src/compiler/scala/tools/nsc/matching/TransMatcher.scala index f14e374b01..97dd2b6424 100644 --- a/src/compiler/scala/tools/nsc/matching/TransMatcher.scala +++ b/src/compiler/scala/tools/nsc/matching/TransMatcher.scala @@ -21,7 +21,7 @@ trait TransMatcher { self: transform.ExplicitOuter with PatternNodes with Parall import collection.mutable.ListBuffer - var cunit: CompilationUnit = _ + var cunit: CompilationUnit = _ // memory leak? def fresh = cunit.fresh var nPatterns = 0 var resultType: Type = _ diff --git a/src/compiler/scala/tools/nsc/symtab/Symbols.scala b/src/compiler/scala/tools/nsc/symtab/Symbols.scala index 8d6f1b0c40..1adcc8d15c 100644 --- a/src/compiler/scala/tools/nsc/symtab/Symbols.scala +++ b/src/compiler/scala/tools/nsc/symtab/Symbols.scala @@ -37,7 +37,6 @@ trait Symbols { coerceIntToPos(pos) } */ - /** The class for all symbols */ abstract class Symbol(initOwner: Symbol, initPos: Position, initName: Name) { @@ -1261,6 +1260,12 @@ trait Symbols { extends Symbol(initOwner, initPos, initName) { override def isTerm = true +/* + val marker = initName.toString match { + case "forCLDC" => new MarkForCLDC + case _ => null + } +*/ privateWithin = NoSymbol protected var referenced: Symbol = NoSymbol @@ -1591,4 +1596,17 @@ trait Symbols { override def toString() = "TypeHistory(" + phaseOf(validFrom)+":"+runId(validFrom) + "," + info + "," + prev + ")" } +/* + var occs = 0 + +class MarkForCLDC { + val atRun: Int = currentRunId + occs += 1 + println("new "+getClass+" at "+atRun+" ("+occs+" total)") + override def finalize() { + occs -=1 + println("drop "+getClass+" from "+atRun+" ("+occs+" total)") + } +} +*/ } diff --git a/src/compiler/scala/tools/nsc/symtab/Types.scala b/src/compiler/scala/tools/nsc/symtab/Types.scala index e32be60f4c..e03e63e9d6 100644 --- a/src/compiler/scala/tools/nsc/symtab/Types.scala +++ b/src/compiler/scala/tools/nsc/symtab/Types.scala @@ -1670,8 +1670,15 @@ A type's typeSymbol should never be inspected directly. override def prefix = maybeRewrap(underlying.prefix) override def typeArgs = underlying.typeArgs map maybeRewrap override def paramTypes = underlying.paramTypes map maybeRewrap - override def instantiateTypeParams(formals: List[Symbol], actuals: List[Type]) = - maybeRewrap(underlying.instantiateTypeParams(formals, actuals)) + override def instantiateTypeParams(formals: List[Symbol], actuals: List[Type]) = { +// maybeRewrap(underlying.instantiateTypeParams(formals, actuals)) + + val quantified1 = new SubstTypeMap(formals, actuals) mapOver quantified + val underlying1 = underlying.instantiateTypeParams(formals, actuals) + if ((quantified1 eq quantified) && (underlying1 eq underlying)) this + else existentialAbstraction(quantified1, underlying1.substSym(quantified, quantified1)) + + } override def baseType(clazz: Symbol) = maybeRewrap(underlying.baseType(clazz)) override def closure = underlying.closure map maybeRewrap override def isHigherKinded = false diff --git a/src/compiler/scala/tools/nsc/symtab/clr/CLRTypes.scala b/src/compiler/scala/tools/nsc/symtab/clr/CLRTypes.scala index 7ce26a2e25..fd0cc1f9c3 100644 --- a/src/compiler/scala/tools/nsc/symtab/clr/CLRTypes.scala +++ b/src/compiler/scala/tools/nsc/symtab/clr/CLRTypes.scala @@ -7,7 +7,8 @@ package scala.tools.nsc.symtab.clr import java.io.File -import java.util.{Arrays, Comparator, StringTokenizer} +import java.util.{Comparator, StringTokenizer} +import scala.util.Sorting import ch.epfl.lamp.compiler.msil._ @@ -116,16 +117,7 @@ abstract class CLRTypes { alltypes = Array.concat(alltypes, atypes) } - val typeNameComparator: Comparator[Any] = - new Comparator[Any]() { - def compare(o1: Any, o2: Any): Int = { - val t1 = o1.asInstanceOf[Type] - val t2 = o2.asInstanceOf[Type] - t1.FullName.compareTo(t2.FullName) - } - } - - Arrays.sort(alltypes.asInstanceOf[Array[Object]], typeNameComparator) + Sorting.stableSort(alltypes, (t1: Type, t2: Type) => (t1.FullName compareTo t2.FullName) < 0) this.alltypes = alltypes } catch { diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala index c118df8a54..182a94b97b 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala @@ -842,7 +842,8 @@ trait Infer { else "invariant"; def qualify(a0: Symbol, b0: Symbol): String = if (a0.toString != b0.toString) "" else { - assert((a0 ne b0) && (a0.owner ne b0.owner)); + assert(a0 ne b0) + assert(a0.owner ne b0.owner) var a = a0; var b = b0 while (a.owner.name == b.owner.name) { a = a.owner; b = b.owner} if (a.locationString ne "") " (" + a.locationString.trim + ")" else "" diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala index 5ed868d779..7b9a1e646c 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala @@ -515,7 +515,7 @@ trait Namers { self: Analyzer => if (self.name != nme.WILDCARD) { clazz.typeOfThis = clazz.tpe self.symbol = clazz.thisSym - } else { + } else if (self ne emptyValDef) { self.symbol = clazz.newThisSym(self.pos) setInfo clazz.tpe } } -- cgit v1.2.3