Skip to content
This repository
Browse code

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...
commit dfa4e23bf8af721a4361567aef9aed672e39d4f8 1 parent a0cd0f8
Eugene Burmako xeno-by authored

Showing 1 changed file with 15 additions and 21 deletions. Show diff stats Hide diff stats

  1. +15 21 src/compiler/scala/tools/nsc/typechecker/Infer.scala
36 src/compiler/scala/tools/nsc/typechecker/Infer.scala
@@ -1003,28 +1003,22 @@ trait Infer extends Checkable {
1003 1003 */
1004 1004 /** error if arguments not within bounds. */
1005 1005 def checkBounds(tree: Tree, pre: Type, owner: Symbol,
1006   - tparams: List[Symbol], targs: List[Type], prefix: String): Boolean = {
1007   - //@M validate variances & bounds of targs wrt variances & bounds of tparams
1008   - //@M TODO: better place to check this?
1009   - //@M TODO: errors for getters & setters are reported separately
1010   - val kindErrors = checkKindBounds(tparams, targs, pre, owner)
1011   - def alreadyHasErrors = (targs exists (_.isErroneous)) || (tparams exists (_.isErroneous))
1012   -
1013   - if(!kindErrors.isEmpty) {
1014   - if (targs contains WildcardType) true
1015   - else {
1016   - if (!alreadyHasErrors) {
1017   - KindBoundErrors(tree, prefix, targs, tparams, kindErrors)
1018   - false
1019   - } else true
  1006 + tparams: List[Symbol], targs: List[Type], prefix: String): Boolean =
  1007 + if ((targs exists (_.isErroneous)) || (tparams exists (_.isErroneous))) true
  1008 + else {
  1009 + //@M validate variances & bounds of targs wrt variances & bounds of tparams
  1010 + //@M TODO: better place to check this?
  1011 + //@M TODO: errors for getters & setters are reported separately
  1012 + val kindErrors = checkKindBounds(tparams, targs, pre, owner)
  1013 + kindErrors match {
  1014 + case Nil =>
  1015 + def notWithinBounds() = NotWithinBounds(tree, prefix, targs, tparams, Nil)
  1016 + isWithinBounds(pre, owner, tparams, targs) || {notWithinBounds(); false}
  1017 + case errors =>
  1018 + def kindBoundErrors() = KindBoundErrors(tree, prefix, targs, tparams, errors)
  1019 + (targs contains WildcardType) || {kindBoundErrors(); false}
1020 1020 }
1021   - } else if (!isWithinBounds(pre, owner, tparams, targs)) {
1022   - if (!alreadyHasErrors) {
1023   - NotWithinBounds(tree, prefix, targs, tparams, kindErrors)
1024   - false
1025   - } else true
1026   - } else true
1027   - }
  1021 + }
1028 1022
1029 1023 def checkKindBounds(tparams: List[Symbol], targs: List[Type], pre: Type, owner: Symbol): List[String] = {
1030 1024 checkKindBounds0(tparams, targs, pre, owner, true) map {

0 comments on commit dfa4e23

Please sign in to comment.
Something went wrong with that request. Please try again.