Permalink
Browse files

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.
  • Loading branch information...
1 parent a0cd0f8 commit dfa4e23bf8af721a4361567aef9aed672e39d4f8 @xeno-by xeno-by committed Dec 9, 2012
Showing with 15 additions and 21 deletions.
  1. +15 −21 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 {

0 comments on commit dfa4e23

Please sign in to comment.