diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2012-12-10 00:49:23 +0100 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2012-12-13 00:00:35 +0100 |
commit | dfa4e23bf8af721a4361567aef9aed672e39d4f8 (patch) | |
tree | c577526cd4462acd360abcc27add9864d12f781c /src | |
parent | a0cd0f81be9ab9ffdb1ecd09aebf43f4d7e738a8 (diff) | |
download | scala-dfa4e23bf8af721a4361567aef9aed672e39d4f8.tar.gz scala-dfa4e23bf8af721a4361567aef9aed672e39d4f8.tar.bz2 scala-dfa4e23bf8af721a4361567aef9aed672e39d4f8.zip |
simplifies checkBounds
This patch is an isomorphic transformation of checkBounds, which avoids
doing any checks altogether if the scrutinee is already erroneous.
Inspection of checkKindBounds and isWithinBounds called from checkBounds
suggests that they don't perform side effects which can't be omitted.
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Infer.scala | 36 |
1 files changed, 15 insertions, 21 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala index 96eb3e5c28..7ae8923e43 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala @@ -1003,28 +1003,22 @@ trait Infer extends Checkable { */ /** error if arguments not within bounds. */ def checkBounds(tree: Tree, pre: Type, owner: Symbol, - tparams: List[Symbol], targs: List[Type], prefix: String): Boolean = { - //@M validate variances & bounds of targs wrt variances & bounds of tparams - //@M TODO: better place to check this? - //@M TODO: errors for getters & setters are reported separately - val kindErrors = checkKindBounds(tparams, targs, pre, owner) - def alreadyHasErrors = (targs exists (_.isErroneous)) || (tparams exists (_.isErroneous)) - - if(!kindErrors.isEmpty) { - if (targs contains WildcardType) true - else { - if (!alreadyHasErrors) { - KindBoundErrors(tree, prefix, targs, tparams, kindErrors) - false - } else true + tparams: List[Symbol], targs: List[Type], prefix: String): Boolean = + if ((targs exists (_.isErroneous)) || (tparams exists (_.isErroneous))) true + else { + //@M validate variances & bounds of targs wrt variances & bounds of tparams + //@M TODO: better place to check this? + //@M TODO: errors for getters & setters are reported separately + val kindErrors = checkKindBounds(tparams, targs, pre, owner) + kindErrors match { + case Nil => + def notWithinBounds() = NotWithinBounds(tree, prefix, targs, tparams, Nil) + isWithinBounds(pre, owner, tparams, targs) || {notWithinBounds(); false} + case errors => + def kindBoundErrors() = KindBoundErrors(tree, prefix, targs, tparams, errors) + (targs contains WildcardType) || {kindBoundErrors(); false} } - } else if (!isWithinBounds(pre, owner, tparams, targs)) { - if (!alreadyHasErrors) { - NotWithinBounds(tree, prefix, targs, tparams, kindErrors) - false - } else true - } else true - } + } def checkKindBounds(tparams: List[Symbol], targs: List[Type], pre: Type, owner: Symbol): List[String] = { checkKindBounds0(tparams, targs, pre, owner, true) map { |