@@ -25,38 +25,35 @@ object VarianceChecker {
2525 * Note: this is achieved by a mechanism separate from checking class type parameters.
2626 * Question: Can the two mechanisms be combined in one?
2727 */
28- def checkLambda (tree : tpd.LambdaTypeTree )(implicit ctx : Context ): tree.type = {
29- tree.tpe match {
30- case tl : HKTypeLambda =>
31- val checkOK = new TypeAccumulator [Boolean ] {
32- def error (tref : TypeParamRef ) = {
33- val VariantName (paramName, v) = tl.paramNames(tref.paramNum).toTermName
34- val paramVarianceStr = if (v == 0 ) " contra" else " co"
35- val occursStr = variance match {
36- case - 1 => " contra"
37- case 0 => " non"
38- case 1 => " co"
39- }
40- val pos = tree.tparams
41- .find(_.name.toTermName == paramName)
42- .map(_.pos)
43- .getOrElse(tree.pos)
44- ctx.error(em " ${paramVarianceStr}variant type parameter $paramName occurs in ${occursStr}variant position in ${tl.resType}" , pos)
28+ def checkLambda (tree : tpd.LambdaTypeTree )(implicit ctx : Context ): Unit = tree.tpe match {
29+ case tl : HKTypeLambda =>
30+ val checkOK = new TypeAccumulator [Boolean ] {
31+ def error (tref : TypeParamRef ) = {
32+ val VariantName (paramName, v) = tl.paramNames(tref.paramNum).toTermName
33+ val paramVarianceStr = if (v == 0 ) " contra" else " co"
34+ val occursStr = variance match {
35+ case - 1 => " contra"
36+ case 0 => " non"
37+ case 1 => " co"
4538 }
46- def apply (x : Boolean , t : Type ) = x && {
47- t match {
48- case tref : TypeParamRef if tref.binder `eq` tl =>
49- val v = tl.typeParams(tref.paramNum).paramVariance
50- varianceConforms(variance, v) || { error(tref); false }
51- case _ =>
52- foldOver(x, t)
53- }
39+ val pos = tree.tparams
40+ .find(_.name.toTermName == paramName)
41+ .map(_.pos)
42+ .getOrElse(tree.pos)
43+ ctx.error(em " ${paramVarianceStr}variant type parameter $paramName occurs in ${occursStr}variant position in ${tl.resType}" , pos)
44+ }
45+ def apply (x : Boolean , t : Type ) = x && {
46+ t match {
47+ case tref : TypeParamRef if tref.binder `eq` tl =>
48+ val v = tl.typeParams(tref.paramNum).paramVariance
49+ varianceConforms(variance, v) || { error(tref); false }
50+ case _ =>
51+ foldOver(x, t)
5452 }
5553 }
56- checkOK.apply(true , tl.resType)
57- case _ =>
58- }
59- tree
54+ }
55+ checkOK.apply(true , tl.resType)
56+ case _ =>
6057 }
6158}
6259
0 commit comments