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