summaryrefslogtreecommitdiff
path: root/src/compiler
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2007-02-13 22:06:58 +0000
committerMartin Odersky <odersky@gmail.com>2007-02-13 22:06:58 +0000
commite5b3a8a6b49dd4ab333781e3e7ce595ba14b06eb (patch)
treeeada70e866264f0c52735024ce7a5804bb9f7bb8 /src/compiler
parentbd426ab6f97ad86266ea1f044f9945d76024eeac (diff)
downloadscala-e5b3a8a6b49dd4ab333781e3e7ce595ba14b06eb.tar.gz
scala-e5b3a8a6b49dd4ab333781e3e7ce595ba14b06eb.tar.bz2
scala-e5b3a8a6b49dd4ab333781e3e7ce595ba14b06eb.zip
changed tuple syntax to (...)
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/scala/tools/ant/Scalac.scala2
-rw-r--r--src/compiler/scala/tools/nsc/Global.scala4
-rw-r--r--src/compiler/scala/tools/nsc/Interpreter.scala2
-rw-r--r--src/compiler/scala/tools/nsc/ast/TreeGen.scala5
-rw-r--r--src/compiler/scala/tools/nsc/ast/TreePrinters.scala2
-rw-r--r--src/compiler/scala/tools/nsc/ast/Trees.scala10
-rw-r--r--src/compiler/scala/tools/nsc/ast/parser/MarkupParsers.scala2
-rw-r--r--src/compiler/scala/tools/nsc/ast/parser/Parsers.scala313
-rw-r--r--src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala48
-rw-r--r--src/compiler/scala/tools/nsc/backend/icode/GenICode.scala30
-rw-r--r--src/compiler/scala/tools/nsc/backend/icode/Members.scala2
-rw-r--r--src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala78
-rw-r--r--src/compiler/scala/tools/nsc/backend/msil/GenMSIL.scala24
-rw-r--r--src/compiler/scala/tools/nsc/matching/PatternMatchers.scala4
-rw-r--r--src/compiler/scala/tools/nsc/matching/PatternNodes.scala8
-rw-r--r--src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala4
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Symbols.scala2
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Types.scala152
-rw-r--r--src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala6
-rw-r--r--src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala12
-rw-r--r--src/compiler/scala/tools/nsc/symtab/classfile/UnPickler.scala4
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/ConstantFolder.scala24
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Contexts.scala10
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Infer.scala48
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Namers.scala14
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/RefChecks.scala10
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala4
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala2
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala68
29 files changed, 394 insertions, 500 deletions
diff --git a/src/compiler/scala/tools/ant/Scalac.scala b/src/compiler/scala/tools/ant/Scalac.scala
index b16aacd2dd..7400cf610e 100644
--- a/src/compiler/scala/tools/ant/Scalac.scala
+++ b/src/compiler/scala/tools/ant/Scalac.scala
@@ -619,7 +619,7 @@ class Scalac extends MatchingTask {
/** Performs the compilation. */
override def execute() = {
- val {settings, sourceFiles} = initialize
+ val Pair(settings, sourceFiles) = initialize
val reporter = new ConsoleReporter(settings)
// Compiles the actual code
diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala
index 58f088002b..7636c39e9b 100644
--- a/src/compiler/scala/tools/nsc/Global.scala
+++ b/src/compiler/scala/tools/nsc/Global.scala
@@ -507,7 +507,7 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable
showDef(newTermName(settings.Xshowobj.value), true)
if (reporter.hasErrors) {
- for (val {sym, file} <- symSource.elements) {
+ for (val Pair(sym, file) <- symSource.elements) {
sym.reset(new loaders.SourcefileLoader(file))
if (sym.isTerm) sym.moduleClass.reset(loaders.moduleClassLoader)
}
@@ -520,7 +520,7 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable
warning("there were unchecked warnings; re-run with -unchecked for details")
}
}
- for (val {sym, file} <- symSource.elements) resetPackageClass(sym.owner)
+ for (val Pair(sym, file) <- symSource.elements) resetPackageClass(sym.owner)
//units foreach (.clear())
informTime("total", startTime)
}
diff --git a/src/compiler/scala/tools/nsc/Interpreter.scala b/src/compiler/scala/tools/nsc/Interpreter.scala
index 119b68e5d3..6ea4d43143 100644
--- a/src/compiler/scala/tools/nsc/Interpreter.scala
+++ b/src/compiler/scala/tools/nsc/Interpreter.scala
@@ -102,7 +102,7 @@ class Interpreter(val settings: Settings, reporter: Reporter, out: PrintWriter)
settings.outdir.value = classfilePath.getPath
/** the compiler to compile expressions with */
- val compiler = new Global(settings, reporter)
+ val compiler: Global = new Global(settings, reporter)
/** the compiler's classpath, as URL's */
val compilerClasspath: List[URL] =
diff --git a/src/compiler/scala/tools/nsc/ast/TreeGen.scala b/src/compiler/scala/tools/nsc/ast/TreeGen.scala
index 8be11e40b4..f639fc3c44 100644
--- a/src/compiler/scala/tools/nsc/ast/TreeGen.scala
+++ b/src/compiler/scala/tools/nsc/ast/TreeGen.scala
@@ -164,8 +164,9 @@ abstract class TreeGen {
mkAttributedRef(definitions.NilModule)
/** Builds a pair */
- def mkNewPair(left: Tree, right: Tree) =
- New(Apply(mkAttributedRef(definitions.TupleClass(2)), List(left, right)))
+ def mkTuple(elems: List[Tree]): Tree =
+ if (elems.isEmpty) Literal(())
+ else New(TypeTree(definitions.TupleClass(elems.length).tpe), List(elems))
def mkCached(cvar: Symbol, expr: Tree): Tree = {
val cvarRef = if (cvar.owner.isClass) Select(This(cvar.owner), cvar) else Ident(cvar)
diff --git a/src/compiler/scala/tools/nsc/ast/TreePrinters.scala b/src/compiler/scala/tools/nsc/ast/TreePrinters.scala
index 55b4bb0e2c..5d2afcc332 100644
--- a/src/compiler/scala/tools/nsc/ast/TreePrinters.scala
+++ b/src/compiler/scala/tools/nsc/ast/TreePrinters.scala
@@ -167,7 +167,7 @@ abstract class TreePrinters {
print(symName(tree, name)); printRow(params, "(", ",", ")"); printBlock(rhs)
case Import(expr, selectors) =>
- def selectorToString(s: {Name, Name}): String =
+ def selectorToString(s: Pair[Name, Name]): String =
if (s._1 == nme.WILDCARD || s._1 == s._2) s._1.toString()
else s._1.toString() + "=>" + s._2.toString()
print("import "); print(expr)
diff --git a/src/compiler/scala/tools/nsc/ast/Trees.scala b/src/compiler/scala/tools/nsc/ast/Trees.scala
index a7843c9fad..abcbcf3cf6 100644
--- a/src/compiler/scala/tools/nsc/ast/Trees.scala
+++ b/src/compiler/scala/tools/nsc/ast/Trees.scala
@@ -407,7 +407,7 @@ trait Trees requires Global {
* @param expr
* @param selectors
*/
- case class Import(expr: Tree, selectors: List[{Name, Name}])
+ case class Import(expr: Tree, selectors: List[Pair[Name, Name]])
extends SymTree
/** Annotation application (constructor arguments + name-value pairs) */
@@ -749,7 +749,7 @@ trait Trees requires Global {
def AbsTypeDef(tree: Tree, mods: Modifiers, name: Name, lo: Tree, hi: Tree): AbsTypeDef
def AliasTypeDef(tree: Tree, mods: Modifiers, name: Name, tparams: List[AbsTypeDef], rhs: Tree): AliasTypeDef
def LabelDef(tree: Tree, name: Name, params: List[Ident], rhs: Tree): LabelDef
- def Import(tree: Tree, expr: Tree, selectors: List[{Name, Name}]): Import
+ def Import(tree: Tree, expr: Tree, selectors: List[Pair[Name, Name]]): Import
def Annotation(tree: Tree, constr: Tree, elements: List[Tree]): Annotation
def DocDef(tree: Tree, comment: String, definition: Tree): DocDef
def Template(tree: Tree, parents: List[Tree], body: List[Tree]): Template
@@ -804,7 +804,7 @@ trait Trees requires Global {
new AliasTypeDef(mods, name, tparams, rhs).copyAttrs(tree)
def LabelDef(tree: Tree, name: Name, params: List[Ident], rhs: Tree) =
new LabelDef(name, params, rhs).copyAttrs(tree)
- def Import(tree: Tree, expr: Tree, selectors: List[{Name, Name}]) =
+ def Import(tree: Tree, expr: Tree, selectors: List[Pair[Name, Name]]) =
new Import(expr, selectors).copyAttrs(tree)
def Annotation(tree: Tree, constr: Tree, elements: List[Tree]) =
new Annotation(constr, elements)
@@ -921,7 +921,7 @@ trait Trees requires Global {
if (name0 == name) && (params0 == params) && (rhs0 == rhs) => t
case _ => copy.LabelDef(tree, name, params, rhs)
}
- def Import(tree: Tree, expr: Tree, selectors: List[{Name, Name}]) = tree match {
+ def Import(tree: Tree, expr: Tree, selectors: List[Pair[Name, Name]]) = tree match {
case t @ Import(expr0, selectors0)
if (expr0 == expr) && (selectors0 == selectors) => t
case _ => copy.Import(tree, expr, selectors)
@@ -1287,7 +1287,7 @@ trait Trees requires Global {
traverse(expr)
case Annotation(constr, elements) =>
traverse(constr); traverseTrees(elements)
- case Annotated(constr: Tree, elements: List[Tree], arg: Tree) =>
+ case Annotated(constr, elements, arg) =>
traverse(constr); traverseTrees(elements); traverse(arg)
case DocDef(comment, definition) =>
traverse(definition)
diff --git a/src/compiler/scala/tools/nsc/ast/parser/MarkupParsers.scala b/src/compiler/scala/tools/nsc/ast/parser/MarkupParsers.scala
index 4b85bd2b6d..4e1d73b53f 100644
--- a/src/compiler/scala/tools/nsc/ast/parser/MarkupParsers.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/MarkupParsers.scala
@@ -575,7 +575,7 @@ class MarkupParser(unit: CompilationUnit, s: Scanner, p: Parser, presWS: boolean
*/
def xScalaPatterns: List[Tree] = {
sync;
- val b = p.patterns(true, false);
+ val b = p.patterns(true);
if (/*s.*/token != RBRACE) {
reportSyntaxError(" expected end of Scala patterns");
}
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
index f85ffc8b4e..dfbc330145 100644
--- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
@@ -256,16 +256,11 @@ trait Parsers requires SyntaxAnalyzer {
/** Convert tree to formal parameter list
*/
- def convertToParams(t: Tree): List[ValDef] = t match {
- case Function(params, TypeTree()) =>
- params
- case Ident(_) | Typed(Ident(_), _) =>
- List(convertToParam(t))
- case Literal(c) if c.tag == UnitTag =>
- Nil
+ def convertToParams(tree: Tree): List[ValDef] = tree match {
+ case Parens(ts) =>
+ ts map convertToParam
case _ =>
- syntaxError(t.pos, "malformed formal parameter list", false)
- Nil
+ List(convertToParam(tree))
}
/** Convert tree to formal parameter
@@ -278,7 +273,9 @@ trait Parsers requires SyntaxAnalyzer {
case Typed(Ident(name), tpe) =>
ValDef(Modifiers(Flags.PARAM), name, tpe, EmptyTree)
case _ =>
+ Console.println("CTP "+tree) //debug
syntaxError(tree.pos, "not a legal formal parameter", false)
+ throw new Error()
ValDef(Modifiers(Flags.PARAM), nme.ERROR, errorTypeTree, EmptyTree)
}
}
@@ -316,7 +313,7 @@ trait Parsers requires SyntaxAnalyzer {
Function(
List(ValDef(Modifiers(Flags.PARAM), pname, TypeTree(), EmptyTree)),
- wrapLiftedGenerators(insertParam(tree)))
+ insertParam(tree))
}
/////// OPERAND/OPERATOR STACK /////////////////////////////////////////////////
@@ -568,13 +565,15 @@ trait Parsers requires SyntaxAnalyzer {
}
else TypeTree()
- /** Types ::= Type {`,' Type}
- */
- def types(): List[Tree] = {
- val ts = new ListBuffer[Tree] + typ()
+ /** Types ::= Type {`,' Type} [`,']
+ * ArgTypePatterns ::= ArgTypePattern {`,' ArgTypePattern} [`,']
+ */
+ def types(isPattern: boolean): List[Tree] = {
+ val ts = new ListBuffer[Tree] + argType(isPattern)
while (in.token == COMMA) {
in.nextToken()
- ts += typ()
+ if (in.token == RPAREN) return List(makeTupleType(ts.toList, false))
+ ts += argType(isPattern)
}
ts.toList
}
@@ -584,14 +583,14 @@ trait Parsers requires SyntaxAnalyzer {
final val LeftOp = 1 // left associative
final val RightOp = 2 // right associative
- /** Type ::= InfixType `=>' Type
- * | `(' [Types | `=>' Type] `)' `=>' Type
- * | InfixType
+ /** Type ::= InfixType [`=>' Type]
+ * | (`=>' Type) `=>' Type
+ * | `(' `)' `=>' Type
*/
def typ(): Tree = {
val t =
if (in.token == LPAREN) {
- in.nextToken()
+ val pos = in.skipToken()
if (in.token == RPAREN) {
in.nextToken()
atPos(accept(ARROW)) { makeFunctionTypeTree(List(), typ()) }
@@ -601,24 +600,15 @@ trait Parsers requires SyntaxAnalyzer {
accept(RPAREN)
atPos(accept(ARROW)) { makeByNameFunctionTypeTree(t0, typ()) }
} else {
- val pos = in.currentPos
- val t0 = typ()
- if (in.token == COMMA) {
- in.nextToken()
- val ts = t0 :: types()
- accept(RPAREN)
- checkSize("function arguments", ts.length, definitions.MaxFunctionArity)
- atPos (accept(ARROW)) { makeFunctionTypeTree(ts, typ()) }
- } else {
- accept(RPAREN)
- infixTypeRest(pos, t0, false, FirstOp)
- }
+ val ts = types(false)
+ accept(RPAREN)
+ if (in.token == ARROW) atPos(in.skipToken()) { makeFunctionTypeTree(ts, typ()) }
+ else infixTypeRest(pos, makeTupleType(ts, true), false, FirstOp)
}
} else {
infixType(false, FirstOp)
}
- if (in.token == ARROW) atPos(in.skipToken()) {
- makeFunctionTypeTree(List(t), typ()) }
+ if (in.token == ARROW) atPos(in.skipToken()) { makeFunctionTypeTree(List(t), typ()) }
else t
}
@@ -667,35 +657,24 @@ trait Parsers requires SyntaxAnalyzer {
* | SimpleType1 `#' Id
* | StableId
* | Path `.' type
- * | `(' Type `)'
- * | `{' [Type `,' [Types [`,']]] `}'
- * SimpleTypePattern ::= SimpleTypePattern1 [TypePatternArgs]
- * SimpleTypePattern1 ::= SimpleTypePattern1 "#" Id
+ * | `(' Types `)'
+ * SimpleTypePattern ::= Annotations SimpleTypePattern1
+ * SimpleTypePattern1 ::= SimpleTypePattern2 [TypePatternArgs]
+ * SimpleTypePattern2 ::= SimpleTypePattern2 "#" Id
* | StableId
* | Path `.' type
- * | `{' [ArgTypePattern `,' [ArgTypePatterns [`,']]] `}'
+ * | `(' ArgTypePattern {`,' ArgTypePattern} [`,'] `)'
*/
def simpleType(isPattern: boolean): Tree = {
val annots = if (settings.Xplugtypes.value) typeAttributes()
else annotations()
val pos = in.currentPos
var t: Tree =
- if (in.token == LPAREN && !isPattern) {
+ if (in.token == LPAREN) {
in.nextToken()
- val t = typ()
+ val ts = types(isPattern)
accept(RPAREN)
- t
- } else if (in.token == LBRACE) {
- in.nextToken()
- val ts = if (in.token == RBRACE) List()
- else {
- val t1 = argType(isPattern)
- accept(COMMA)
- t1 :: (if (in.token == RBRACE) List() else argTypes(isPattern, true))
- }
- checkSize("tuple elements", ts.length, definitions.MaxTupleArity)
- accept(RBRACE)
- makeTupleType(ts, false)
+ atPos(pos) { makeTupleType(ts, true) }
} else {
val r = path(false, true)
val x = r match {
@@ -723,29 +702,16 @@ trait Parsers requires SyntaxAnalyzer {
else (t /: annots) (makeAnnotated)
}
- /** TypeArgs ::= `[' ArgTypes `]'
- * TypePatternArgs ::= '[' ArgTypePatterns `]'
+ /** TypeArgs ::= `[' ArgType {`,' ArgType} `]'
+ * TypePatternArgs ::= '[' ArgTypePattern {`,' ArgTypePattern} `]'
*/
def typeArgs(isPattern: boolean): List[Tree] = {
accept(LBRACKET)
- val ts = argTypes(isPattern, false)
+ val ts = types(isPattern)
accept(RBRACKET)
ts
}
- /** ArgTypes ::= ArgType {`,' ArgType}
- * ArgTypePatterns ::= ArgTypePattern {`,' ArgTypePattern}
- */
- def argTypes(isPattern: boolean, trailingComma: boolean): List[Tree] = {
- val ts = new ListBuffer[Tree] + argType(isPattern)
- while (in.token == COMMA) {
- in.nextToken()
- if (!trailingComma || in.token != RBRACE)
- ts += argType(isPattern)
- }
- ts.toList
- }
-
/** ArgType ::= Type
* ArgTypePattern ::= varid
* | `_'
@@ -764,6 +730,7 @@ trait Parsers requires SyntaxAnalyzer {
//////// EXPRESSIONS ////////////////////////////////////////////////////////
+/*
// XX_LIFTED
var liftedGenerators = new collection.mutable.ListBuffer[ValFrom]
@@ -797,7 +764,7 @@ trait Parsers requires SyntaxAnalyzer {
liftedGenerators = savedLiftedGenerators
t
}
-
+*/
/** EqualsExpr ::= `=' Expr
*/
def equalsExpr(): Tree = {
@@ -805,19 +772,20 @@ trait Parsers requires SyntaxAnalyzer {
expr()
}
- /** Exprs ::= Expr {`,' Expr} [ `:' `_' `*' ]
+ /** Exprs ::= Expr {`,' Expr} [`,']
*/
- def argExprs(): List[Tree] = {
+ def exprs(): List[Tree] = {
val ts = new ListBuffer[Tree] + argExpr()
while (in.token == COMMA) {
- in.nextToken(); ts += argExpr()
+ in.nextToken();
+ if (in.token == RPAREN) return List(makeTupleTerm(ts.toList, false))
+ ts += argExpr()
}
ts.toList
}
/** expression modifiles */
- final val IsArgument = 1
final val IsInBlock = 2
final val ClosureOK = 4
@@ -835,29 +803,27 @@ trait Parsers requires SyntaxAnalyzer {
* | [SimpleExpr `.'] Id `=' Expr
* | SimpleExpr ArgumentExprs `=' Expr
* | `.' SimpleExpr
- * | PostfixExpr [`:' CompoundType]
+ * | PostfixExpr [`:' (CompoundType | `_' `*')]
* | PostfixExpr match [`!'] `{' CaseClauses `}'
* | MethodClosure
* Bindings ::= `(' [Binding {`,' Binding}] `)'
* Binding ::= Id [`:' Type]
*/
def expr(): Tree =
- liftingScope(exprImpl(ClosureOK))
+ exprImpl(ClosureOK)
def blockStatExpr(): Tree = {
- liftingScope(exprImpl(IsInBlock | ClosureOK))
+ exprImpl(IsInBlock | ClosureOK)
}
def argExpr(): Tree = {
- exprImpl(IsArgument | ClosureOK)
+ exprImpl(ClosureOK)
}
def localExpr(): Tree = {
exprImpl(ClosureOK)
}
- def expr1(): Tree = exprImpl(0)
-
private def exprImpl(mode: int): Tree = in.token match {
case IF =>
val pos = in.skipToken()
@@ -892,7 +858,7 @@ trait Parsers requires SyntaxAnalyzer {
val lname: Name = unit.fresh.newName("while$")
val pos = in.skipToken()
accept(LPAREN)
- val cond = noLifting(localExpr())
+ val cond = localExpr()
accept(RPAREN)
newLinesOpt()
val body = expr()
@@ -904,7 +870,7 @@ trait Parsers requires SyntaxAnalyzer {
if (isStatSep) in.nextToken()
accept(WHILE)
accept(LPAREN)
- val cond = noLifting(localExpr())
+ val cond = localExpr()
accept(RPAREN)
atPos(pos) { makeDoWhile(lname, body, cond) }
case FOR =>
@@ -929,7 +895,7 @@ trait Parsers requires SyntaxAnalyzer {
case DOT =>
atPos(in.skipToken()) {
if (isIdent) {
- liftingScope(makeClosure(simpleExpr()))
+ makeClosure(stripParens(simpleExpr()))
// Note: makeClosure does some special treatment of liftedGenerators
} else {
syntaxErrorOrIncomplete("identifier expected", true)
@@ -945,17 +911,16 @@ trait Parsers requires SyntaxAnalyzer {
case _ =>
}
} else if (in.token == COLON) {
+ t = stripParens(t)
val pos = in.skipToken()
val annots = annotations()
- if ((mode & IsArgument) != 0 && in.token == USCORE) {
+ if (in.token == USCORE) {
val pos1 = in.skipToken()
if (isIdent && in.name == nme.STAR) {
in.nextToken()
t = atPos(pos) {
Typed(t, atPos(pos1) { Ident(nme.WILDCARD_STAR.toTypeName) })
}
- if (in.token != RPAREN)
- syntaxErrorOrIncomplete("`)' expected", false)
} else {
syntaxErrorOrIncomplete("`*' expected", true)
}
@@ -974,7 +939,7 @@ trait Parsers requires SyntaxAnalyzer {
accept(LBRACE)
val cases = caseClauses()
accept(RBRACE)
- Match(t, cases)
+ Match(stripParens(t), cases)
}
}
if ((mode & ClosureOK) != 0 && in.token == ARROW) {
@@ -982,12 +947,12 @@ trait Parsers requires SyntaxAnalyzer {
Function(convertToParams(t), if ((mode & IsInBlock) != 0) block() else expr())
}
}
- t
+ stripParens(t)
}
/** PostfixExpr ::= [`.'] InfixExpr [Id [NewLine]]
* InfixExpr ::= PrefixExpr
- * | InfixExpr Id [NewLine] (InfixExpr | ArgumentExprs)
+ * | InfixExpr Id [NewLine] InfixExpr
*/
def postfixExpr(): Tree = {
val base = opstack
@@ -1000,7 +965,7 @@ trait Parsers requires SyntaxAnalyzer {
ident()
newLineOptWhenFollowing(isExprIntroToken)
if (isExprIntro) {
- top = secondInfixOperandExpr(op)
+ top = prefixExpr()
} else {
val topinfo = opstack.head
opstack = opstack.tail
@@ -1012,17 +977,6 @@ trait Parsers requires SyntaxAnalyzer {
reduceStack(true, base, top, 0, true)
}
- def secondInfixOperandExpr(op: Name): Tree =
- if (in.token == LPAREN && treeInfo.isLeftAssoc(op)) {
- val pos = in.currentPos
- val args = argumentExprs()
- if (args.isEmpty) simpleExprRest(Literal(()) setPos pos, false)
- else if (args.tail.isEmpty) simpleExprRest(args.head, false)
- else ArgumentExprs(args)
- } else {
- prefixExpr()
- }
-
/** PrefixExpr ::= [`-' | `+' | `~' | `!' | `&' | `/'] SimpleExpr
*/
def prefixExpr(): Tree =
@@ -1030,16 +984,16 @@ trait Parsers requires SyntaxAnalyzer {
val name = ident()
in.token match {
case INTLIT | LONGLIT | FLOATLIT | DOUBLELIT => literal(false, true)
- case _ => atPos(in.currentPos) { Select(simpleExpr(), name) }
+ case _ => atPos(in.currentPos) { Select(stripParens(simpleExpr()), name) }
}
} else if (isIdent && (in.name == PLUS || in.name == TILDE || in.name == BANG)) {
val pos = in.currentPos
val name = ident()
- atPos(pos) { Select(simpleExpr(), name) }
+ atPos(pos) { Select(stripParens(simpleExpr()), name) }
} else if (isIdent && in.name == AMP) {
val pos = in.currentPos
val name = ident()
- atPos(pos) { Typed(simpleExpr(), Function(List(), EmptyTree)) }
+ atPos(pos) { Typed(stripParens(simpleExpr()), Function(List(), EmptyTree)) }
/* XX-LIFTING
} else if (settings.Xexperimental.value && isIdent && in.name == SLASH) {
val pos = in.skipToken()
@@ -1059,6 +1013,7 @@ trait Parsers requires SyntaxAnalyzer {
* | StableId `.' class
* | `(' [Expr] `)'
* | BlockExpr
+ * | new Template
* | SimpleExpr `.' Id
* | SimpleExpr TypeArgs
* | SimpleExpr1 ArgumentExprs
@@ -1076,28 +1031,9 @@ trait Parsers requires SyntaxAnalyzer {
t = path(true, false)
case LPAREN =>
val pos = in.skipToken()
- if (in.token == RPAREN) {
- in.nextToken()
- t = Literal(()).setPos(pos)
- } else {
- t = localExpr()
- if (in.token == COMMA) {
- val commapos = in.skipToken()
- val ts = new ListBuffer[Tree] + t ++ argExprs()
- accept(RPAREN)
- if (in.token == ARROW) {
- t = atPos(pos) {
- Function(ts.toList map convertToParam, TypeTree())
- }
- } else if(in.token == EOF) {
- incompleteInputError("`=>' expected")
- } else {
- syntaxError(commapos, "`)' expected", false)
- }
- } else {
- accept(RPAREN)
- }
- }
+ val ts = if (in.token == RPAREN) List() else exprs()
+ accept(RPAREN)
+ t = Parens(ts)
case LBRACE =>
t = blockExpr()
case NEW =>
@@ -1130,7 +1066,7 @@ trait Parsers requires SyntaxAnalyzer {
def simpleExprRest(t: Tree, isNew: boolean): Tree = in.token match {
case DOT =>
- simpleExprRest(atPos(in.skipToken()) { selector(t) }, false)
+ simpleExprRest(atPos(in.skipToken()) { selector(stripParens(t)) }, false)
case LBRACKET =>
t match {
case Ident(_) | Select(_, _) =>
@@ -1139,7 +1075,7 @@ trait Parsers requires SyntaxAnalyzer {
t
}
case LPAREN | LBRACE if (!isNew) =>
- simpleExprRest(atPos(in.currentPos) { Apply(t, argumentExprs()) }, false)
+ simpleExprRest(atPos(in.currentPos) { Apply(stripParens(t), argumentExprs()) }, false)
case _ =>
t
}
@@ -1152,7 +1088,7 @@ trait Parsers requires SyntaxAnalyzer {
List(blockExpr())
} else {
accept(LPAREN)
- val ts = if (in.token == RPAREN) List() else argExprs()
+ val ts = if (in.token == RPAREN) List() else exprs()
accept(RPAREN)
ts
}
@@ -1163,18 +1099,16 @@ trait Parsers requires SyntaxAnalyzer {
def blockExpr(): Tree = {
val res = atPos(accept(LBRACE)) {
if (in.token == CASE) makeVisitor(caseClauses(), true)
- else blockOrTuple(true)
+ else block()
}
accept(RBRACE)
res
}
/** Block ::= BlockStatSeq
- * Tuple ::= [Expr1 `,' {Expr1 `,'} [Expr1]]
*/
- def block(): Tree = blockOrTuple(false)
- def blockOrTuple(tupleOK: boolean): Tree =
- makeBlock(blockStatSeqOrTuple(tupleOK, new ListBuffer[Tree]))
+ def block(): Tree =
+ makeBlock(blockStatSeq(new ListBuffer[Tree]))
/** CaseClauses ::= CaseClause {CaseClause}
*/
@@ -1191,7 +1125,7 @@ trait Parsers requires SyntaxAnalyzer {
atPos(accept(CASE)) {
val pat = pattern()
val guard =
- if (in.token == IF) { in.nextToken(); noLifting(postfixExpr()) }
+ if (in.token == IF) { in.nextToken(); stripParens(postfixExpr()) }
else EmptyTree
makeCaseDef(pat, guard, atPos(accept(ARROW))(block()))
}
@@ -1225,12 +1159,12 @@ trait Parsers requires SyntaxAnalyzer {
/** Patterns ::= Pattern { `,' Pattern } */
/** SeqPatterns ::= SeqPattern { `,' SeqPattern } */
- def patterns(seqOK: boolean, trailingComma: boolean): List[Tree] = {
- val ts = new ListBuffer[Tree]
- ts += pattern(seqOK)
+ def patterns(seqOK: boolean): List[Tree] = {
+ val ts = new ListBuffer[Tree] + pattern(seqOK)
while (in.token == COMMA) {
in.nextToken();
- if (!trailingComma || in.token != RBRACE) ts += pattern(seqOK)
+ if (in.token == RPAREN) return List(makeTupleTerm(ts.toList, false))
+ ts += pattern(seqOK)
}
ts.toList
}
@@ -1319,22 +1253,11 @@ trait Parsers requires SyntaxAnalyzer {
val op = in.name
opstack = OpInfo(top, op, in.currentPos) :: opstack
ident()
- top = secondInfixOperandPattern(op, seqOK)
+ top = simplePattern(seqOK)
}
- reduceStack(false, base, top, 0, true)
+ stripParens(reduceStack(false, base, top, 0, true))
}
- def secondInfixOperandPattern(op: Name, seqOK: boolean): Tree =
- if (in.token == LPAREN && treeInfo.isLeftAssoc(op)) {
- val pos = in.currentPos
- val args = argumentPatterns()
- if (args.isEmpty) Literal(()) setPos pos
- else if (args.tail.isEmpty) args.head
- else ArgumentExprs(args)
- } else {
- simplePattern(seqOK)
- }
-
/** SimplePattern ::= varid
* | `_'
* | literal
@@ -1373,9 +1296,7 @@ trait Parsers requires SyntaxAnalyzer {
}
else */
if (in.token == LPAREN) {
- atPos(in.currentPos) { Apply(/*convertToTypeId*/(t), argumentPatterns()) }
- } else if (in.token == LBRACE) {
- atPos(in.currentPos) { Apply(/*convertToTypeId*/(t), List(tuplePattern())) }
+ atPos(in.currentPos) { Apply(t, argumentPatterns()) }
} else t
case USCORE =>
atPos(in.skipToken()) { Ident(nme.WILDCARD) }
@@ -1383,15 +1304,9 @@ trait Parsers requires SyntaxAnalyzer {
literal(true, false)
case LPAREN =>
val pos = in.skipToken()
- val p =
- //if (false /*disabled, no regexp matching*/ && seqOK) atPos(pos) { makeSequence(patterns(true, false)) }
- //else
- if (in.token != RPAREN) pattern(false)
- else Literal(()).setPos(pos)
+ val ps = if (in.token == RPAREN) List() else patterns(false)
accept(RPAREN)
- p
- case LBRACE =>
- tuplePattern()
+ Parens(ps)
case XMLSTART =>
xmlp.xLiteralPattern
case _ =>
@@ -1404,24 +1319,11 @@ trait Parsers requires SyntaxAnalyzer {
def argumentPatterns(): List[Tree] = {
accept(LPAREN)
- val ps = if (in.token == RPAREN) List() else patterns(true, false)
+ val ps = if (in.token == RPAREN) List() else patterns(true)
accept(RPAREN)
ps
}
- def tuplePattern(): Tree = {
- in.nextToken()
- val ts = if (in.token == RBRACE) List()
- else {
- val p1 = pattern()
- accept(COMMA)
- p1 :: (if (in.token == RBRACE) List() else patterns(false, true))
- }
- checkSize("tuple elements", ts.length, definitions.MaxTupleArity)
- accept(RBRACE)
- makeTuplePattern(ts)
- }
-
////////// MODIFIERS ////////////////////////////////////////////////////////////
private def normalize(mods: Modifiers): Modifiers =
@@ -1706,7 +1608,7 @@ trait Parsers requires SyntaxAnalyzer {
def loop: Tree =
if (in.token == USCORE) {
in.nextToken()
- Import(t, List({nme.WILDCARD, null}))
+ Import(t, List(Pair(nme.WILDCARD, null)))
} else if (in.token == LBRACE) {
Import(t, importSelectors())
} else {
@@ -1716,7 +1618,7 @@ trait Parsers requires SyntaxAnalyzer {
pos = accept(DOT)
loop
} else {
- Import(t, List({name, name}))
+ Import(t, List(Pair(name, name)))
}
}
loop
@@ -1724,8 +1626,8 @@ trait Parsers requires SyntaxAnalyzer {
/** ImportSelectors ::= `{' {ImportSelector `,'} (ImportSelector | `_') `}'
*/
- def importSelectors(): List[{Name, Name}] = {
- val names = new ListBuffer[{Name, Name}]
+ def importSelectors(): List[Pair[Name, Name]] = {
+ val names = new ListBuffer[Pair[Name, Name]]
accept(LBRACE)
var isLast = importSelector(names)
while (!isLast && in.token == COMMA) {
@@ -1738,19 +1640,19 @@ trait Parsers requires SyntaxAnalyzer {
/** ImportSelector ::= Id [`=>' Id | `=>' `_']
*/
- def importSelector(names: ListBuffer[{Name, Name}]): boolean =
+ def importSelector(names: ListBuffer[Pair[Name, Name]]): boolean =
if (in.token == USCORE) {
- in.nextToken(); names += {nme.WILDCARD, null}; true
+ in.nextToken(); names += Pair(nme.WILDCARD, null); true
} else {
val name = ident()
- names += {
+ names += Pair(
name,
if (in.token == ARROW) {
in.nextToken()
if (in.token == USCORE) { in.nextToken(); nme.WILDCARD } else ident()
} else {
name
- }}
+ })
false
}
@@ -1788,7 +1690,7 @@ trait Parsers requires SyntaxAnalyzer {
var lhs = new ListBuffer[Tree]
do {
in.nextToken()
- lhs += pattern2(false)
+ lhs += stripParens(pattern2(false))
} while (in.token == COMMA)
val tp = typedOpt()
val rhs =
@@ -1823,9 +1725,9 @@ trait Parsers requires SyntaxAnalyzer {
*/
def varDefOrDcl(mods: Modifiers): List[Tree] = {
var newmods = mods | Flags.MUTABLE
- val lhs = new ListBuffer[{Int, Name}]
+ val lhs = new ListBuffer[Pair[Int, Name]]
do {
- lhs += {in.skipToken(), ident()}
+ lhs += Pair(in.skipToken(), ident())
} while (in.token == COMMA)
val tp = typedOpt()
val rhs = if (tp.isEmpty || in.token == EQUALS) {
@@ -1840,7 +1742,7 @@ trait Parsers requires SyntaxAnalyzer {
newmods = newmods | Flags.DEFERRED
EmptyTree
}
- for (val {pos, name} <- lhs.toList) yield
+ for (val Pair(pos, name) <- lhs.toList) yield
atPos(pos) { ValDef(newmods, name, tp.duplicate, rhs.duplicate) }
}
@@ -1963,10 +1865,10 @@ trait Parsers requires SyntaxAnalyzer {
implicitClassViews = implicitViewBuf.toList
//if (mods.hasFlag(Flags.CASE) && in.token != LPAREN) accept(LPAREN)
val constrAnnots = annotations()
- val {constrMods, vparamss} =
- if (mods.hasFlag(Flags.TRAIT)) {NoMods, List()}
- else {accessModifierOpt(),
- paramClauses(name, implicitClassViews, mods.hasFlag(Flags.CASE))}
+ val Pair(constrMods, vparamss) =
+ if (mods.hasFlag(Flags.TRAIT)) Pair(NoMods, List())
+ else Pair(accessModifierOpt(),
+ paramClauses(name, implicitClassViews, mods.hasFlag(Flags.CASE)))
val thistpe = requiresTypeOpt()
val template = classTemplate(mods, name, constrMods withAnnotations constrAnnots, vparamss)
val mods1 = if (mods.hasFlag(Flags.TRAIT) &&
@@ -2162,7 +2064,7 @@ trait Parsers requires SyntaxAnalyzer {
if (settings.Xplugtypes.value) {
while(in.token == LBRACKET) {
accept(LBRACKET)
- exps ++= argExprs
+ exps ++= exprs()
accept(RBRACKET)
}
}
@@ -2177,7 +2079,7 @@ trait Parsers requires SyntaxAnalyzer {
var pos = in.currentPos
val aname = atPos(pos) { Ident(ident()) }
accept(EQUALS)
- atPos(pos) { Assign(aname, liftingScope(prefixExpr())) }
+ atPos(pos) { Assign(aname, stripParens(prefixExpr())) }
}
val pos = in.currentPos
var t: Tree = convertToTypeId(stableId())
@@ -2222,11 +2124,8 @@ trait Parsers requires SyntaxAnalyzer {
* | LocalModifiers TmplDef
* | Expr1
* |
- * Tuple ::= [Expr1 `,' {Expr1 `,'} [Expr1]]
*/
- def blockStatSeq(stats: ListBuffer[Tree]): List[Tree] =
- blockStatSeqOrTuple(false, stats)
- def blockStatSeqOrTuple(tupleOK: boolean, stats: ListBuffer[Tree]): List[Tree] = {
+ def blockStatSeq(stats: ListBuffer[Tree]): List[Tree] = {
def localDef(mods: Modifiers) = {
if (!(mods hasFlag ~Flags.IMPLICIT)) stats ++= defOrDcl(mods)
else stats += tmplDef(mods)
@@ -2243,23 +2142,7 @@ trait Parsers requires SyntaxAnalyzer {
stats ++= importClause()
acceptStatSep()
} else if (isExprIntro) {
- val expr = blockStatExpr()
- if (in.token == COMMA) {
- val exprbuf = new ListBuffer[Tree] + expr
- while (in.token == COMMA) {
- in.nextToken()
- if (in.token != RBRACE) exprbuf += expr1()
- }
- val exprs = exprbuf.toList
- if (in.token == ARROW) {
- val vdefs = exprs flatMap convertToParams
- checkSize("function arguments", vdefs.length, definitions.MaxFunctionArity)
- stats += atPos(in.skipToken()) { Function(vdefs, block()) }
- } else {
- checkSize("tuple elements:", exprs.length, definitions.MaxTupleArity)
- stats += makeTupleTerm(exprs, false)
- }
- } else stats += expr
+ stats += blockStatExpr()
if (in.token != RBRACE && in.token != CASE) acceptStatSep()
} else if (isDefIntro) {
localDef(NoMods)
diff --git a/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala b/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala
index e09b18dfd8..b197940207 100644
--- a/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala
@@ -57,16 +57,16 @@ abstract class TreeBuilder {
/** Traverse pattern and collect all variable names with their types in buffer */
private object getvarTraverser extends Traverser {
- val buf = new ListBuffer[{Name, Tree}]
+ val buf = new ListBuffer[Pair[Name, Tree]]
def init: Traverser = { buf.clear; this }
override def traverse(tree: Tree): unit = tree match {
case Bind(name, Typed(tree1, tpt)) =>
if ((name != nme.WILDCARD) && (buf.elements forall (name !=)))
- buf += {name, tpt}
+ buf += Pair(name, tpt)
traverse(tree1)
case Bind(name, tree1) =>
if ((name != nme.WILDCARD) && (buf.elements forall (name !=)))
- buf += {name, TypeTree()}
+ buf += Pair(name, TypeTree())
traverse(tree1)
case _ =>
super.traverse(tree)
@@ -76,7 +76,7 @@ abstract class TreeBuilder {
/** Returns list of all pattern variables, possibly with their types,
* without duplicates
*/
- private def getVariables(tree: Tree): List[{Name, Tree}] = {
+ private def getVariables(tree: Tree): List[Pair[Name, Tree]] = {
getvarTraverser.init.traverse(tree)
getvarTraverser.buf.toList
}
@@ -92,48 +92,48 @@ abstract class TreeBuilder {
case _ => makeTuple(trees, false)
}
- def makeTuplePattern(trees: List[Tree]): Tree = trees match {
- case List() => Literal(())
- case _ => makeTuple(trees, false)
- }
-
def makeTupleType(trees: List[Tree], flattenUnary: boolean): Tree = trees match {
case List() => scalaUnitConstr
case List(tree) if flattenUnary => tree
case _ => AppliedTypeTree(scalaDot(newTypeName("Tuple" + trees.length)), trees)
}
+ def stripParens(t: Tree) = t match {
+ case Parens(ts) => atPos(t.pos) { makeTupleTerm(ts, true) }
+ case _ => t
+ }
+
def makeAnnotated(t: Tree, attr: Tree): Tree = attr match {
case Annotation(constr, elements) => Annotated(constr, elements, t) setPos attr.pos
}
/** If tree is a variable pattern, return Some("its name and type").
* Otherwise return none */
- private def matchVarPattern(tree: Tree): Option[{Name, Tree}] = tree match {
- case Ident(name) => Some{name, TypeTree()}
- case Bind(name, Ident(nme.WILDCARD)) => Some{name, TypeTree()}
- case Typed(Ident(name), tpt) => Some{name, tpt}
- case Bind(name, Typed(Ident(nme.WILDCARD), tpt)) => Some{name, tpt}
+ private def matchVarPattern(tree: Tree): Option[Pair[Name, Tree]] = tree match {
+ case Ident(name) => Some(Pair(name, TypeTree()))
+ case Bind(name, Ident(nme.WILDCARD)) => Some(Pair(name, TypeTree()))
+ case Typed(Ident(name), tpt) => Some(Pair(name, tpt))
+ case Bind(name, Typed(Ident(nme.WILDCARD), tpt)) => Some(Pair(name, tpt))
case _ => None
}
/** Create tree representing (unencoded) binary operation expression or pattern. */
def makeBinop(isExpr: boolean, left: Tree, op: Name, right: Tree): Tree = {
val arguments = right match {
- case ArgumentExprs(args) => args
+ case Parens(args) => args
case _ => List(right)
}
if (isExpr) {
if (treeInfo.isLeftAssoc(op)) {
- Apply(Select(left, op.encode), arguments)
+ Apply(Select(stripParens(left), op.encode), arguments)
} else {
val x = freshName();
Block(
- List(ValDef(Modifiers(SYNTHETIC), x, TypeTree(), left)),
- Apply(Select(right, op.encode), List(Ident(x))))
+ List(ValDef(Modifiers(SYNTHETIC), x, TypeTree(), stripParens(left))),
+ Apply(Select(stripParens(right), op.encode), List(Ident(x))))
}
} else {
- Apply(Ident(op.encode), left :: arguments)
+ Apply(Ident(op.encode), stripParens(left) :: arguments)
}
}
@@ -259,7 +259,7 @@ abstract class TreeBuilder {
private def makeFor(mapName: Name, flatMapName: Name, enums: List[Enumerator], body: Tree): Tree = {
def makeClosure(pat: Tree, body: Tree): Tree = matchVarPattern(pat) match {
- case Some{name, tpt} =>
+ case Some(Pair(name, tpt)) =>
Function(List(ValDef(Modifiers(PARAM), name, tpt, EmptyTree)), body)
case None =>
makeVisitor(List(CaseDef(pat, EmptyTree, body)), false)
@@ -385,7 +385,7 @@ abstract class TreeBuilder {
/** Create tree for pattern definition &lt;mods val pat0 = rhs&gt; */
def makePatDef(mods: Modifiers, pat: Tree, rhs: Tree): List[Tree] = matchVarPattern(pat) match {
- case Some{name, tpt} =>
+ case Some(Pair(name, tpt)) =>
List(ValDef(mods, name, tpt, rhs))
case None =>
@@ -410,13 +410,13 @@ abstract class TreeBuilder {
vars match {
case List() =>
List(matchExpr)
- case List{vname, tpt} =>
+ case List(Pair(vname, tpt)) =>
List(ValDef(mods, vname, tpt, matchExpr))
case _ =>
val tmp = freshName()
val firstDef = ValDef(Modifiers(PRIVATE | LOCAL | SYNTHETIC), tmp, TypeTree(), matchExpr)
var cnt = 0
- val restDefs = for (val {vname, tpt} <- vars) yield {
+ val restDefs = for (val Pair(vname, tpt) <- vars) yield {
cnt = cnt + 1
ValDef(mods, vname, tpt, Select(Ident(tmp), newTermName("_" + cnt)))
}
@@ -448,5 +448,5 @@ abstract class TreeBuilder {
makePackaging(qual, List(PackageDef(name, stats)))
}
- case class ArgumentExprs(args: List[Tree]) extends Tree
+ case class Parens(args: List[Tree]) extends Tree
}
diff --git a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
index 2622be079a..0219442b8a 100644
--- a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
+++ b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
@@ -484,34 +484,34 @@ abstract class GenICode extends SubComponent {
val kind = toTypeKind(tree.tpe)
var handlers = for (val CaseDef(pat, _, body) <- catches.reverse)
yield pat match {
- case Typed(Ident(nme.WILDCARD), tpt) => {tpt.tpe.symbol, kind, {
+ case Typed(Ident(nme.WILDCARD), tpt) => Triple(tpt.tpe.symbol, kind, {
ctx: Context =>
ctx.bb.emit(DROP(REFERENCE(tpt.tpe.symbol)));
val ctx1 = genLoad(body, ctx, kind);
genLoad(finalizer, ctx1, UNIT);
- }}
+ })
- case Ident(nme.WILDCARD) => {definitions.ThrowableClass, kind, {
+ case Ident(nme.WILDCARD) => Triple(definitions.ThrowableClass, kind, {
ctx: Context =>
ctx.bb.emit(DROP(REFERENCE(definitions.ThrowableClass)))
val ctx1 = genLoad(body, ctx, kind)
genLoad(finalizer, ctx1, UNIT)
- }}
+ })
case Bind(name, _) =>
val exception = new Local(pat.symbol, toTypeKind(pat.symbol.tpe), false)
ctx.method.addLocal(exception);
- {pat.symbol.tpe.symbol, kind, {
+ Triple(pat.symbol.tpe.symbol, kind, {
ctx: Context =>
ctx.bb.emit(STORE_LOCAL(exception), pat.pos);
val ctx1 = genLoad(body, ctx, kind);
genLoad(finalizer, ctx1, UNIT);
- }}
+ })
}
if (finalizer != EmptyTree)
- handlers = { NoSymbol, kind, {
+ handlers = Triple(NoSymbol, kind, {
ctx: Context =>
val exception = new Local(ctx.method.symbol
.newVariable(finalizer.pos, unit.fresh.newName("exc"))
@@ -525,7 +525,7 @@ abstract class GenICode extends SubComponent {
ctx1.bb.emit(THROW());
ctx1.bb.enterIgnoreMode;
ctx1
- }} :: handlers;
+ }) :: handlers;
ctx.Try(
bodyCtx => {
@@ -1273,9 +1273,9 @@ abstract class GenICode extends SubComponent {
def genComparisonOp(l: Tree, r: Tree, code: Int): Unit = {
// special-case reference (in)equality test for null
if (code == scalaPrimitives.ID || code == scalaPrimitives.NI) {
- val expr: Tree = {l, r} match {
- case {Literal(Constant(null)), expr} => expr
- case {expr, Literal(Constant(null))} => expr
+ val expr: Tree = Pair(l, r) match {
+ case Pair(Literal(Constant(null)), expr) => expr
+ case Pair(expr, Literal(Constant(null))) => expr
case _ => null
}
if (expr ne null) {
@@ -1393,15 +1393,15 @@ abstract class GenICode extends SubComponent {
local
}
- {l, r} match {
+ Pair(l, r) match {
// null == expr -> expr eq null
- case {Literal(Constant(null)), expr} =>
+ case Pair(Literal(Constant(null)), expr) =>
val ctx1 = genLoad(expr, ctx, ANY_REF_CLASS)
ctx1.bb.emit(CZJUMP(thenCtx.bb, elseCtx.bb, EQ, ANY_REF_CLASS))
ctx1.bb.close
// expr == null -> if(expr eq null) true else expr.equals(null)
- case {expr, Literal(Constant(null))} =>
+ case Pair(expr, Literal(Constant(null))) =>
val eqEqTempLocal = getTempLocal
var ctx1 = genLoad(expr, ctx, ANY_REF_CLASS)
ctx1.bb.emit(DUP(ANY_REF_CLASS))
@@ -1808,7 +1808,7 @@ abstract class GenICode extends SubComponent {
* } ))</code>
*/
def Try(body: Context => Context,
- handlers: List[{Symbol, TypeKind, (Context => Context)}],
+ handlers: List[Triple[Symbol, TypeKind, (Context => Context)]],
finalizer: Tree) = {
val outerCtx = this.dup
val afterCtx = outerCtx.newBlock
diff --git a/src/compiler/scala/tools/nsc/backend/icode/Members.scala b/src/compiler/scala/tools/nsc/backend/icode/Members.scala
index 6116b73d1e..0f8d1091a1 100644
--- a/src/compiler/scala/tools/nsc/backend/icode/Members.scala
+++ b/src/compiler/scala/tools/nsc/backend/icode/Members.scala
@@ -229,7 +229,7 @@ trait Members requires ICodes {
var end: Int = _
/** PC-based ranges for this local variable's visibility range */
- var ranges: List[{Int, Int}] = Nil
+ var ranges: List[Pair[Int, Int]] = Nil
override def equals(other: Any): Boolean = (
other.isInstanceOf[Local] &&
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala
index d412a4315e..0a4de0e814 100644
--- a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala
+++ b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala
@@ -203,7 +203,7 @@ abstract class GenJVM extends SubComponent {
}
def addExceptionsAttribute(sym: Symbol): Unit = {
- val {excs, others} = sym.attributes.partition((a => a match {
+ val Pair(excs, others) = sym.attributes.partition((a => a match {
case AttrInfo(ThrowsAttr, _, _) => true
case _ => false
}))
@@ -289,7 +289,7 @@ abstract class GenJVM extends SubComponent {
buf.putShort(cpool.addUtf8("value").toShort)
emitElement(consts.head)
}
- for (val {name, value} <- nvPairs) {
+ for (val Pair(name, value) <- nvPairs) {
buf.putShort(cpool.addUtf8(name.toString()).toShort)
emitElement(value)
}
@@ -593,7 +593,7 @@ abstract class GenJVM extends SubComponent {
if (! (covered contains b) ) {
if (start >= 0) { // we're inside a handler range
end = labels(b).getAnchor()
- ranges = {start, end} :: ranges
+ ranges = Pair(start, end) :: ranges
start = -1
}
} else {
@@ -612,7 +612,7 @@ abstract class GenJVM extends SubComponent {
* code!
*/
if (start >= 0) {
- ranges = {start, jcode.getPC()} :: ranges;
+ ranges = Pair(start, jcode.getPC()) :: ranges;
}
if (covered != Nil)
@@ -989,10 +989,10 @@ abstract class GenJVM extends SubComponent {
case SCOPE_EXIT(lv) =>
if (varsInBlock contains lv) {
- lv.ranges = {lv.start, jcode.getPC()} :: lv.ranges
+ lv.ranges = Pair(lv.start, jcode.getPC()) :: lv.ranges
varsInBlock -= lv
} else if (b.varsInScope contains lv) {
- lv.ranges = {labels(b).getAnchor(), jcode.getPC()} :: lv.ranges
+ lv.ranges = Pair(labels(b).getAnchor(), jcode.getPC()) :: lv.ranges
b.varsInScope -= lv
} else
assert(false, "Illegal local var nesting: " + method)
@@ -1022,10 +1022,10 @@ abstract class GenJVM extends SubComponent {
// local vars that survived this basic block
for (val lv <- varsInBlock) {
- lv.ranges = {lv.start, jcode.getPC()} :: lv.ranges
+ lv.ranges = Pair(lv.start, jcode.getPC()) :: lv.ranges
}
for (val lv <- b.varsInScope) {
- lv.ranges = {labels(b).getAnchor(), jcode.getPC()} :: lv.ranges
+ lv.ranges = Pair(labels(b).getAnchor(), jcode.getPC()) :: lv.ranges
}
}
@@ -1101,67 +1101,67 @@ abstract class GenJVM extends SubComponent {
abort("Unknown arithmetic primitive " + primitive)
}
- case Logical(op, kind) => {op, kind} match {
- case {AND, LONG} =>
+ case Logical(op, kind) => Pair(op, kind) match {
+ case Pair(AND, LONG) =>
jcode.emitLAND()
- case {AND, INT} =>
+ case Pair(AND, INT) =>
jcode.emitIAND()
- case {AND, _} =>
+ case Pair(AND, _) =>
jcode.emitIAND()
if (kind != BOOL)
jcode.emitT2T(javaType(INT), javaType(kind));
- case {OR, LONG} =>
+ case Pair(OR, LONG) =>
jcode.emitLOR()
- case {OR, INT} =>
+ case Pair(OR, INT) =>
jcode.emitIOR()
- case {OR, _} =>
+ case Pair(OR, _) =>
jcode.emitIOR()
if (kind != BOOL)
jcode.emitT2T(javaType(INT), javaType(kind));
- case {XOR, LONG} =>
+ case Pair(XOR, LONG) =>
jcode.emitLXOR()
- case {XOR, INT} =>
+ case Pair(XOR, INT) =>
jcode.emitIXOR()
- case {XOR, _} =>
+ case Pair(XOR, _) =>
jcode.emitIXOR()
if (kind != BOOL)
jcode.emitT2T(javaType(INT), javaType(kind));
}
- case Shift(op, kind) => {op, kind} match {
- case {LSL, LONG} =>
+ case Shift(op, kind) => Pair(op, kind) match {
+ case Pair(LSL, LONG) =>
jcode.emitLSHL()
- case {LSL, INT} =>
+ case Pair(LSL, INT) =>
jcode.emitISHL()
- case {LSL, _} =>
+ case Pair(LSL, _) =>
jcode.emitISHL()
jcode.emitT2T(javaType(INT), javaType(kind))
- case {ASR, LONG} =>
+ case Pair(ASR, LONG) =>
jcode.emitLSHR()
- case {ASR, INT} =>
+ case Pair(ASR, INT) =>
jcode.emitISHR()
- case {ASR, _} =>
+ case Pair(ASR, _) =>
jcode.emitISHR()
jcode.emitT2T(javaType(INT), javaType(kind))
- case {LSR, LONG} =>
+ case Pair(LSR, LONG) =>
jcode.emitLUSHR()
- case {LSR, INT} =>
+ case Pair(LSR, INT) =>
jcode.emitIUSHR()
- case {LSR, _} =>
+ case Pair(LSR, _) =>
jcode.emitIUSHR()
jcode.emitT2T(javaType(INT), javaType(kind))
}
- case Comparison(op, kind) => {op, kind} match {
- case {CMP, LONG} => jcode.emitLCMP()
- case {CMPL, FLOAT} => jcode.emitFCMPL()
- case {CMPG, FLOAT} => jcode.emitFCMPG()
- case {CMPL, DOUBLE} => jcode.emitDCMPL()
- case {CMPG, DOUBLE} => jcode.emitDCMPL()
+ case Comparison(op, kind) => Pair(op, kind) match {
+ case Pair(CMP, LONG) => jcode.emitLCMP()
+ case Pair(CMPL, FLOAT) => jcode.emitFCMPL()
+ case Pair(CMPG, FLOAT) => jcode.emitFCMPG()
+ case Pair(CMPL, DOUBLE) => jcode.emitDCMPL()
+ case Pair(CMPG, DOUBLE) => jcode.emitDCMPL()
}
case Conversion(src, dst) =>
@@ -1449,7 +1449,7 @@ abstract class GenJVM extends SubComponent {
val index = indexOf(lv).asInstanceOf[Short]
val tpe = javaType(lv.kind).getSignature()
- for (val {start, end} <- lv.ranges) {
+ for (val Pair(start, end) <- lv.ranges) {
emitEntry(name, tpe, index, start.asInstanceOf[Short], (end - start).asInstanceOf[Short])
}
}
@@ -1463,10 +1463,10 @@ abstract class GenJVM extends SubComponent {
/** Merge adjacent ranges. */
- private def mergeEntries(ranges: List[{Int, Int}]): List[{Int, Int}] =
- (ranges.foldLeft(Nil: List[{Int, Int}]) { (collapsed: List[{Int, Int}], p: {Int, Int}) => {collapsed, p} match {
- case { Nil, _ } => List(p)
- case { {s1, e1} :: rest, {s2, e2} } if (e1 == s2) => {s1, e2} :: rest
+ private def mergeEntries(ranges: List[Pair[Int, Int]]): List[Pair[Int, Int]] =
+ (ranges.foldLeft(Nil: List[Pair[Int, Int]]) { (collapsed: List[Pair[Int, Int]], p: Pair[Int, Int]) => Pair(collapsed, p) match {
+ case Pair(Nil, _) => List(p)
+ case Pair(Pair(s1, e1) :: rest, Pair(s2, e2)) if (e1 == s2) => Pair(s1, e2) :: rest
case _ => p :: collapsed
}}).reverse
diff --git a/src/compiler/scala/tools/nsc/backend/msil/GenMSIL.scala b/src/compiler/scala/tools/nsc/backend/msil/GenMSIL.scala
index 2d16388b37..3623d125ea 100644
--- a/src/compiler/scala/tools/nsc/backend/msil/GenMSIL.scala
+++ b/src/compiler/scala/tools/nsc/backend/msil/GenMSIL.scala
@@ -889,7 +889,7 @@ abstract class GenMSIL extends SubComponent {
def leavingBlocks(blocks: List[BasicBlock]): List[Pair[BasicBlock, List[BasicBlock]]] = {
for {val b <- blocks
val t = outsideTargets(b, blocks)
- t.length != 0 } yield {b, t}
+ t.length != 0 } yield Pair(b, t)
}
def replaceOutJumps(blocks: List[BasicBlock], leaving: List[Pair[BasicBlock, List[BasicBlock]]], exh: ExceptionHandler):Pair[List[BasicBlock], Option[BasicBlock]] = {
@@ -926,12 +926,12 @@ abstract class GenMSIL extends SubComponent {
val target = p._2(0) // the elemets of p._2 are all the same, checked before
replaceJump(lBlock, target, jumpOutBlock)
})
- {blocks ::: List(jumpOutBlock), Some(jumpOutBlock)}
+ Pair(blocks ::: List(jumpOutBlock), Some(jumpOutBlock))
}
val leaving = leavingBlocks(blocks)
if (leaving.length == 0)
- {blocks, None}
+ Pair(blocks, None)
else if (leaving.length == 1) {
val outside = leaving(0)._2
assert(outside.forall(b => b == outside(0)), "exception-block leaving to multiple targets")
@@ -940,7 +940,7 @@ abstract class GenMSIL extends SubComponent {
else
assert(firstBlockAfter(exh) == outside(0), "try/catch leaving to multiple targets: " + firstBlockAfter(exh) + ", new: " + outside(0))
val last = leaving(0)._1
- {blocks.diff(List(last)) ::: List(last), None}
+ Pair(blocks.diff(List(last)) ::: List(last), None)
} else {
val outside = leaving.flatMap(p => p._2)
assert(outside.forall(b => b == outside(0)), "exception-block leaving to multiple targets")
@@ -968,7 +968,7 @@ abstract class GenMSIL extends SubComponent {
var singleAffectedHandler: ExceptionHandler = affectedHandlers(0) // List[ExceptionHandler] = Nil
var exceptionBlock: Option[ExceptionBlock] = None
affectedHandlers.foreach(h1 => {
- val {adaptedBlocks, newBlock} = adaptBlocks(blocksToPut.intersect(h1.blocks), singleAffectedHandler)
+ val Pair(adaptedBlocks, newBlock) = adaptBlocks(blocksToPut.intersect(h1.blocks), singleAffectedHandler)
newBlock match {
case Some(block) =>
blocksToPut = blocksToPut ::: List(block)
@@ -986,7 +986,7 @@ abstract class GenMSIL extends SubComponent {
val excBlock = currentBlock.addExceptionBlock(singleAffectedHandler)
exceptionBlock = Some(excBlock)
- val {tryBlocks, newBlock} = adaptBlocks(blocksToPut.intersect(singleAffectedHandler.covered), singleAffectedHandler)
+ val Pair(tryBlocks, newBlock) = adaptBlocks(blocksToPut.intersect(singleAffectedHandler.covered), singleAffectedHandler)
newBlock match {
case Some(block) =>
@@ -998,7 +998,7 @@ abstract class GenMSIL extends SubComponent {
addBlocks(tryBlocks)
if (singleAffectedHandler.finalizer != null && singleAffectedHandler.finalizer != NoFinalizer) {
- val {blocks0, newBlock} = adaptBlocks(blocksToPut.intersect(singleAffectedHandler.finalizer.blocks), singleAffectedHandler)
+ val Pair(blocks0, newBlock) = adaptBlocks(blocksToPut.intersect(singleAffectedHandler.finalizer.blocks), singleAffectedHandler)
newBlock match {
case Some(block) =>
blocksToPut = blocksToPut ::: List(block)
@@ -1379,13 +1379,13 @@ abstract class GenMSIL extends SubComponent {
}
// method: implicit view(FunctionX[PType0, PType1, ...,PTypeN, ResType]):DelegateType
- val {isDelegateView, paramType, resType} = atPhase(currentRun.typerPhase){
+ val Triple(isDelegateView, paramType, resType) = atPhase(currentRun.typerPhase){
msym.tpe match {
case MethodType(parameterTypes, resultType)
if (parameterTypes.length == 1 && msym.name == nme.view_) =>
val isDel = definitions.isCorrespondingDelegate(resultType, parameterTypes(0))
- {isDel, parameterTypes(0), resultType}
- case _ => {false, null, null}
+ Triple(isDel, parameterTypes(0), resultType)
+ case _ => Triple(false, null, null)
}
}
if (doEmit && isDelegateView) {
@@ -2206,8 +2206,8 @@ abstract class GenMSIL extends SubComponent {
// create the static caller method and the delegate object
- val {paramTypes, returnType} = delegateType.member(nme.apply).tpe match {
- case MethodType(delParams, delReturn) => {delParams, delReturn}
+ val Pair(paramTypes, returnType) = delegateType.member(nme.apply).tpe match {
+ case MethodType(delParams, delReturn) => Pair(delParams, delReturn)
case _ => abort("not a delegate type: " + delegateType)
}
val caller: MethodBuilder = delegateCallers.DefineMethod(
diff --git a/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala b/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala
index c66c3e1ff8..75ab5623fd 100644
--- a/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala
+++ b/src/compiler/scala/tools/nsc/matching/PatternMatchers.scala
@@ -1044,7 +1044,7 @@ print()
//Console.println("sel:"+selector+" last"+lastSelector+" - "+(selector == lastSelector))
val next = _h.next;
//res = And(mkNegate(res), toTree(node.or, selector));
- val {doOptimize, coveredCases, remainingCases} = _h.optimize1()
+ val Triple(doOptimize, coveredCases, remainingCases) = _h.optimize1()
if(!remainingCases.isEmpty && doCheckExhaustive) {
carryCovered = carryCovered ++ coveredCases // ??
if(next != null && next.or.and.isUnguardedBody) {
@@ -1301,7 +1301,7 @@ print()
true
case _ =>
if(settings.XprintOuterMatches.value)
- cunit.warning(node.pos, "can't be sure statically that these outers are equal:"+{left,right}.toString)
+ cunit.warning(node.pos, "can't be sure statically that these outers are equal:"+Pair(left,right).toString)
false
}
diff --git a/src/compiler/scala/tools/nsc/matching/PatternNodes.scala b/src/compiler/scala/tools/nsc/matching/PatternNodes.scala
index cd0d5da3d8..b436dccefb 100644
--- a/src/compiler/scala/tools/nsc/matching/PatternNodes.scala
+++ b/src/compiler/scala/tools/nsc/matching/PatternNodes.scala
@@ -327,16 +327,16 @@ trait PatternNodes requires transform.ExplicitOuter {
/** returns true if this tree is optimizable
* throws a warning if is not exhaustive
*/
- def optimize1(): { Boolean, SymSet, SymSet } = {
+ def optimize1(): Triple[Boolean, SymSet, SymSet] = {
import symtab.Flags
val selType = this.getTpe
if (!isSubType(selType, definitions.ScalaObjectClass.tpe))
- return {false, null, emptySymbolSet};
+ return Triple(false, null, emptySymbolSet)
if(this.or eq null)
- return {false, null, emptySymbolSet} // only case _
+ return Triple(false, null, emptySymbolSet) // only case _
def checkExCoverage(tpesym:Symbol): SymSet =
if(!tpesym.hasFlag(Flags.SEALED)) emptySymbolSet
@@ -409,7 +409,7 @@ trait PatternNodes requires transform.ExplicitOuter {
}
this.forEachBranch(traverse)
- return {res && (cases > 2), coveredCases, remainingCases};
+ return Triple(res && (cases > 2), coveredCases, remainingCases)
} // def optimize
}
diff --git a/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala b/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala
index 178c6155fa..8fe03975f3 100644
--- a/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala
+++ b/src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala
@@ -174,7 +174,7 @@ abstract class SymbolLoaders {
}
// do classes first
- for (val {name, file} <- classes.elements) {
+ for (val Pair(name, file) <- classes.elements) {
val loader = if (!file.isSourceFile) {
new ClassfileLoader(file.classFile, file.sourceFile, file.sourcePath)
} else {
@@ -184,7 +184,7 @@ abstract class SymbolLoaders {
enterClassAndModule(name, loader)
}
- for (val {name, file} <- packages.elements)
+ for (val Pair(name, file) <- packages.elements)
enterPackage(name, newPackageLoader(file))
}
}
diff --git a/src/compiler/scala/tools/nsc/symtab/Symbols.scala b/src/compiler/scala/tools/nsc/symtab/Symbols.scala
index fad85cfc4a..2db48eaa41 100644
--- a/src/compiler/scala/tools/nsc/symtab/Symbols.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Symbols.scala
@@ -1306,7 +1306,7 @@ trait Symbols requires SymbolTable {
def cloneSymbolImpl(owner: Symbol): Symbol = throw new Error()
}
- case class AttrInfo(atp: Type, args: List[Constant], assocs: List[{Name, Constant}]) {
+ case class AttrInfo(atp: Type, args: List[Constant], assocs: List[Pair[Name, Constant]]) {
override def toString: String =
atp +
(if (args.isEmpty) "" else args.mkString("(", ", ", ")")) +
diff --git a/src/compiler/scala/tools/nsc/symtab/Types.scala b/src/compiler/scala/tools/nsc/symtab/Types.scala
index 348f9c2f77..27bc11ff67 100644
--- a/src/compiler/scala/tools/nsc/symtab/Types.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Types.scala
@@ -918,7 +918,7 @@ trait Types requires SymbolTable {
def apply(tp: Type): Type = {
tp match {
case TypeRef(_, sym, args) =>
- for (val {tparam1, arg} <- sym.info.typeParams zip args)
+ for (val Pair(tparam1, arg) <- sym.info.typeParams zip args)
if (arg contains tparam) {
addRef(NonExpansive, tparam, tparam1)
if (arg.symbol != tparam) addRef(Expansive, tparam, tparam1)
@@ -943,7 +943,7 @@ trait Types requires SymbolTable {
val lastRefs = Array(refs(0), refs(1))
state = Initialized
var change = false
- for (val {from, targets} <- refs(NonExpansive).elements)
+ for (val Pair(from, targets) <- refs(NonExpansive).elements)
for (val target <- targets) {
var thatInfo = classInfo(target)
if (thatInfo.state != Initialized)
@@ -951,7 +951,7 @@ trait Types requires SymbolTable {
addRefs(NonExpansive, from, thatInfo.getRefs(NonExpansive, target))
addRefs(Expansive, from, thatInfo.getRefs(Expansive, target))
}
- for (val {from, targets} <- refs(Expansive).elements)
+ for (val Pair(from, targets) <- refs(Expansive).elements)
for (val target <- targets) {
var thatInfo = classInfo(target)
addRefs(Expansive, from, thatInfo.getRefs(NonExpansive, target))
@@ -2012,40 +2012,40 @@ trait Types requires SymbolTable {
* equivalent types.
*/
def isSameType(tp1: Type, tp2: Type): boolean = {
- {tp1, tp2} match {
- case {ErrorType, _} => true
- case {WildcardType, _} => true
- case {_, ErrorType} => true
- case {_, WildcardType} => true
-
- case {NoType, _} => false
- case {NoPrefix, _} => tp2.symbol.isPackageClass
- case {_, NoType} => false
- case {_, NoPrefix} => tp1.symbol.isPackageClass
-
- case {ThisType(sym1), ThisType(sym2)}
+ Pair(tp1, tp2) match {
+ case Pair(ErrorType, _) => true
+ case Pair(WildcardType, _) => true
+ case Pair(_, ErrorType) => true
+ case Pair(_, WildcardType) => true
+
+ case Pair(NoType, _) => false
+ case Pair(NoPrefix, _) => tp2.symbol.isPackageClass
+ case Pair(_, NoType) => false
+ case Pair(_, NoPrefix) => tp1.symbol.isPackageClass
+
+ case Pair(ThisType(sym1), ThisType(sym2))
if (sym1 == sym2) =>
true
- case {SingleType(pre1, sym1), SingleType(pre2, sym2)}
+ case Pair(SingleType(pre1, sym1), SingleType(pre2, sym2))
if ((sym1 == sym2) && (pre1 =:= pre2)) =>
true
/*
- case {SingleType(pre1, sym1), ThisType(sym2)}
+ case Pair(SingleType(pre1, sym1), ThisType(sym2))
if (sym1.isModule &&
sym1.moduleClass == sym2 &&
pre1 =:= sym2.owner.thisType) =>
true
- case {ThisType(sym1), SingleType(pre2, sym2)}
+ case Pair(ThisType(sym1), SingleType(pre2, sym2))
if (sym2.isModule &&
sym2.moduleClass == sym1 &&
pre2 =:= sym1.owner.thisType) =>
true
*/
- case {ConstantType(value1), ConstantType(value2)} =>
+ case Pair(ConstantType(value1), ConstantType(value2)) =>
value1 == value2
- case {TypeRef(pre1, sym1, args1), TypeRef(pre2, sym2, args2)} =>
+ case Pair(TypeRef(pre1, sym1, args1), TypeRef(pre2, sym2, args2)) =>
sym1 == sym2 && (phase.erasedTypes || pre1 =:= pre2) && isSameTypes(args1, args2)
- case {RefinedType(parents1, ref1), RefinedType(parents2, ref2)} =>
+ case Pair(RefinedType(parents1, ref1), RefinedType(parents2, ref2)) =>
def isSubScope(s1: Scope, s2: Scope): boolean = s2.toList.forall {
sym2 =>
val sym1 = s1.lookup(sym2.name)
@@ -2054,31 +2054,31 @@ trait Types requires SymbolTable {
}
//Console.println("is same? " + tp1 + " " + tp2 + " " + tp1.symbol.owner + " " + tp2.symbol.owner)//DEBUG
isSameTypes(parents1, parents2) && isSubScope(ref1, ref2) && isSubScope(ref2, ref1)
- case {MethodType(pts1, res1), MethodType(pts2, res2)} =>
+ case Pair(MethodType(pts1, res1), MethodType(pts2, res2)) =>
(pts1.length == pts2.length &&
isSameTypes(pts1, pts2) &&
res1 =:= res2 &&
tp1.isInstanceOf[ImplicitMethodType] == tp2.isInstanceOf[ImplicitMethodType])
- case {PolyType(tparams1, res1), PolyType(tparams2, res2)} =>
+ case Pair(PolyType(tparams1, res1), PolyType(tparams2, res2)) =>
(tparams1.length == tparams2.length &&
List.forall2(tparams1, tparams2)
((p1, p2) => p1.info =:= p2.info.substSym(tparams2, tparams1)) &&
res1 =:= res2.substSym(tparams2, tparams1))
- case {TypeBounds(lo1, hi1), TypeBounds(lo2, hi2)} =>
+ case Pair(TypeBounds(lo1, hi1), TypeBounds(lo2, hi2)) =>
lo1 =:= lo2 && hi1 =:= hi2
- case {BoundedWildcardType(bounds), _} =>
+ case Pair(BoundedWildcardType(bounds), _) =>
bounds containsType tp2
- case {_, BoundedWildcardType(bounds)} =>
+ case Pair(_, BoundedWildcardType(bounds)) =>
bounds containsType tp1
- case {TypeVar(_, constr1), _} =>
+ case Pair(TypeVar(_, constr1), _) =>
if (constr1.inst != NoType) constr1.inst =:= tp2
else constr1 instantiate (wildcardToTypeVarMap(tp2))
- case {_, TypeVar(_, constr2)} =>
+ case Pair(_, TypeVar(_, constr2)) =>
if (constr2.inst != NoType) tp1 =:= constr2.inst
else constr2 instantiate (wildcardToTypeVarMap(tp1))
- case {AttributedType(_,atp), _} =>
+ case Pair(AttributedType(_,atp), _) =>
isSameType(atp, tp2)
- case {_, AttributedType(_,atp)} =>
+ case Pair(_, AttributedType(_,atp)) =>
isSameType(tp1, atp)
case _ =>
if (tp1.isStable && tp2.isStable) {
@@ -2127,24 +2127,24 @@ trait Types requires SymbolTable {
* @return ...
*/
def isSubType0(tp1: Type, tp2: Type): boolean = {
- {tp1, tp2} match {
- case {ErrorType, _} => true
- case {WildcardType, _} => true
- case {_, ErrorType} => true
- case {_, WildcardType} => true
-
- case {NoType, _} => false
- case {NoPrefix, _} => tp2.symbol.isPackageClass
- case {_, NoType} => false
- case {_, NoPrefix} => tp1.symbol.isPackageClass
-
- case {ThisType(_), ThisType(_)} => tp1 =:= tp2
- case {ThisType(_), SingleType(_, _)} => tp1 =:= tp2
- case {SingleType(_, _), ThisType(_)} => tp1 =:= tp2
- case {SingleType(_, _), SingleType(_, _)} => tp1 =:= tp2
- case {ConstantType(_), ConstantType(_)} => tp1 =:= tp2
-
- case {TypeRef(pre1, sym1, args1), TypeRef(pre2, sym2, args2)} =>
+ Pair(tp1, tp2) match {
+ case Pair(ErrorType, _) => true
+ case Pair(WildcardType, _) => true
+ case Pair(_, ErrorType) => true
+ case Pair(_, WildcardType) => true
+
+ case Pair(NoType, _) => false
+ case Pair(NoPrefix, _) => tp2.symbol.isPackageClass
+ case Pair(_, NoType) => false
+ case Pair(_, NoPrefix) => tp1.symbol.isPackageClass
+
+ case Pair(ThisType(_), ThisType(_)) => tp1 =:= tp2
+ case Pair(ThisType(_), SingleType(_, _)) => tp1 =:= tp2
+ case Pair(SingleType(_, _), ThisType(_)) => tp1 =:= tp2
+ case Pair(SingleType(_, _), SingleType(_, _)) => tp1 =:= tp2
+ case Pair(ConstantType(_), ConstantType(_)) => tp1 =:= tp2
+
+ case Pair(TypeRef(pre1, sym1, args1), TypeRef(pre2, sym2, args2)) =>
//Console.println("isSubType " + tp1 + " " + tp2);//DEBUG
def isSubArgs(tps1: List[Type], tps2: List[Type],
tparams: List[Symbol]): boolean = (
@@ -2172,50 +2172,50 @@ trait Types requires SymbolTable {
||
// Console.println("last chance " + sym1 + " " + sym2 + " " + sym2.isClass + " " (sym2 isSubClass ObjectClass))
sym1 == AllRefClass && sym2.isClass && sym2 != AllClass && (sym2 isSubClass ObjectClass))
- case {MethodType(pts1, res1), MethodType(pts2, res2)} =>
+ case Pair(MethodType(pts1, res1), MethodType(pts2, res2)) =>
(pts1.length == pts2.length &&
matchingParams(pts1, pts2, tp2.isInstanceOf[JavaMethodType]) &&
(res1 <:< res2) &&
tp1.isInstanceOf[ImplicitMethodType] == tp2.isInstanceOf[ImplicitMethodType])
- case {PolyType(tparams1, res1), PolyType(tparams2, res2)} =>
+ case Pair(PolyType(tparams1, res1), PolyType(tparams2, res2)) =>
(tparams1.length == tparams2.length &&
List.forall2(tparams1, tparams2)
((p1, p2) => p2.info.substSym(tparams2, tparams1) <:< p1.info) &&
res1 <:< res2.substSym(tparams2, tparams1))
- case {TypeBounds(lo1, hi1), TypeBounds(lo2, hi2)} =>
+ case Pair(TypeBounds(lo1, hi1), TypeBounds(lo2, hi2)) =>
lo2 <:< lo1 && hi1 <:< hi2
- case {BoundedWildcardType(bounds), _} =>
+ case Pair(BoundedWildcardType(bounds), _) =>
bounds.lo <:< tp2
- case {_, BoundedWildcardType(bounds)} =>
+ case Pair(_, BoundedWildcardType(bounds)) =>
tp1 <:< bounds.hi
- case {_, TypeVar(_, constr2)} =>
+ case Pair(_, TypeVar(_, constr2)) =>
if (constr2.inst != NoType) tp1 <:< constr2.inst
else { constr2.lobounds = tp1 :: constr2.lobounds; true }
- case {TypeVar(_, constr1), _} =>
+ case Pair(TypeVar(_, constr1), _) =>
if (constr1.inst != NoType) constr1.inst <:< tp2
else { constr1.hibounds = tp2 :: constr1.hibounds; true }
- case {AttributedType(_,atp1), _} =>
+ case Pair(AttributedType(_,atp1), _) =>
atp1 <:< tp2
- case {_, AttributedType(_,atp2)} =>
+ case Pair(_, AttributedType(_,atp2)) =>
tp1 <:< atp2
- case {_, TypeRef(pre2, sym2, args2)}
+ case Pair(_, TypeRef(pre2, sym2, args2))
if sym2.isAbstractType && !(tp2 =:= tp2.bounds.lo) && (tp1 <:< tp2.bounds.lo) =>
true
- case {_, RefinedType(parents2, ref2)} =>
+ case Pair(_, RefinedType(parents2, ref2)) =>
(parents2 forall tp1.<:<) && (ref2.toList forall tp1.specializes) &&
(!parents2.exists(.symbol.isAbstractType) || tp1.symbol != AllRefClass)
- case {RefinedType(parents1, ref1), _} =>
+ case Pair(RefinedType(parents1, ref1), _) =>
parents1 exists (.<:<(tp2))
/* todo: replace following with
- case {ThisType(_), _}
+ case Pair(ThisType(_), _)
| {SingleType(_, _), _}
| {ConstantType(_), _} =>
once patern matching bug is fixed */
- case {ThisType(_), _} => tp1.singleDeref <:< tp2
- case {SingleType(_, _), _} => tp1.singleDeref <:< tp2
- case {ConstantType(_), _} => tp1.singleDeref <:< tp2
+ case Pair(ThisType(_), _) => tp1.singleDeref <:< tp2
+ case Pair(SingleType(_, _), _) => tp1.singleDeref <:< tp2
+ case Pair(ConstantType(_), _) => tp1.singleDeref <:< tp2
- case {TypeRef(pre1, sym1, args1), _} =>
+ case Pair(TypeRef(pre1, sym1, args1), _) =>
(sym1 == AllClass && tp2 <:< AnyClass.tpe
||
sym1 == AllRefClass && tp2.isInstanceOf[SingletonType] && (tp1 <:< tp2.widen))
@@ -2260,21 +2260,21 @@ trait Types requires SymbolTable {
}
/** A function implementing <code>tp1</code> matches <code>tp2</code> */
- private def matchesType(tp1: Type, tp2: Type): boolean = {tp1, tp2} match {
- case {MethodType(pts1, res1), MethodType(pts2, res2)} =>
+ private def matchesType(tp1: Type, tp2: Type): boolean = Pair(tp1, tp2) match {
+ case Pair(MethodType(pts1, res1), MethodType(pts2, res2)) =>
(matchingParams(pts1, pts2, tp2.isInstanceOf[JavaMethodType]) && (res1 matches res2) &&
tp1.isInstanceOf[ImplicitMethodType] == tp2.isInstanceOf[ImplicitMethodType])
- case {PolyType(tparams1, res1), PolyType(tparams2, res2)} =>
+ case Pair(PolyType(tparams1, res1), PolyType(tparams2, res2)) =>
(tparams1.length == tparams2.length &&
(res1 matches res2.substSym(tparams2, tparams1)))
- case {PolyType(List(), rtp1), MethodType(List(), rtp2)} => matchesType(rtp1, rtp2)
- case {MethodType(List(), rtp1), PolyType(List(), rtp2)} => matchesType(rtp1, rtp2)
- case {PolyType(List(), rtp1), _} => matchesType(rtp1, tp2)
- case {_, PolyType(List(), rtp2)} => matchesType(tp1, rtp2)
- case {MethodType(_, _), _} => false
- case {PolyType(_, _), _} => false
- case {_, MethodType(_, _)} => false
- case {_, PolyType(_, _)} => false
+ case Pair(PolyType(List(), rtp1), MethodType(List(), rtp2)) => matchesType(rtp1, rtp2)
+ case Pair(MethodType(List(), rtp1), PolyType(List(), rtp2)) => matchesType(rtp1, rtp2)
+ case Pair(PolyType(List(), rtp1), _) => matchesType(rtp1, tp2)
+ case Pair(_, PolyType(List(), rtp2)) => matchesType(tp1, rtp2)
+ case Pair(MethodType(_, _), _) => false
+ case Pair(PolyType(_, _), _) => false
+ case Pair(_, MethodType(_, _)) => false
+ case Pair(_, PolyType(_, _)) => false
case _ =>
!phase.erasedTypes || tp1 =:= tp2
}
diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala
index 8c0833e3bf..cf53db37a2 100644
--- a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala
+++ b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala
@@ -193,7 +193,7 @@ abstract class ClassfileParser {
in.buf(start) != CONSTANT_METHODREF &&
in.buf(start) != CONSTANT_INTFMETHODREF) errorBadTag(start)
val ownerTpe = getClassOrArrayType(in.getChar(start + 1))
- val {name, tpe} = getNameAndType(in.getChar(start + 3), ownerTpe)
+ val Pair(name, tpe) = getNameAndType(in.getChar(start + 3), ownerTpe)
if (name == nme.MODULE_INSTANCE_FIELD) {
val index = in.getChar(start + 1)
val name = getExternalName(in.getChar(starts(index) + 1))
@@ -232,7 +232,7 @@ abstract class ClassfileParser {
tpe = MethodType(formals, ownerTpe)
}
- p = {name, tpe}
+ p = Pair(name, tpe)
}
p
}
@@ -700,7 +700,7 @@ abstract class ClassfileParser {
val nvpairs = new ListBuffer[Pair[Name,Constant]]
for (val i <- 0 until nargs) {
val name = pool.getName(in.nextChar)
- nvpairs += {name, parseTaggedConstant()}
+ nvpairs += Pair(name, parseTaggedConstant())
}
sym.attributes = AttrInfo(attrType, List(), nvpairs.toList) :: sym.attributes
}
diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala b/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala
index 68c504eb30..ebe7c6d763 100644
--- a/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala
+++ b/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala
@@ -169,15 +169,15 @@ abstract class Pickler extends SubComponent {
}
private def putChildren(sym: Symbol, children: Set[Symbol]): unit = {
- assert(putEntry{sym, children})
+ assert(putEntry(Pair(sym, children)))
children foreach putSymbol
}
private def putAnnotation(sym: Symbol, attr: AttrInfo): unit = {
- assert(putEntry{sym, attr})
+ assert(putEntry(Pair(sym, attr)))
putType(attr.atp)
for (val c <- attr.args) putConstant(c)
- for (val {name, c} <- attr.assocs) { putEntry(name); putConstant(c) }
+ for (val Pair(name, c) <- attr.assocs) { putEntry(name); putConstant(c) }
}
// Phase 2 methods: Write all entries to byte array ------------------------------
@@ -279,13 +279,13 @@ abstract class Pickler extends SubComponent {
LITERAL + c.tag
case AttributedType(attribs, tp) =>
writeBody(tp) // obviously, this should be improved
- case {target: Symbol, attr @ AttrInfo(atp, args, assocs)} =>
+ case Pair(target: Symbol, attr @ AttrInfo(atp, args, assocs)) =>
writeRef(target)
writeRef(atp)
for (val c <- args) writeRef(c)
- for (val {name, c} <- assocs) { writeRef(name); writeRef(c) }
+ for (val Pair(name, c) <- assocs) { writeRef(name); writeRef(c) }
ATTRIBUTE
- case {target: Symbol, children: Set[_]} =>
+ case Pair(target: Symbol, children: Set[_]) =>
writeRef(target)
for (val c <- children) writeRef(c.asInstanceOf[Symbol])
CHILDREN
diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/UnPickler.scala b/src/compiler/scala/tools/nsc/symtab/classfile/UnPickler.scala
index e28ed90b69..ac1d10e9be 100644
--- a/src/compiler/scala/tools/nsc/symtab/classfile/UnPickler.scala
+++ b/src/compiler/scala/tools/nsc/symtab/classfile/UnPickler.scala
@@ -288,10 +288,10 @@ abstract class UnPickler {
if (tag == ATTRIBUTE) {
val attrType = readTypeRef()
val args = new ListBuffer[Constant]
- val assocs = new ListBuffer[{Name, Constant}]
+ val assocs = new ListBuffer[Pair[Name, Constant]]
while (readIndex != end) {
val argref = readNat()
- if (isNameEntry(argref)) assocs += {at(argref, readName), readConstantRef()}
+ if (isNameEntry(argref)) assocs += Pair(at(argref, readName), readConstantRef())
else args += at(argref, readConstant)
}
val attr = AttrInfo(attrType, args.toList, assocs.toList)
diff --git a/src/compiler/scala/tools/nsc/typechecker/ConstantFolder.scala b/src/compiler/scala/tools/nsc/typechecker/ConstantFolder.scala
index 1610d237e0..7323b17fa3 100644
--- a/src/compiler/scala/tools/nsc/typechecker/ConstantFolder.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/ConstantFolder.scala
@@ -49,21 +49,21 @@ abstract class ConstantFolder {
// compiler itself crashing
}
- private def foldUnop(op: Name, x: Constant): Constant = {op, x.tag} match {
- case {nme.ZNOT, BooleanTag} => Constant(!x.booleanValue)
+ private def foldUnop(op: Name, x: Constant): Constant = Pair(op, x.tag) match {
+ case Pair(nme.ZNOT, BooleanTag) => Constant(!x.booleanValue)
- case {nme.NOT , IntTag } => Constant(~x.intValue)
- case {nme.NOT , LongTag } => Constant(~x.longValue)
+ case Pair(nme.NOT , IntTag ) => Constant(~x.intValue)
+ case Pair(nme.NOT , LongTag ) => Constant(~x.longValue)
- case {nme.ADD , IntTag } => Constant(+x.intValue)
- case {nme.ADD , LongTag } => Constant(+x.longValue)
- case {nme.ADD , FloatTag } => Constant(+x.floatValue)
- case {nme.ADD , DoubleTag } => Constant(+x.doubleValue)
+ case Pair(nme.ADD , IntTag ) => Constant(+x.intValue)
+ case Pair(nme.ADD , LongTag ) => Constant(+x.longValue)
+ case Pair(nme.ADD , FloatTag ) => Constant(+x.floatValue)
+ case Pair(nme.ADD , DoubleTag ) => Constant(+x.doubleValue)
- case {nme.SUB , IntTag } => Constant(-x.intValue)
- case {nme.SUB , LongTag } => Constant(-x.longValue)
- case {nme.SUB , FloatTag } => Constant(-x.floatValue)
- case {nme.SUB , DoubleTag } => Constant(-x.doubleValue)
+ case Pair(nme.SUB , IntTag ) => Constant(-x.intValue)
+ case Pair(nme.SUB , LongTag ) => Constant(-x.longValue)
+ case Pair(nme.SUB , FloatTag ) => Constant(-x.floatValue)
+ case Pair(nme.SUB , DoubleTag ) => Constant(-x.doubleValue)
case _ => null
}
diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
index 72f8d8540e..0fb3d02cc5 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
@@ -41,7 +41,7 @@ trait Contexts requires Analyzer {
assert(pkg ne null)
val qual = gen.mkAttributedStableRef(pkg)
sc = sc.makeNewImport(
- Import(qual, List({nme.WILDCARD, null}))
+ Import(qual, List(Pair(nme.WILDCARD, null)))
.setSymbol(NoSymbol.newImport(NoPos).setFlag(SYNTHETIC).setInfo(ImportType(qual)))
.setType(NoType))
sc.depth = sc.depth + 1
@@ -364,12 +364,12 @@ trait Contexts requires Analyzer {
}
def pushTypeBounds(sym: Symbol): unit = {
- savedTypeBounds = {sym, sym.info} :: savedTypeBounds
+ savedTypeBounds = Pair(sym, sym.info) :: savedTypeBounds
}
def restoreTypeBounds(tp: Type): Type = {
var current = tp
- for (val {sym, info} <- savedTypeBounds) {
+ for (val Pair(sym, info) <- savedTypeBounds) {
if (settings.debug.value) log("resetting " + sym + " to " + info);
sym.info match {
case TypeBounds(lo, hi) if (hi <:< lo && lo <:< hi) =>
@@ -393,8 +393,8 @@ trait Contexts requires Analyzer {
val pre = imp.qual.tpe
def collect(sels: List[Pair[Name, Name]]): List[ImplicitInfo] = sels match {
case List() => List()
- case List{nme.WILDCARD, _} => collectImplicits(pre.implicitMembers, pre)
- case {from, to} :: sels1 =>
+ case List(Pair(nme.WILDCARD, _)) => collectImplicits(pre.implicitMembers, pre)
+ case Pair(from, to) :: sels1 =>
var impls = collect(sels1) filter (info => info.name != from)
if (to != nme.WILDCARD) {
val sym = imp.importedSymbol(to)
diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala
index 3e63401356..91ff898450 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala
@@ -50,6 +50,14 @@ trait Infer requires Analyzer {
} else formals1
}
+ def actualTypes(actuals: List[Type], nformals: int): List[Type] =
+ if (nformals == 1 && actuals.length != 1)
+ List(if (actuals.length == 0) UnitClass.tpe else tupleType(actuals))
+ else actuals
+
+ def actualArgs(pos: PositionType, actuals: List[Tree], nformals: int): List[Tree] =
+ if (nformals == 1 && actuals.length != 1) List(gen.mkTuple(actuals) setPos pos) else actuals
+
/** A fresh type varable with given type parameter as origin.
*
* @param tparam ...
@@ -134,7 +142,7 @@ trait Infer requires Analyzer {
val bound: Type = if (up) tparam.info.bounds.hi else tparam.info.bounds.lo
//Console.println("solveOne0 "+tvar+" "+config+" "+bound);//DEBUG
var cyclic = false
- for (val {tvar2, {tparam2, variance2}} <- config) {
+ for (val Pair(tvar2, Pair(tparam2, variance2)) <- config) {
if (tparam2 != tparam &&
((bound contains tparam2) ||
up && (tparam2.info.bounds.lo =:= tparam.tpe) ||
@@ -170,7 +178,7 @@ trait Infer requires Analyzer {
assertNonCyclic(tvar)//debug
}
}
- for (val {tvar, {tparam, variance}} <- config)
+ for (val Pair(tvar, Pair(tparam, variance)) <- config)
solveOne(tvar, tparam, variance)
tvars map instantiate
}
@@ -227,11 +235,11 @@ trait Infer requires Analyzer {
"expression of type " + tree.tpe
else if (tree.symbol.hasFlag(OVERLOADED))
"overloaded method " + tree.symbol + " with alternatives " + tree.tpe
- else (
+ else
tree.symbol.toString() +
(if (tree.tpe.paramSectionCount > 0) ": " else " of type ") +
- tree.tpe
- )
+ tree.tpe +
+ (if (tree.symbol.name == nme.apply) tree.symbol.locationString else "")
def applyErrorMsg(tree: Tree, msg: String, argtpes: List[Type], pt: Type) = (
treeSymTypeMsg(tree) + msg + argtpes.mkString("(", ",", ")") +
@@ -295,13 +303,13 @@ trait Infer requires Analyzer {
explainName(sym1)
explainName(sym2)
if (sym1.owner == sym2.owner) sym2.name = newTypeName("(some other)"+sym2.name)
- {sym1, sym2, name}
+ Triple(sym1, sym2, name)
}
}
val result = op
- for (val {sym1, sym2, name} <- patches) {
+ for (val Triple(sym1, sym2, name) <- patches) {
sym1.name = name
sym2.name = name
}
@@ -519,10 +527,11 @@ trait Infer requires Analyzer {
* @return ...
*/
def isApplicable(undetparams: List[Symbol], ftpe: Type,
- argtpes: List[Type], pt: Type): boolean =
+ argtpes0: List[Type], pt: Type): boolean =
ftpe match {
case MethodType(formals0, restpe) =>
- val formals = formalTypes(formals0, argtpes.length)
+ val formals = formalTypes(formals0, argtpes0.length)
+ val argtpes = actualTypes(argtpes0, formals.length)
if (undetparams.isEmpty) {
(formals.length == argtpes.length &&
isCompatible(argtpes, formals) &&
@@ -539,7 +548,7 @@ trait Infer requires Analyzer {
}
case PolyType(tparams, restpe) =>
val tparams1 = cloneSymbols(tparams)
- isApplicable(tparams1 ::: undetparams, restpe.substSym(tparams, tparams1), argtpes, pt)
+ isApplicable(tparams1 ::: undetparams, restpe.substSym(tparams, tparams1), argtpes0, pt)
case ErrorType =>
true
case _ =>
@@ -650,13 +659,12 @@ trait Infer requires Analyzer {
*/
def inferMethodInstance(fn: Tree, undetparams: List[Symbol],
args: List[Tree], pt: Type): List[Symbol] = fn.tpe match {
- case MethodType(formals, restpe) =>
+ case MethodType(formals0, restpe) =>
try {
- val argtpes = args map (.tpe.deconst)
+ val formals = formalTypes(formals0, args.length)
+ val argtpes = actualTypes(args map (.tpe.deconst), formals.length)
val uninstantiated = new ListBuffer[Symbol]
- val targs = methTypeArgs(
- undetparams, formalTypes(formals, argtpes.length),
- restpe, argtpes, pt, uninstantiated)
+ val targs = methTypeArgs(undetparams, formals, restpe, argtpes, pt, uninstantiated)
checkBounds(fn.pos, NoPrefix, NoSymbol, undetparams, targs, "inferred ")
//Console.println("UNAPPLY subst type "+undetparams+" to "+targs+" in "+fn+" ( "+args+ ")")
val treeSubst = new TreeTypeSubstituter(undetparams, targs)
@@ -685,8 +693,8 @@ trait Infer requires Analyzer {
* any correspondiong non-variant type arguments of bt1 and bt2 are the same
*/
def isPopulated(tp1: Type, tp2: Type): boolean = {
- def isConsistent(tp1: Type, tp2: Type): boolean = {tp1, tp2} match {
- case {TypeRef(pre1, sym1, args1), TypeRef(pre2, sym2, args2)} =>
+ def isConsistent(tp1: Type, tp2: Type): boolean = Pair(tp1, tp2) match {
+ case Pair(TypeRef(pre1, sym1, args1), TypeRef(pre2, sym2, args2)) =>
assert(sym1 == sym2)
pre1 =:= pre2 &&
!(List.map3(args1, args2, sym1.typeParams) {
@@ -773,9 +781,9 @@ trait Infer requires Analyzer {
if (settings.debug.value) log("new alias of " + tparam + " = " + tparam.info)
} else {
val instType = toOrigin(tvar.constr.inst)
- val {loBounds, hiBounds} =
- if (instType != NoType && isFullyDefined(instType)) {List(instType), List(instType)}
- else {tvar.constr.lobounds, tvar.constr.hibounds}
+ val Pair(loBounds, hiBounds) =
+ if (instType != NoType && isFullyDefined(instType)) Pair(List(instType), List(instType))
+ else Pair(tvar.constr.lobounds, tvar.constr.hibounds)
val lo = lub(tparam.info.bounds.lo :: loBounds map toOrigin)
val hi = glb(tparam.info.bounds.hi :: hiBounds map toOrigin)
if (!(lo <:< hi)) {
diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala
index 162bc87d43..d7025f3dc1 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala
@@ -219,7 +219,7 @@ trait Namers requires Analyzer {
def skolemize(tparams: List[AbsTypeDef]): unit = {
val tskolems = newTypeSkolems(tparams map (.symbol))
- for (val {tparam, tskolem} <- tparams zip tskolems) tparam.symbol = tskolem
+ for (val Pair(tparam, tskolem) <- tparams zip tskolems) tparam.symbol = tskolem
}
def applicableTypeParams(owner: Symbol): List[Symbol] =
@@ -625,8 +625,8 @@ trait Namers requires Analyzer {
}
true
}
- def checkSelectors(selectors: List[{Name, Name}]): unit = selectors match {
- case {from, to} :: rest =>
+ def checkSelectors(selectors: List[Pair[Name, Name]]): unit = selectors match {
+ case Pair(from, to) :: rest =>
if (from != nme.WILDCARD && base != ErrorType) {
if (base.member(from) == NoSymbol && base.member(from.toTypeName) == NoSymbol)
context.error(tree.pos, from.decode + " is not a member of " + expr);
@@ -687,12 +687,12 @@ trait Namers requires Analyzer {
error(ntree.pos, "duplicate value for element " + name)
} else {
names -= sym
- {sym.name, getConstant(typer.typed(rhs, EXPRmode | CONSTmode, sym.tpe.resultType))}
+ Pair(sym.name, getConstant(typer.typed(rhs, EXPRmode | CONSTmode, sym.tpe.resultType)))
}
}
}
for (val name <- names) {
- if (!name.attributes.contains{AnnotationDefaultAttr.tpe, List(), List()}) {
+ if (!name.attributes.contains(Triple(AnnotationDefaultAttr.tpe, List(), List()))) {
error(t.pos, "attribute " + tpt.tpe.symbol.fullNameString + " is missing element " + name.name)
}
}
@@ -784,8 +784,8 @@ trait Namers requires Analyzer {
else if (isFunctionType(tp) &&
(!isFunctionType(elemtp) || tp.typeArgs.length > elemtp.typeArgs.length))
result = true
- else {tp, elemtp} match {
- case {TypeRef(pre, sym, args), TypeRef(elempre, elemsym, elemargs)} =>
+ else Pair(tp, elemtp) match {
+ case Pair(TypeRef(pre, sym, args), TypeRef(elempre, elemsym, elemargs)) =>
if ((sym == elemsym) && (pre =:= elempre) && (args.length == elemargs.length))
result = List.forall2(elemargs, args) (isContainedIn)
case _ =>
diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
index 0c1df47925..2afb6dd493 100644
--- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
@@ -100,12 +100,12 @@ abstract class RefChecks extends InfoTransform {
else "")))
}
- def overridesType(tp1: Type, tp2: Type): boolean = {tp1, tp2} match {
- case {MethodType(List(), rtp1), PolyType(List(), rtp2)} =>
+ def overridesType(tp1: Type, tp2: Type): boolean = Pair(tp1, tp2) match {
+ case Pair(MethodType(List(), rtp1), PolyType(List(), rtp2)) =>
rtp1 <:< rtp2
- case {PolyType(List(), rtp1), MethodType(List(), rtp2)} =>
+ case Pair(PolyType(List(), rtp1), MethodType(List(), rtp2)) =>
rtp1 <:< rtp2
- case {TypeRef(_, sym, _), _} if (sym.isModuleClass) =>
+ case Pair(TypeRef(_, sym, _), _) if (sym.isModuleClass) =>
overridesType(PolyType(List(), tp1), tp2)
case _ =>
tp1 <:< tp2
@@ -375,7 +375,7 @@ abstract class RefChecks extends InfoTransform {
def validateVarianceArgs(tps: List[Type], variance: int, tparams: List[Symbol]): unit =
(tps zip tparams) foreach {
- case {tp, tparam} => validateVariance(tp, variance * tparam.variance)
+ case Pair(tp, tparam) => validateVariance(tp, variance * tparam.variance)
}
validateVariance(all, variance)
diff --git a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala
index 84eb0cc9bf..51ed171076 100644
--- a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala
@@ -36,7 +36,7 @@ abstract class SuperAccessors extends transform.Transform with transform.TypingT
class SuperAccTransformer(unit: CompilationUnit) extends TypingTransformer(unit) {
private var validCurrentOwner = true
- private var accDefs: List[{Symbol, ListBuffer[Tree]}] = List()
+ private var accDefs: List[Pair[Symbol, ListBuffer[Tree]]] = List()
private def accDefBuf(clazz: Symbol) =
accDefs.dropWhile(._1.!=(clazz)).head._2
@@ -63,7 +63,7 @@ abstract class SuperAccessors extends transform.Transform with transform.TypingT
super.transform(tree)
case Template(parents, body) =>
val ownAccDefs = new ListBuffer[Tree];
- accDefs = {currentOwner, ownAccDefs} :: accDefs;
+ accDefs = Pair(currentOwner, ownAccDefs) :: accDefs;
// ugly hack... normally, the following line should not be
// necessary, the 'super' method taking care of that. but because
diff --git a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala
index f5999b3582..bd534813c2 100644
--- a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala
@@ -81,7 +81,7 @@ trait SyntheticMethods requires Analyzer {
//val retTpe = lub(accs map (.tpe.resultType))
val method = syntheticMethod(nme.element, FINAL, MethodType(List(IntClass.tpe), AnyClass.tpe/*retTpe*/))
typed(DefDef(method, vparamss => Match(Ident(vparamss.head.head), {
- (for(val {sym,i} <- accs.zipWithIndex) yield {
+ (for(val Pair(sym,i) <- accs.zipWithIndex) yield {
CaseDef(Literal(Constant(i)),EmptyTree, Ident(sym))
}):::List(CaseDef(Ident(nme.WILDCARD), EmptyTree,
Throw(New(TypeTree(IndexOutOfBoundsExceptionClass.tpe), List(List(
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index b546d4b8d6..1e645f3baa 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -974,21 +974,21 @@ trait Typers requires Analyzer {
*/
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): {Tree, List[Tree]} = call match {
+ def decompose(call: Tree): Pair[Tree, List[Tree]] = call match {
case Apply(fn, args) =>
- val {superConstr, args1} = decompose(fn)
+ val Pair(superConstr, args1) = decompose(fn)
val formals = fn.tpe.paramTypes
val args2 = if (formals.isEmpty || formals.last.symbol != RepeatedParamClass) args
else args.take(formals.length - 1) ::: List(EmptyTree)
if (args2.length != formals.length)
assert(false, "mismatch " + clazz + " " + formals + " " + args2);//debug
- {superConstr, args1 ::: args2}
+ Pair(superConstr, args1 ::: args2)
case Block(stats, expr) =>
decompose(stats.head)
case _ =>
- {call, List()}
+ Pair(call, List())
}
- val {superConstr, superArgs} = decompose(rhs)
+ val Pair(superConstr, superArgs) = decompose(rhs)
assert(superConstr.symbol ne null)//debug
if (superConstr.symbol.isPrimaryConstructor) {
val superClazz = superConstr.symbol.owner
@@ -1221,16 +1221,16 @@ trait Typers requires Analyzer {
def typedFunction(fun: Function, mode: int, pt: Type): Tree = {
val codeExpected = !forCLDC && !forMSIL && (pt.symbol isNonBottomSubClass CodeClass)
- def decompose(pt: Type): {Symbol, List[Type], Type} =
+ def decompose(pt: Type): Triple[Symbol, List[Type], Type] =
if (isFunctionType(pt)
||
pt.symbol == PartialFunctionClass &&
fun.vparams.length == 1 && fun.body.isInstanceOf[Match])
- {pt.symbol, pt.typeArgs.init, pt.typeArgs.last}
+ Triple(pt.symbol, pt.typeArgs.init, pt.typeArgs.last)
else
- {FunctionClass(fun.vparams.length), fun.vparams map (x => NoType), WildcardType}
+ Triple(FunctionClass(fun.vparams.length), fun.vparams map (x => NoType), WildcardType)
- val {clazz, argpts, respt} = decompose(if (codeExpected) pt.typeArgs.head else pt)
+ val Triple(clazz, argpts, respt) = decompose(if (codeExpected) pt.typeArgs.head else pt)
if (fun.vparams.length != argpts.length)
errorTree(fun, "wrong number of parameters; expected = " + argpts.length)
@@ -1381,14 +1381,15 @@ trait Typers requires Analyzer {
typedApply(tree, adapt(fun, funMode(mode), WildcardType), args1, mode, pt)
case MethodType(formals0, restpe) =>
val formals = formalTypes(formals0, args.length)
- if (formals.length != args.length) {
- //Console.println(formals.length+" "+args.length);//DEBUG
+ var args1 = actualArgs(tree.pos, args, formals.length)
+ if (formals.length != args1.length) {
+ Console.println(formals+" "+args1);//DEBUG
errorTree(tree, "wrong number of arguments for "+treeSymTypeMsg(fun))
} else {
val tparams = context.undetparams
context.undetparams = List()
if (tparams.isEmpty) {
- val args1 = typedArgs(args, mode, formals0, formals)
+ val args2 = typedArgs(args1, mode, formals0, formals)
def ifPatternSkipFormals(tp: Type) = tp match {
case MethodType(_, rtp) if ((mode & PATTERNmode) != 0) => rtp
case _ => tp
@@ -1408,7 +1409,7 @@ trait Typers requires Analyzer {
// the compiler thinks, the PLUS method takes only one argument,
// but he thinks it's an instance method -> still two ref's on the stack
// -> translated by backend
- val rhs = copy.Apply(tree, f, args)
+ val rhs = copy.Apply(tree, f, args1)
return typed(Assign(qual, rhs))
}
case _ => ()
@@ -1418,9 +1419,9 @@ trait Typers requires Analyzer {
if (fun.symbol == List_apply && args.isEmpty) {
atPos(tree.pos) { gen.mkNil setType restpe }
} else if ((mode & CONSTmode) != 0 && fun.symbol.owner == PredefModule.tpe.symbol && fun.symbol.name == nme.Array) {
- val elems = new Array[Constant](args1.length)
+ val elems = new Array[Constant](args2.length)
var i = 0;
- for (val arg <- args1) arg match {
+ for (val arg <- args2) arg match {
case Literal(value) =>
elems(i) = value
i = i + 1
@@ -1430,7 +1431,7 @@ trait Typers requires Analyzer {
Literal(arrayConst) setType mkConstantType(arrayConst)
}
else
- constfold(copy.Apply(tree, fun, args1).setType(ifPatternSkipFormals(restpe)))
+ constfold(copy.Apply(tree, fun, args2).setType(ifPatternSkipFormals(restpe)))
} else {
assert((mode & PATTERNmode) == 0); // this case cannot arise for patterns
val lenientTargs = protoTypeArgs(tparams, formals, restpe, pt)
@@ -1447,12 +1448,12 @@ trait Typers requires Analyzer {
}
arg1
}
- val args1 = List.map2(args, formals)(typedArgToPoly)
- if (args1 exists (.tpe.isError)) setError(tree)
+ val args2 = List.map2(args1, formals)(typedArgToPoly)
+ if (args2 exists (.tpe.isError)) setError(tree)
else {
- if (settings.debug.value) log("infer method inst "+fun+", tparams = "+tparams+", args = "+args1.map(.tpe)+", pt = "+pt+", lobounds = "+tparams.map(.tpe.bounds.lo)+", parambounds = "+tparams.map(.info));//debug
- val undetparams = inferMethodInstance(fun, tparams, args1, pt)
- val result = typedApply(tree, fun, args1, mode, pt)
+ if (settings.debug.value) log("infer method inst "+fun+", tparams = "+tparams+", args = "+args2.map(.tpe)+", pt = "+pt+", lobounds = "+tparams.map(.tpe.bounds.lo)+", parambounds = "+tparams.map(.info));//debug
+ val undetparams = inferMethodInstance(fun, tparams, args2, pt)
+ val result = typedApply(tree, fun, args2, mode, pt)
context.undetparams = undetparams
result
}
@@ -1499,14 +1500,14 @@ trait Typers requires Analyzer {
val oldArgType = arg.tpe
if (!isApplicable(List(), unappType, List(arg.tpe), WildcardType)) {
//Console.println("UNAPP: need to typetest, arg.tpe = "+arg.tpe+", unappType = "+unappType)
- def freshArgType(tp: Type): {Type, List[Symbol]} = tp match {
+ def freshArgType(tp: Type): Pair[Type, List[Symbol]] = tp match {
case MethodType(formals, restpe) =>
- {formals(0), List()}
+ Pair(formals(0), List())
case PolyType(tparams, restype) =>
val tparams1 = cloneSymbols(tparams)
- {freshArgType(restype)._1.substSym(tparams, tparams1), tparams1}
+ Pair(freshArgType(restype)._1.substSym(tparams, tparams1), tparams1)
}
- val {unappFormal, freeVars} = freshArgType(unappType)
+ val Pair(unappFormal, freeVars) = freshArgType(unappType)
val context1 = context.makeNewScope(context.tree, context.owner)
freeVars foreach context1.scope.enter
val typer1 = new Typer(context1)
@@ -1567,12 +1568,12 @@ trait Typers requires Analyzer {
error(ntree.pos, "duplicate value for element " + name)
} else {
names -= sym
- {sym.name, getConstant(typed(rhs, EXPRmode | CONSTmode, sym.tpe.resultType))}
+ Pair(sym.name, getConstant(typed(rhs, EXPRmode | CONSTmode, sym.tpe.resultType)))
}
}
}
for (val name <- names) {
- if (!name.attributes.contains{AnnotationDefaultAttr.tpe, List(), List()}) {
+ if (!name.attributes.contains(Triple(AnnotationDefaultAttr.tpe, List(), List()))) {
error(constr.pos, "attribute " + tpt.tpe.symbol.fullNameString + " is missing element " + name.name)
}
}
@@ -2151,6 +2152,7 @@ trait Typers requires Analyzer {
}
case Typed(expr, tpt @ Ident(name)) if (name == nme.WILDCARD_STAR.toTypeName) =>
+ //todo: do this: errorTree(tree, "`: _*' annotation only legal for method arguments")
val expr1 = typed(expr, mode & stickyModes, seqType(pt))
expr1.tpe.baseType(SeqClass) match {
case TypeRef(_, _, List(elemtp)) =>
@@ -2198,12 +2200,12 @@ trait Typers requires Analyzer {
}
case Super(qual, mix) =>
- val {clazz, selftype} =
+ val Pair(clazz, selftype) =
if (tree.symbol != NoSymbol) {
- {tree.symbol, tree.symbol.thisType}
+ Pair(tree.symbol, tree.symbol.thisType)
} else {
val clazzContext = qualifyingClassContext(tree, qual)
- {clazzContext.owner, clazzContext.prefix}
+ Pair(clazzContext.owner, clazzContext.prefix)
}
if (clazz == NoSymbol) setError(tree)
else {
@@ -2229,12 +2231,12 @@ trait Typers requires Analyzer {
}
case This(qual) =>
- val {clazz, selftype} =
+ val Pair(clazz, selftype) =
if (tree.symbol != NoSymbol) {
- {tree.symbol, tree.symbol.thisType}
+ Pair(tree.symbol, tree.symbol.thisType)
} else {
val clazzContext = qualifyingClassContext(tree, qual)
- {clazzContext.owner, clazzContext.prefix}
+ Pair(clazzContext.owner, clazzContext.prefix)
}
if (clazz == NoSymbol) setError(tree)
else {