Skip to content

Commit 17d0525

Browse files
committed
fixed scala#654 and scala#688
1 parent 233e710 commit 17d0525

File tree

7 files changed

+61
-65
lines changed

7 files changed

+61
-65
lines changed

src/compiler/scala/tools/nsc/ast/parser/Parsers.scala

Lines changed: 26 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ trait Parsers extends NewScanners with MarkupParsers {
788788
}
789789
}
790790

791-
/** AnnotType ::= SimpleType Annotations
791+
/** AnnotType ::= SimpleType {Annotation}
792792
* SimpleType ::= SimpleType TypeArgs
793793
* | SimpleType `#' Id
794794
* | StableId
@@ -797,13 +797,6 @@ trait Parsers extends NewScanners with MarkupParsers {
797797
* | WildcardType
798798
*/
799799
def annotType(isPattern: Boolean): Tree = placeholderTypeBoundary {
800-
val annots1 = annotations()
801-
if (!annots1.isEmpty)
802-
deprecationWarning(
803-
annots1.head.pos,
804-
"Type annotations should now follow the type")
805-
// deprecated on August 13, 2007
806-
807800
val pos = inCurrentPos
808801

809802
val t: Tree = annotTypeRest(pos, isPattern,
@@ -821,10 +814,7 @@ trait Parsers extends NewScanners with MarkupParsers {
821814
case _ => convertToTypeId(r)
822815
}
823816
})
824-
825-
val annots2 = annotations()
826-
val annots = annots1 ::: annots2
827-
(t /: annots) (makeAnnotated)
817+
(t /: annotations(false)) (makeAnnotated)
828818
}
829819

830820
def annotTypeRest(pos: Int, isPattern: Boolean, t: Tree): Tree =
@@ -1038,8 +1028,8 @@ trait Parsers extends NewScanners with MarkupParsers {
10381028
} else if (inToken == COLON) {
10391029
t = stripParens(t)
10401030
val pos = inSkipToken
1041-
val annots = annotations()
10421031
if (inToken == USCORE) {
1032+
//todo: need to handle case where USCORE is a wildcard in a type
10431033
val pos1 = inSkipToken
10441034
if (isIdent && inName == nme.STAR) {
10451035
inNextToken
@@ -1049,7 +1039,9 @@ trait Parsers extends NewScanners with MarkupParsers {
10491039
} else {
10501040
syntaxErrorOrIncomplete("`*' expected", true)
10511041
}
1052-
} else if (annots.isEmpty || isTypeIntro) {
1042+
} else if (in.token == AT) {
1043+
t = (t /: annotations(false)) (makeAnnotated)
1044+
} else {
10531045
t = atPos(pos) {
10541046
val tpt = if (location != Local) compoundType(false) else typ()
10551047
if (isWildcard(t))
@@ -1059,10 +1051,8 @@ trait Parsers extends NewScanners with MarkupParsers {
10591051
}
10601052
// this does not correspond to syntax, but is necessary to
10611053
// accept closures. We might restrict closures to be between {...} only!
1062-
Typed(t, (tpt /: annots) (makeAnnotated))
1054+
Typed(t, tpt)
10631055
}
1064-
} else {
1065-
t = (t /: annots) (makeAnnotated)
10661056
}
10671057
} else if (inToken == MATCH) {
10681058
t = atPos(inSkipToken) {
@@ -1280,6 +1270,8 @@ trait Parsers extends NewScanners with MarkupParsers {
12801270
*/
12811271
def enumerators(): List[Enumerator] = {
12821272
val newStyle = inToken != VAL // todo: deprecate old style
1273+
//if (!newStyle)
1274+
// deprecationWarning(inCurrentPos, "for (val x <- ... ) has been deprecated; use for (x <- ... ) instead")
12831275
val enums = new ListBuffer[Enumerator]
12841276
generator(enums, false)
12851277
while (isStatSep) {
@@ -1576,29 +1568,15 @@ trait Parsers extends NewScanners with MarkupParsers {
15761568
loop(NoMods)
15771569
}
15781570

1579-
/** Annotations ::= {Annotation}
1580-
* Annotation ::= `@' AnnotationExpr [nl]
1571+
/** Annotations ::= {Annotation [nl]}
1572+
* Annotation ::= `@' AnnotationExpr
15811573
*/
1582-
def annotations(): List[Annotation] = {
1574+
def annotations(skipNewLines: Boolean): List[Annotation] = {
15831575
var annots = new ListBuffer[Annotation]
1584-
if (inToken == LBRACKET) {
1585-
deprecationWarning(in.currentPos, "The [attribute] syntax has been deprecated; use @annotation instead")
1586-
while (inToken == LBRACKET) {
1587-
inNextToken
1588-
annots += annotation()
1589-
while (inToken == COMMA) {
1590-
inNextToken
1591-
annots += annotation()
1592-
}
1593-
accept(RBRACKET)
1594-
newLineOpt()
1595-
}
1596-
} else {
1597-
while (inToken == AT) {
1598-
inNextToken
1599-
annots += annotation()
1600-
newLineOpt()
1601-
}
1576+
while (inToken == AT) {
1577+
inNextToken
1578+
annots += annotationExpr()
1579+
if (skipNewLines) newLineOpt()
16021580
}
16031581
annots.toList
16041582
}
@@ -1617,10 +1595,10 @@ trait Parsers extends NewScanners with MarkupParsers {
16171595
exps.toList
16181596
}
16191597

1620-
/** Annotation ::= StableId [TypeArgs] [`(' [Exprs] `)'] [[nl] `{' {NameValuePair} `}']
1598+
/** AnnotationExpr ::= StableId [TypeArgs] [`(' [Exprs] `)'] [[nl] `{' {NameValuePair} `}']
16211599
* NameValuePair ::= val id `=' PrefixExpr
16221600
*/
1623-
def annotation(): Annotation = {
1601+
def annotationExpr(): Annotation = {
16241602
def nameValuePair(): Tree = {
16251603
var pos = inCurrentPos
16261604
accept(VAL)
@@ -1654,11 +1632,11 @@ trait Parsers extends NewScanners with MarkupParsers {
16541632
/** ParamClauses ::= {ParamClause} [[nl] `(' implicit Params `)']
16551633
* ParamClause ::= [nl] `(' [Params] ')'
16561634
* Params ::= Param {`,' Param}
1657-
* Param ::= Annotations Id [`:' ParamType]
1635+
* Param ::= {Annotation} Id [`:' ParamType]
16581636
* ClassParamClauses ::= {ClassParamClause} [[nl] `(' implicit ClassParams `)']
16591637
* ClassParamClause ::= [nl] `(' [ClassParams] ')'
16601638
* ClassParams ::= ClassParam {`,' ClassParam}
1661-
* ClassParam ::= Annotations [{Modifier} (`val' | `var')] Id [`:' ParamType]
1639+
* ClassParam ::= {Annotation} [{Modifier} (`val' | `var')] Id [`:' ParamType]
16621640
*/
16631641
def paramClauses(owner: Name, implicitViews: List[Tree], ofCaseClass: Boolean): List[List[ValDef]] = {
16641642
var implicitmod = 0
@@ -1667,7 +1645,7 @@ trait Parsers extends NewScanners with MarkupParsers {
16671645
var pos = inCurrentPos
16681646

16691647
{
1670-
val annots = annotations()
1648+
val annots = annotations(false)
16711649
var mods = Modifiers(Flags.PARAM)
16721650
if (owner.isTypeName) {
16731651
mods = modifiers() | Flags.PARAMACCESSOR
@@ -1945,7 +1923,7 @@ trait Parsers extends NewScanners with MarkupParsers {
19451923
}
19461924
/** IDE hook: for non-local defs or dcls with modifiers and annotations */
19471925
def nonLocalDefOrDcl : List[Tree] = {
1948-
val annots = annotations()
1926+
val annots = annotations(true)
19491927
defOrDcl(modifiers() withAnnotations annots)
19501928
}
19511929

@@ -2142,7 +2120,7 @@ trait Parsers extends NewScanners with MarkupParsers {
21422120

21432121
/** Hook for IDE, for top-level classes/objects */
21442122
def topLevelTmplDef: Tree = {
2145-
val annots = annotations()
2123+
val annots = annotations(true)
21462124
val mods = modifiers() withAnnotations annots
21472125
tmplDef(mods)
21482126
}
@@ -2170,7 +2148,7 @@ trait Parsers extends NewScanners with MarkupParsers {
21702148
}
21712149
}
21722150

2173-
/** ClassDef ::= Id [TypeParamClause] Annotations
2151+
/** ClassDef ::= Id [TypeParamClause] {Annotation}
21742152
[AccessModifier] ClassParamClauses RequiresTypeOpt ClassTemplateOpt
21752153
* TraitDef ::= Id [TypeParamClause] RequiresTypeOpt TraitTemplateOpt
21762154
*/
@@ -2188,7 +2166,7 @@ trait Parsers extends NewScanners with MarkupParsers {
21882166
syntaxError("traits cannot have type parameters with <% bounds", false)
21892167
implicitClassViews = List()
21902168
}
2191-
val constrAnnots = annotations()
2169+
val constrAnnots = annotations(false)
21922170
val (constrMods, vparamss) =
21932171
if (mods.hasFlag(Flags.TRAIT)) (Modifiers(Flags.TRAIT), List())
21942172
else (accessModifierOpt(), paramClauses(name, implicitClassViews, mods.hasFlag(Flags.CASE)))
@@ -2444,7 +2422,7 @@ trait Parsers extends NewScanners with MarkupParsers {
24442422

24452423
/** overridable IDE hook for local definitions of blockStatSeq */
24462424
def localDef : List[Tree] = {
2447-
val annots = annotations()
2425+
val annots = annotations(true)
24482426
val mods = localModifiers() withAnnotations annots
24492427
if (!(mods hasFlag ~(Flags.IMPLICIT | Flags.LAZY))) defOrDcl(mods)
24502428
else List(tmplDef(mods))

src/compiler/scala/tools/nsc/matching/TransMatcher.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ trait TransMatcher { self: transform.ExplicitOuter with PatternNodes with Parall
2121

2222
import collection.mutable.ListBuffer
2323

24-
var cunit: CompilationUnit = _
24+
var cunit: CompilationUnit = _ // memory leak?
2525
def fresh = cunit.fresh
2626
var nPatterns = 0
2727
var resultType: Type = _

src/compiler/scala/tools/nsc/symtab/Symbols.scala

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ trait Symbols {
3737
coerceIntToPos(pos)
3838
}
3939
*/
40-
4140
/** The class for all symbols */
4241
abstract class Symbol(initOwner: Symbol, initPos: Position, initName: Name) {
4342

@@ -1261,6 +1260,12 @@ trait Symbols {
12611260
extends Symbol(initOwner, initPos, initName) {
12621261
override def isTerm = true
12631262

1263+
/*
1264+
val marker = initName.toString match {
1265+
case "forCLDC" => new MarkForCLDC
1266+
case _ => null
1267+
}
1268+
*/
12641269
privateWithin = NoSymbol
12651270

12661271
protected var referenced: Symbol = NoSymbol
@@ -1591,4 +1596,17 @@ trait Symbols {
15911596
override def toString() =
15921597
"TypeHistory(" + phaseOf(validFrom)+":"+runId(validFrom) + "," + info + "," + prev + ")"
15931598
}
1599+
/*
1600+
var occs = 0
1601+
1602+
class MarkForCLDC {
1603+
val atRun: Int = currentRunId
1604+
occs += 1
1605+
println("new "+getClass+" at "+atRun+" ("+occs+" total)")
1606+
override def finalize() {
1607+
occs -=1
1608+
println("drop "+getClass+" from "+atRun+" ("+occs+" total)")
1609+
}
1610+
}
1611+
*/
15941612
}

src/compiler/scala/tools/nsc/symtab/Types.scala

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,8 +1670,15 @@ A type's typeSymbol should never be inspected directly.
16701670
override def prefix = maybeRewrap(underlying.prefix)
16711671
override def typeArgs = underlying.typeArgs map maybeRewrap
16721672
override def paramTypes = underlying.paramTypes map maybeRewrap
1673-
override def instantiateTypeParams(formals: List[Symbol], actuals: List[Type]) =
1674-
maybeRewrap(underlying.instantiateTypeParams(formals, actuals))
1673+
override def instantiateTypeParams(formals: List[Symbol], actuals: List[Type]) = {
1674+
// maybeRewrap(underlying.instantiateTypeParams(formals, actuals))
1675+
1676+
val quantified1 = new SubstTypeMap(formals, actuals) mapOver quantified
1677+
val underlying1 = underlying.instantiateTypeParams(formals, actuals)
1678+
if ((quantified1 eq quantified) && (underlying1 eq underlying)) this
1679+
else existentialAbstraction(quantified1, underlying1.substSym(quantified, quantified1))
1680+
1681+
}
16751682
override def baseType(clazz: Symbol) = maybeRewrap(underlying.baseType(clazz))
16761683
override def closure = underlying.closure map maybeRewrap
16771684
override def isHigherKinded = false

src/compiler/scala/tools/nsc/symtab/clr/CLRTypes.scala

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
package scala.tools.nsc.symtab.clr
88

99
import java.io.File
10-
import java.util.{Arrays, Comparator, StringTokenizer}
10+
import java.util.{Comparator, StringTokenizer}
11+
import scala.util.Sorting
1112

1213
import ch.epfl.lamp.compiler.msil._
1314

@@ -116,16 +117,7 @@ abstract class CLRTypes {
116117
alltypes = Array.concat(alltypes, atypes)
117118
}
118119

119-
val typeNameComparator: Comparator[Any] =
120-
new Comparator[Any]() {
121-
def compare(o1: Any, o2: Any): Int = {
122-
val t1 = o1.asInstanceOf[Type]
123-
val t2 = o2.asInstanceOf[Type]
124-
t1.FullName.compareTo(t2.FullName)
125-
}
126-
}
127-
128-
Arrays.sort(alltypes.asInstanceOf[Array[Object]], typeNameComparator)
120+
Sorting.stableSort(alltypes, (t1: Type, t2: Type) => (t1.FullName compareTo t2.FullName) < 0)
129121
this.alltypes = alltypes
130122
}
131123
catch {

src/compiler/scala/tools/nsc/typechecker/Infer.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,8 @@ trait Infer {
842842
else "invariant";
843843

844844
def qualify(a0: Symbol, b0: Symbol): String = if (a0.toString != b0.toString) "" else {
845-
assert((a0 ne b0) && (a0.owner ne b0.owner));
845+
assert(a0 ne b0)
846+
assert(a0.owner ne b0.owner)
846847
var a = a0; var b = b0
847848
while (a.owner.name == b.owner.name) { a = a.owner; b = b.owner}
848849
if (a.locationString ne "") " (" + a.locationString.trim + ")" else ""

src/compiler/scala/tools/nsc/typechecker/Namers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ trait Namers { self: Analyzer =>
515515
if (self.name != nme.WILDCARD) {
516516
clazz.typeOfThis = clazz.tpe
517517
self.symbol = clazz.thisSym
518-
} else {
518+
} else if (self ne emptyValDef) {
519519
self.symbol = clazz.newThisSym(self.pos) setInfo clazz.tpe
520520
}
521521
}

0 commit comments

Comments
 (0)