File tree 1 file changed +22
-1
lines changed
compiler/src/dotty/tools/dotc/core
1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -444,7 +444,28 @@ object Types {
444
444
case _ => NoType
445
445
}
446
446
447
- /** Is this a higher-kinded type lambda with given parameter variances? */
447
+ /** Is this a higher-kinded type lambda with given parameter variances?
448
+ * These lambdas are used as the RHS of higher-kinded abstract types or
449
+ * type aliases. The variance info is strictly needed only for abstract types.
450
+ * For type aliases we allow the user to write the variance, and we use it
451
+ * to check that the structural variance of the type lambda is compatible
452
+ * with the declared variance, and that the declared variance is compatible
453
+ * with any abstract types that are overridden.
454
+ *
455
+ * But it's important to note that the variance of a type parameter in
456
+ * a type lambda is strictly determined by how it occurs in the body of
457
+ * the lambda. Declared variances have no influence here. For instance
458
+ * the following two lambdas are variant, even though no parameter variance
459
+ * is indicated:
460
+ *
461
+ * [X] =>> List[X] // covariant
462
+ * [X] =>> X => Unit // contravariant
463
+ *
464
+ * Why store declared variances in lambdas at all? It's because type symbols are just
465
+ * normal symbols, and there is no field in a Symbol that keeps a list of variances.
466
+ * Generally we have the design that we store all info that applies to some symbols
467
+ * but not others in the symbol's types.
468
+ */
448
469
def isDeclaredVarianceLambda : Boolean = false
449
470
450
471
/** Does this type contain wildcard types? */
You can’t perform that action at this time.
0 commit comments