@@ -512,31 +512,35 @@ If `K` is any other type schema:
512
512
As noted above, contrary to the practice for runtime checked covariant nominal
513
513
types, we do not prefer the context type over the more precise upwards type.
514
514
The following example illustrates this:
515
+
515
516
``` dart
516
- // No static error.
517
- // Inferred type of the record is (int, double)
518
- (num, num) r = (3, 3.5)..$0.isEven;
517
+ // No static error.
518
+ // Inferred type of the record is (int, double)
519
+ (num, num) r = (3, 3.5)..$0.isEven;
519
520
```
520
521
521
522
Also note that implicit casts and other coercions are considered to be applied
522
523
as part of inference, hence:
524
+
523
525
``` dart
524
- class Callable {
525
- void call(num x) {}
526
- }
527
- T id<T>(T x) => x;
528
- // No static error.
529
- // Inferred type of the record is:
530
- // (int, double, int Function(int), void Function(num))
531
- var c = Callable();
532
- dynamic d = 3;
533
- (num, double, int Function(int), void Function(num)) r = (d, 3, id, c);
526
+ class Callable {
527
+ void call(num x) {}
528
+ }
529
+ T id<T>(T x) => x;
530
+ // No static error.
531
+ // Inferred type of the record is:
532
+ // (int, double, int Function(int), void Function(num))
533
+ var c = Callable();
534
+ dynamic d = 3;
535
+ (num, double, int Function(int), void Function(num)) r = (d, 3, id, c);
534
536
```
537
+
535
538
and the record initialization in the last line above is implicitly coerced to be
536
539
the equivalent of:
540
+
537
541
``` dart
538
- (num, double, int Function(int), void Function(num)) r =
539
- (d as num, 3.0, id<int>, c.call);
542
+ (num, double, int Function(int), void Function(num)) r =
543
+ (d as num, 3.0, id<int>, c.call);
540
544
```
541
545
542
546
See issue [ 2488] ( https://github.com/dart-lang/language/issues/2488 ) for some of
@@ -785,15 +789,11 @@ covariant in their field types.
785
789
786
790
### Interactions with libraries using older language versions
787
791
788
- The records feature is language versioned, as usual with new Dart features.
789
- This means that it will be an error to use the syntax for records in libraries
790
- which do not have a language version greater than or equal to the language
791
- version in which records are released. More specifically, assuming that ` v ` is
792
- the language version in which records are released, the following errors apply.
793
-
794
- It is an error for the identifier ` Record ` , denoting the ` Record ` class from
795
- ` dart:core ` , where that import scope name is only imported from platform
796
- libraries, to appear in a library whose language version is less than ` v ` .
792
+ The records feature is language versioned, as usual with new Dart features. This
793
+ means that it will be an error to use the syntax for records in libraries which
794
+ do not have a language version greater than or equal to the language version in
795
+ which records are released. More specifically, assuming that ` v ` is the language
796
+ version in which records are released, the following errors apply.
797
797
798
798
It is an error for the record literal syntax (e.g. ` (3, 4) ` ) to be used
799
799
syntactically in a library whose language version is less than ` v ` .
@@ -806,28 +806,33 @@ record syntax in legacy libraries. It is not an error for a library whose
806
806
language version is less than ` v ` (a "legacy library") to include types which
807
807
denote or include the ` Record ` class, record types or record expressions when
808
808
these terms arise directly or indirectly from references to another library
809
- whose language version is greater than or equal to ` v ` . For example, such a
810
- legacy library may reference a typedef name which is bound to a record type in
811
- another library, and the semantic interpretation of the typedef is as the
812
- underlying record type, just as it would be for any other type. Similarly, type
813
- inference may introduce record types into a legacy library, and such types will
814
- be interpreted by the compiler as record types as usual (that is, there is no
815
- erasure implied to remove these inferred types). A legacy library may refer to
816
- the ` Record ` class via a library which has re-exported it. Record values may
817
- flow into a legacy library via a reference to a member from another library, and
818
- a legacy library may freely call getters on record values (since there is no new
819
- syntax for calling a record getter). The rationale for the choices described in
820
- this section is that the intent of language versioning (for an additive feature
821
- such as records) is to ensure that users do not accidentally use new features in
822
- a package without specifying an SDK constraint which ensures that their code
823
- will always be run on an SDK which supports the feature. But in the case of a
824
- legacy library which references record values or types indirectly via another
825
- library, the SDK constraint on the referenced library is sufficient to enforce
826
- this. *
827
-
809
+ whose language version is greater than or equal to ` v ` .*
810
+
811
+ * For example, such a legacy library may reference a typedef name which is bound
812
+ to a record type in another library, and the semantic interpretation of the
813
+ typedef is as the underlying record type, just as it would be for any other
814
+ type. Similarly, type inference may introduce record types into a legacy
815
+ library, and such types will be interpreted by the compiler as record types as
816
+ usual (that is, there is no erasure implied to remove these inferred types). *
817
+
818
+ * Record values may flow into a legacy library via a reference to a member from
819
+ another library, and a legacy library may freely call getters on record values
820
+ (since there is no new syntax for calling a record getter). The rationale for
821
+ the choices described in this section is that the intent of language versioning
822
+ (for an additive feature such as records) is to ensure that users do not
823
+ accidentally use new features in a package without specifying an SDK constraint
824
+ which ensures that their code will always be run on an SDK which supports the
825
+ feature. But in the case of a legacy library which references record values or
826
+ types indirectly via another library, the SDK constraint on the referenced
827
+ library is sufficient to enforce this. *
828
828
829
829
## CHANGELOG
830
830
831
+ ### 1.19
832
+
833
+ - Allow legacy libraries that don't support records to still be able to see the
834
+ ` Record ` class in "dart: core " (#2661 ).
835
+
831
836
### 1.18
832
837
833
838
- Unconditionally treat ` on ` after a ` try ` block as an on clause even when not
0 commit comments