@@ -1420,6 +1420,19 @@ object Types {
1420
1420
1421
1421
override def underlying (implicit ctx : Context ) = parent
1422
1422
1423
+ private def checkInst (implicit ctx : Context ): this .type = {
1424
+ if (Config .checkLambdaVariance)
1425
+ refinedInfo match {
1426
+ case refinedInfo : TypeBounds if refinedInfo.variance != 0 && refinedName.isLambdaArgName =>
1427
+ val cls = parent.LambdaClass (forcing = false )
1428
+ if (cls.exists)
1429
+ assert(refinedInfo.variance == cls.typeParams.apply(refinedName.lambdaArgIndex).variance,
1430
+ s " variance mismatch for $this, $cls, ${cls.typeParams}, ${cls.typeParams.apply(refinedName.lambdaArgIndex).variance}, ${refinedInfo.variance}" )
1431
+ case _ =>
1432
+ }
1433
+ this
1434
+ }
1435
+
1423
1436
/** Derived refined type, with a twist: A refinement with a higher-kinded type param placeholder
1424
1437
* is transformed to a refinement of the original type parameter if that one exists.
1425
1438
*/
@@ -1476,10 +1489,10 @@ object Types {
1476
1489
else make(RefinedType (parent, names.head, infoFns.head), names.tail, infoFns.tail)
1477
1490
1478
1491
def apply (parent : Type , name : Name , infoFn : RefinedType => Type )(implicit ctx : Context ): RefinedType =
1479
- ctx.base.uniqueRefinedTypes.enterIfNew(new CachedRefinedType (parent, name, infoFn))
1492
+ ctx.base.uniqueRefinedTypes.enterIfNew(new CachedRefinedType (parent, name, infoFn)).checkInst
1480
1493
1481
1494
def apply (parent : Type , name : Name , info : Type )(implicit ctx : Context ): RefinedType = {
1482
- ctx.base.uniqueRefinedTypes.enterIfNew(parent, name, info)
1495
+ ctx.base.uniqueRefinedTypes.enterIfNew(parent, name, info).checkInst
1483
1496
}
1484
1497
}
1485
1498
0 commit comments