@@ -178,7 +178,7 @@ fun main() {
178
178
```
179
179
180
180
Let's take a look at the source of the described type inference
181
- behaviour in Dart.
181
+ behavior in Dart.
182
182
183
183
## Constraint solution for a set of type variables
184
184
@@ -194,7 +194,7 @@ is limited in two ways:
194
194
195
195
A convenient way to graphically represent CSSTV is by a rectangle,
196
196
where three sides of it take the three inputs relevant to this
197
- proposal , and the fourth side produces the output. The relevant inputs
197
+ feature , and the fourth side produces the output. The relevant inputs
198
198
are (1) the preliminary solution found by the previous phase of the
199
199
inference, (2) the constraints collected during the current phase of
200
200
the inference, and (3) the bounds of the type variables. The output of
@@ -583,17 +583,20 @@ block-beta
583
583
csstvUpwards -- "{X = B}" --> overallOutput
584
584
```
585
585
586
- ## More examples enabled by the current proposal
586
+ ## More examples enabled by this feature
587
587
588
- In addition to the motivating examples, both the original and the more
589
- complex, being handled by the current proposal, some cases of non
590
- F-bounded type variables are enabled by it as well.
588
+ In addition to both motivating examples, this feature also handles
589
+ some cases involving type variables that are not F-bounded.
591
590
592
- The following example demonstrates a tempting assumption that doesn't
593
- hold today, but will hold with the proposed update. The developers
594
- might think that they will get the extracted type value for ` Y ` when
595
- they specify a type value for ` X ` . We remember similar cases occurring
596
- in practice.
591
+ With a class like ` A ` below, and with this feature, the constructor
592
+ invocation in ` test ` is inferred as ` A<List<num>, num>(<num>[]) ` .
593
+ Without this feature, it is inferred as ` A<List<num>, dynamic>(<num>[]) ` .
594
+
595
+ Intuitively, this happens because the type inference algorithm without this
596
+ feature is unable to detect that there is a relationship between ` X ` and ` Y ` .
597
+ With this feature one could say that the value of ` Y ` is "extracted" from
598
+ the value of ` X ` . We have seen cases in practice demonstrating that the
599
+ ability to transfer this information during type inference is useful.
597
600
598
601
``` dart
599
602
class A<X extends Iterable<Y>, Y> {
@@ -608,9 +611,7 @@ test() {
608
611
```
609
612
610
613
[ #3009 ] : https://github.com/dart-lang/language/issues/3009
611
-
612
614
[ CSSTV ] : https://github.com/dart-lang/language/blob/main/resources/type-system/inference.md#constraint-solution-for-a-set-of-type-variables
613
-
614
615
[ subtype-constraint-generation ] : https://github.com/dart-lang/language/blob/main/resources/type-system/inference.md#subtype-constraint-generation
615
616
616
617
## Changelog
0 commit comments