diff options
author | Paul Phillips <paulp@improving.org> | 2013-05-19 12:40:30 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2013-05-20 10:01:39 -0700 |
commit | 8b8c91ef5678bce9ad0ca94dc2b396a065bc09cc (patch) | |
tree | aa9794d4004426f23d9e2d093b235059066fe424 | |
parent | 0fe56b9770331d258cc71b609af343e02be3f65f (diff) | |
download | scala-8b8c91ef5678bce9ad0ca94dc2b396a065bc09cc.tar.gz scala-8b8c91ef5678bce9ad0ca94dc2b396a065bc09cc.tar.bz2 scala-8b8c91ef5678bce9ad0ca94dc2b396a065bc09cc.zip |
Moving on to checkBounds.
So much dust and debris, so little time.
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Infer.scala | 45 |
1 files changed, 19 insertions, 26 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala index af7b27a4ff..7d614017b7 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala @@ -920,7 +920,7 @@ trait Infer extends Checkable { case et: ExistentialType => isAsSpecific(et.skolemizeExistential, ftpe2) case NullaryMethodType(restpe) => isAsSpecific(restpe, ftpe2) case mt @ MethodType(_, restpe) if mt.isImplicit => isAsSpecific(restpe, ftpe2) - case mt @ MethodType(_, _) if bothAreVarargs => checkIsApplicable(mt.paramTypes map repeatedToSingle) + case mt @ MethodType(_, _) if bothAreVarargs => checkIsApplicable(mt.paramTypes mapConserve repeatedToSingle) case mt @ MethodType(params, _) if params.nonEmpty => checkIsApplicable(mt.paramTypes) case PolyType(tparams, NullaryMethodType(restpe)) => isAsSpecific(PolyType(tparams, restpe), ftpe2) case PolyType(tparams, mt @ MethodType(_, restpe)) if mt.isImplicit => isAsSpecific(PolyType(tparams, restpe), ftpe2) @@ -1042,24 +1042,20 @@ 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 = - 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} - } + def checkBounds(tree: Tree, pre: Type, owner: Symbol, tparams: List[Symbol], targs: List[Type], prefix: String): Boolean = { + def issueBoundsError() = { NotWithinBounds(tree, prefix, targs, tparams, Nil) ; false } + def issueKindBoundErrors(errs: List[String]) = { KindBoundErrors(tree, prefix, targs, tparams, errs) ; false } + //@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 + def check() = checkKindBounds(tparams, targs, pre, owner) match { + case Nil => isWithinBounds(pre, owner, tparams, targs) || issueBoundsError() + case errs => (targs contains WildcardType) || issueKindBoundErrors(errs) } + targs.exists(_.isErroneous) || tparams.exists(_.isErroneous) || check() + } + def checkKindBounds(tparams: List[Symbol], targs: List[Type], pre: Type, owner: Symbol): List[String] = { checkKindBounds0(tparams, targs, pre, owner, explainErrors = true) map { case (targ, tparam, kindErrors) => @@ -1262,17 +1258,14 @@ trait Infer extends Checkable { } } else None - val inferred = inferFor(pt) orElse inferForApproxPt - - inferred match { + inferFor(pt) orElse inferForApproxPt match { case Some(targs) => - new TreeTypeSubstituter(undetparams, targs).traverse(tree) - notifyUndetparamsInferred(undetparams, targs) + new TreeTypeSubstituter(undetparams, targs).traverse(tree) + notifyUndetparamsInferred(undetparams, targs) case _ => - def full = if (isFullyDefined(pt)) "(fully defined)" else "(not fully defined)" - devWarning(s"failed inferConstructorInstance for $tree: ${tree.tpe} undet=$undetparams, pt=$pt $full") - // if (settings.explaintypes.value) explainTypes(resTp.instantiateTypeParams(undetparams, tvars), pt) - ConstrInstantiationError(tree, resTp, pt) + def not = if (isFullyDefined(pt)) "" else "not " + devWarning(s"failed inferConstructorInstance for $tree: ${tree.tpe} undet=$undetparams, pt=$pt (${not}fully defined)") + ConstrInstantiationError(tree, resTp, pt) } } |