diff options
author | Iulian Dragos <jaguarul@gmail.com> | 2011-11-01 14:02:33 +0000 |
---|---|---|
committer | Iulian Dragos <jaguarul@gmail.com> | 2011-11-01 14:02:33 +0000 |
commit | c6f6a5f78133043d80bbf5a8f67407e4de3cffbf (patch) | |
tree | 29ccf15272324180cb950682504f12aa368f5789 /src | |
parent | 8c1a86b2a061ff500ffba51d79cae0ad0d9127b5 (diff) | |
download | scala-c6f6a5f78133043d80bbf5a8f67407e4de3cffbf.tar.gz scala-c6f6a5f78133043d80bbf5a8f67407e4de3cffbf.tar.bz2 scala-c6f6a5f78133043d80bbf5a8f67407e4de3cffbf.zip |
Manually Backported r25899.
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 923a389fc3..da7ab7b239 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -2248,6 +2248,9 @@ trait Typers extends Modes { def doTypedApply(tree: Tree, fun0: Tree, args: List[Tree], mode: Int, pt: Type): Tree = { // TODO_NMT: check the assumption that args nonEmpty + def errTree = setError(treeCopy.Apply(tree, fun0, args)) + def errorTree(msg: String) = { error(tree.pos, msg); errTree } + var fun = fun0 if (fun.hasSymbol && fun.symbol.isOverloaded) { // remove alternatives with wrong number of parameters without looking at types. @@ -2342,22 +2345,21 @@ trait Typers extends Modes { def tryNamesDefaults: Tree = { val lencmp = compareLengths(args, formals) - if (mt.isErroneous) setError(tree) + if (mt.isErroneous) errTree else if (inPatternMode(mode)) // #2064 - errorTree(tree, "wrong number of arguments for "+ treeSymTypeMsg(fun)) + errorTree("wrong number of arguments for "+ treeSymTypeMsg(fun)) else if (lencmp > 0) { - tryTupleApply getOrElse errorTree(tree, "too many arguments for "+treeSymTypeMsg(fun)) + tryTupleApply getOrElse errorTree("too many arguments for "+treeSymTypeMsg(fun)) } else if (lencmp == 0) { // we don't need defaults. names were used, so this application is transformed // into a block (@see transformNamedApplication in NamesDefaults) val (namelessArgs, argPos) = removeNames(Typer.this)(args, params) if (namelessArgs exists (_.isErroneous)) { - setError(tree) + errTree } else if (!isIdentity(argPos) && !sameLength(formals, params)) // !isIdentity indicates that named arguments are used to re-order arguments - errorTree(tree, "when using named arguments, the vararg parameter "+ - "has to be specified exactly once") + errorTree("when using named arguments, the vararg parameter has to be specified exactly once") else if (isIdentity(argPos) && !isNamedApplyBlock(fun)) { // if there's no re-ordering, and fun is not transformed, no need to transform // more than an optimization, e.g. important in "synchronized { x = update-x }" @@ -2371,7 +2373,7 @@ trait Typers extends Modes { // calls to the default getters. Example: // foo[Int](a)() ==> foo[Int](a)(b = foo$qual.foo$default$2[Int](a)) val fun1 = transformNamedApplication(Typer.this, mode, pt)(fun, x => x) - if (fun1.isErroneous) setError(tree) + if (fun1.isErroneous) errTree else { assert(isNamedApplyBlock(fun1), fun1) val NamedApplyInfo(qual, targs, previousArgss, _) = context.namedApplyBlockInfo.get._2 @@ -2388,17 +2390,17 @@ trait Typers extends Modes { val lencmp2 = compareLengths(allArgs, formals) if (!sameLength(allArgs, args) && callToCompanionConstr(context, funSym)) { - errorTree(tree, "module extending its companion class cannot use default constructor arguments") + errorTree("module extending its companion class cannot use default constructor arguments") } else if (lencmp2 > 0) { removeNames(Typer.this)(allArgs, params) // #3818 - setError(tree) + errTree } else if (lencmp2 == 0) { // useful when a default doesn't match parameter type, e.g. def f[T](x:T="a"); f[Int]() val note = "Error occurred in an application involving default arguments." if (!(context.diagnostic contains note)) context.diagnostic = note :: context.diagnostic doTypedApply(tree, if (blockIsEmpty) fun else fun1, allArgs, mode, pt) } else { - tryTupleApply getOrElse errorTree(tree, notEnoughArgumentsMsg(fun, missing)) + tryTupleApply getOrElse errorTree(notEnoughArgumentsMsg(fun, missing)) } } } @@ -2483,7 +2485,7 @@ trait Typers extends Modes { arg1 } val args1 = (args, formals).zipped map typedArgToPoly - if (args1 exists (_.tpe.isError)) setError(tree) + if (args1 exists (_.tpe.isError)) errTree 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 // define the undetparams which have been fixed by this param list, replace the corresponding symbols in "fun" @@ -2546,7 +2548,7 @@ trait Typers extends Modes { // setType null is necessary so that ref will be stabilized; see bug 881 val fun1 = typedPos(fun.pos)(Apply(Select(fun setType null, unapp), List(arg))) - if (fun1.tpe.isErroneous) setError(tree) + if (fun1.tpe.isErroneous) errTree else { val formals0 = unapplyTypeList(fun1.symbol, fun1.tpe) val formals1 = formalTypes(formals0, args.length) @@ -2562,13 +2564,13 @@ trait Typers extends Modes { UnApply(fun1, args1) setPos tree.pos setType itype } else { - errorTree(tree, "wrong number of arguments for "+treeSymTypeMsg(fun)) + errorTree("wrong number of arguments for "+treeSymTypeMsg(fun)) } } /* --- end unapply --- */ case _ => - errorTree(tree, fun.tpe+" does not take parameters") + errorTree(fun.tpe+" does not take parameters") } } @@ -2980,7 +2982,7 @@ trait Typers extends Modes { errorTree(tree, "wrong number of type parameters for "+treeSymTypeMsg(fun)) } case ErrorType => - setError(tree) + setError(treeCopy.TypeApply(tree, fun, args)) case _ => errorTree(tree, treeSymTypeMsg(fun)+" does not take type parameters.") } @@ -3337,7 +3339,7 @@ trait Typers extends Modes { } } reportTypeError(tree.pos, ex) - setError(tree) + setError(treeCopy.Apply(tree, fun, args)) } } |