@@ -353,29 +353,35 @@ class TypeApplications(val self: Type) extends AnyVal {
353
353
}
354
354
355
355
/** If argument A and type parameter P are higher-kinded, adapt the variances
356
- * of A to those of P, ensuring that the variances of the type lambda A
357
- * agree with the variances of corresponding higherkinded type parameters of P. Example:
356
+ * of A to those of P, ensuring that the variances of the type lambda A
357
+ * agree with the variances of corresponding higher-kinded type parameters of P. Example:
358
358
*
359
- * class Companion [+CC[X]]
360
- * Companion [List]
359
+ * class GenericCompanion [+CC[X]]
360
+ * GenericCompanion [List]
361
361
*
362
- * with adaptArgs, this will expand to
362
+ * with adaptHkVariances, the argument `List` will expand to
363
363
*
364
- * Companion[[ X] => List[X] ]
364
+ * [ X] => List[X]
365
365
*
366
366
* instead of
367
367
*
368
- * Companion[[ +X] => List[X] ]
368
+ * [ +X] => List[X]
369
369
*
370
370
* even though `List` is covariant. This adaptation is necessary to ignore conflicting
371
- * variances in overriding members that have types of hk-type parameters such as `Companion[GenTraversable]`
372
- * or `Companion[ListBuffer]`. Without the adaptation we would end up with
371
+ * variances in overriding members that have types of hk-type parameters such as
372
+ * `GenericCompanion[GenTraversable]` or `GenericCompanion[ListBuffer]`.
373
+ * When checking overriding, we need to validate the subtype relationship
373
374
*
374
- * Companion[[+X] => GenTraversable[X]]
375
- * Companion[[X] => List[X]]
375
+ * GenericCompanion[[X] -> ListBuffer[X]] <: GenericCompanion[[+X] -> GenTraversable[X]]
376
376
*
377
- * and the second is not a subtype of the first. So if we have overridding memebrs of the two
378
- * types we get an error.
377
+ * Without adaptation, this would be false, and hence an overriding error would
378
+ * result. But with adaptation, the rhs argument will be adapted to
379
+ *
380
+ * [X] -> GenTraversable[X]
381
+ *
382
+ * which makes the subtype test succeed. The crucial point here is that, since
383
+ * GenericCompanion only expects a non-variant CC, the fact that GenTraversable
384
+ * is covariant is irrelevant, so can be ignored.
379
385
*/
380
386
def adaptHkVariances (bound : Type )(implicit ctx : Context ): Type = {
381
387
val boundLambda = bound.LambdaTrait
0 commit comments