Skip to content

Commit bd1d91e

Browse files
authored
#1399. [Records] Interaction with legacy tests added (#1502)
Authored by @sgrekhov.
1 parent 8492cbb commit bd1d91e

8 files changed

+436
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion Assuming that v is the language version in which records are
6+
/// released, the following errors apply.
7+
///
8+
/// It is an error for the identifier [Record], denoting the [Record] class from
9+
/// dart:core, where that import scope name is only imported from platform
10+
/// libraries, to appear in a library whose language version is less than v.
11+
///
12+
/// @description Check that it is a compile-time error if class [Record] from
13+
/// dart:core is used in a library whose language version is less than v.
14+
/// @author [email protected]
15+
16+
// @dart = 2.18
17+
18+
// SharedOptions=--enable-experiment=records
19+
20+
typedef T1 = Record;
21+
// ^^^^^^
22+
// [analyzer] unspecified
23+
// [cfe] unspecified
24+
25+
T? foo<T>(T? t) => t;
26+
27+
main() {
28+
Record? r = null;
29+
//^^^^^^
30+
// [analyzer] unspecified
31+
// [cfe] unspecified
32+
foo<Record>(null);
33+
// ^^^^^^
34+
// [analyzer] unspecified
35+
// [cfe] unspecified
36+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion Assuming that v is the language version in which records are
6+
/// released, the following errors apply.
7+
///
8+
/// It is an error for the record literal syntax (e.g. (3, 4)) to be used
9+
/// syntactically in a library whose language version is less than v.
10+
///
11+
/// @description Check that it is a compile-time error if record literal syntax
12+
/// is used in a library whose language version is less than v.
13+
/// @author [email protected]
14+
15+
// @dart = 2.18
16+
17+
// SharedOptions=--enable-experiment=records
18+
19+
void foo(dynamic x) {}
20+
21+
main() {
22+
var r1 = (1, 2);
23+
// ^^^^^^
24+
// [analyzer] unspecified
25+
// [cfe] unspecified
26+
27+
var r2 = (1, n: 2);
28+
// ^^^^^^^^^
29+
// [analyzer] unspecified
30+
// [cfe] unspecified
31+
32+
var r3 = (1,);
33+
// ^^^^
34+
// [analyzer] unspecified
35+
// [cfe] unspecified
36+
37+
var r4 = ();
38+
// ^^
39+
// [analyzer] unspecified
40+
// [cfe] unspecified
41+
42+
var r5 = (s: "x");
43+
// ^^^^^^^^
44+
// [analyzer] unspecified
45+
// [cfe] unspecified
46+
47+
foo(());
48+
// ^^
49+
// [analyzer] unspecified
50+
// [cfe] unspecified
51+
52+
foo((1,));
53+
// ^^^^
54+
// [analyzer] unspecified
55+
// [cfe] unspecified
56+
57+
foo((1, 2));
58+
// ^^^^^^
59+
// [analyzer] unspecified
60+
// [cfe] unspecified
61+
62+
foo((1, n: 42));
63+
// ^^^^^^^^^^
64+
// [analyzer] unspecified
65+
// [cfe] unspecified
66+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion Assuming that v is the language version in which records are
6+
/// released, the following errors apply.
7+
///
8+
/// It is an error for the record type syntax (e.g. (int, int)) to be used
9+
/// syntactically in a library whose language version is less than v.
10+
///
11+
/// @description Check that it is a compile-time error if record type syntax
12+
/// is used in a library whose language version is less than v.
13+
/// @author [email protected]
14+
15+
// @dart = 2.18
16+
17+
// SharedOptions=--enable-experiment=records
18+
19+
typedef T1 = ();
20+
// ^^
21+
// [analyzer] unspecified
22+
// [cfe] unspecified
23+
24+
typedef T2 = (int,);
25+
// ^^^^^^
26+
// [analyzer] unspecified
27+
// [cfe] unspecified
28+
29+
typedef T3 = (int, String);
30+
// ^^^^^^^^^^^^^
31+
// [analyzer] unspecified
32+
// [cfe] unspecified
33+
34+
typedef T4 = (int, {String s});
35+
// ^^^^^^^^^^^^^^^^^
36+
// [analyzer] unspecified
37+
// [cfe] unspecified
38+
39+
typedef T5 = ({String s});
40+
// ^^^^^^^^^^^^
41+
// [analyzer] unspecified
42+
// [cfe] unspecified
43+
44+
main() {
45+
()? r1 = null;
46+
//^^
47+
// [analyzer] unspecified
48+
// [cfe] unspecified
49+
50+
(int,)? r2 = null;
51+
//^^^^^^
52+
// [analyzer] unspecified
53+
// [cfe] unspecified
54+
55+
(int, String)? r3 = null;
56+
//^^^^^^^^^^^^^
57+
// [analyzer] unspecified
58+
// [cfe] unspecified
59+
60+
(int, {String s})? r4 = null;
61+
//^^^^^^^^^^^^^^^^^
62+
// [analyzer] unspecified
63+
// [cfe] unspecified
64+
65+
({String s})? r5 = null;
66+
//^^^^^^^^^^^^
67+
// [analyzer] unspecified
68+
// [cfe] unspecified
69+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion It is not an error for a library whose language version is less
6+
/// than v (a "legacy library") to include types which denote or include the
7+
/// [Record] class, record types or record expressions when these terms arise
8+
/// directly or indirectly from references to another library whose language
9+
/// version is greater than or equal to v. For example, such a legacy library
10+
/// may reference a typedef name which is bound to a record type in another
11+
/// library, and the semantic interpretation of the typedef is as the underlying
12+
/// record type, just as it would be for any other type. Similarly, type
13+
/// inference may introduce record types into a legacy library, and such types
14+
/// will be interpreted by the compiler as record types as usual (that is, there
15+
/// is no erasure implied to remove these inferred types). A legacy library may
16+
/// refer to the [Record] class via a library which has re-exported it. Record
17+
/// values may flow into a legacy library via a reference to a member from
18+
/// another library, and a legacy library may freely call getters on record
19+
/// values (since there is no new syntax for calling a record getter). The
20+
/// rationale for the choices described in this section is that the intent of
21+
/// language versioning (for an additive feature such as records) is to ensure
22+
/// that users do not accidentally use new features in a package without
23+
/// specifying an SDK constraint which ensures that their code will always be
24+
/// run on an SDK which supports the feature. But in the case of a legacy
25+
/// library which references record values or types indirectly via another
26+
/// library, the SDK constraint on the referenced library is sufficient to
27+
/// enforce this.
28+
///
29+
/// @description Check that it is not an error if legacy library includes types
30+
/// which denote or include record types or record expressions from not legacy
31+
/// library
32+
/// @author [email protected]
33+
34+
// @dart = 2.18
35+
36+
// SharedOptions=--enable-experiment=records
37+
38+
import "interaction_with_legacy_lib.dart";
39+
40+
main() {
41+
R0 _r0 = r0;
42+
R1 _r1 = r1;
43+
R2 _r2 = r2;
44+
R3 _r3 = r3;
45+
R4 _r4 = r4;
46+
Rec _rec = rec;
47+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion It is not an error for a library whose language version is less
6+
/// than v (a "legacy library") to include types which denote or include the
7+
/// [Record] class, record types or record expressions when these terms arise
8+
/// directly or indirectly from references to another library whose language
9+
/// version is greater than or equal to v. For example, such a legacy library
10+
/// may reference a typedef name which is bound to a record type in another
11+
/// library, and the semantic interpretation of the typedef is as the underlying
12+
/// record type, just as it would be for any other type. Similarly, type
13+
/// inference may introduce record types into a legacy library, and such types
14+
/// will be interpreted by the compiler as record types as usual (that is, there
15+
/// is no erasure implied to remove these inferred types). A legacy library may
16+
/// refer to the [Record] class via a library which has re-exported it. Record
17+
/// values may flow into a legacy library via a reference to a member from
18+
/// another library, and a legacy library may freely call getters on record
19+
/// values (since there is no new syntax for calling a record getter). The
20+
/// rationale for the choices described in this section is that the intent of
21+
/// language versioning (for an additive feature such as records) is to ensure
22+
/// that users do not accidentally use new features in a package without
23+
/// specifying an SDK constraint which ensures that their code will always be
24+
/// run on an SDK which supports the feature. But in the case of a legacy
25+
/// library which references record values or types indirectly via another
26+
/// library, the SDK constraint on the referenced library is sufficient to
27+
/// enforce this.
28+
///
29+
/// @description Check that type inference may introduce record types into a
30+
/// legacy library, and such types will be interpreted by the compiler as record
31+
/// types as usual
32+
/// @author [email protected]
33+
34+
// @dart = 2.18
35+
36+
// SharedOptions=--enable-experiment=records
37+
38+
import "interaction_with_legacy_lib.dart";
39+
40+
main() {
41+
Object _r1 = r1;
42+
Object _r2 = r2;
43+
Object _r3 = r3;
44+
Object _r4 = r4;
45+
46+
if (_r1 is R1) {
47+
_r1.$0;
48+
}
49+
if (_r2 is R2) {
50+
_r2.$0;
51+
_r2.$1;
52+
}
53+
if (_r3 is R3) {
54+
_r3.$0;
55+
_r3.name;
56+
}
57+
if (_r4 is R4) {
58+
_r4.s;
59+
}
60+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion It is not an error for a library whose language version is less
6+
/// than v (a "legacy library") to include types which denote or include the
7+
/// [Record] class, record types or record expressions when these terms arise
8+
/// directly or indirectly from references to another library whose language
9+
/// version is greater than or equal to v. For example, such a legacy library
10+
/// may reference a typedef name which is bound to a record type in another
11+
/// library, and the semantic interpretation of the typedef is as the underlying
12+
/// record type, just as it would be for any other type. Similarly, type
13+
/// inference may introduce record types into a legacy library, and such types
14+
/// will be interpreted by the compiler as record types as usual (that is, there
15+
/// is no erasure implied to remove these inferred types). A legacy library may
16+
/// refer to the [Record] class via a library which has re-exported it. Record
17+
/// values may flow into a legacy library via a reference to a member from
18+
/// another library, and a legacy library may freely call getters on record
19+
/// values (since there is no new syntax for calling a record getter). The
20+
/// rationale for the choices described in this section is that the intent of
21+
/// language versioning (for an additive feature such as records) is to ensure
22+
/// that users do not accidentally use new features in a package without
23+
/// specifying an SDK constraint which ensures that their code will always be
24+
/// run on an SDK which supports the feature. But in the case of a legacy
25+
/// library which references record values or types indirectly via another
26+
/// library, the SDK constraint on the referenced library is sufficient to
27+
/// enforce this.
28+
///
29+
/// @description Check that a legacy library may refer to the [Record] class via
30+
/// a library which has re-exported it
31+
/// @author [email protected]
32+
33+
// @dart = 2.18
34+
35+
// SharedOptions=--enable-experiment=records
36+
37+
import "interaction_with_legacy_lib.dart";
38+
39+
Record foo<T extends Record>(T t) => t;
40+
41+
main() {
42+
Record _r0 = r0;
43+
Record _r1 = r1;
44+
Record _r2 = r2;
45+
Record _r3 = r3;
46+
Record _r4 = r4;
47+
Record _rec = rec;
48+
49+
foo(_rec);
50+
foo<R0>(_r0);
51+
foo<R1>(_r1);
52+
foo<R2>(_r2);
53+
foo<R3>(_r3);
54+
foo<R4>(_r4);
55+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion It is not an error for a library whose language version is less
6+
/// than v (a "legacy library") to include types which denote or include the
7+
/// [Record] class, record types or record expressions when these terms arise
8+
/// directly or indirectly from references to another library whose language
9+
/// version is greater than or equal to v. For example, such a legacy library
10+
/// may reference a typedef name which is bound to a record type in another
11+
/// library, and the semantic interpretation of the typedef is as the underlying
12+
/// record type, just as it would be for any other type. Similarly, type
13+
/// inference may introduce record types into a legacy library, and such types
14+
/// will be interpreted by the compiler as record types as usual (that is, there
15+
/// is no erasure implied to remove these inferred types). A legacy library may
16+
/// refer to the [Record] class via a library which has re-exported it. Record
17+
/// values may flow into a legacy library via a reference to a member from
18+
/// another library, and a legacy library may freely call getters on record
19+
/// values (since there is no new syntax for calling a record getter). The
20+
/// rationale for the choices described in this section is that the intent of
21+
/// language versioning (for an additive feature such as records) is to ensure
22+
/// that users do not accidentally use new features in a package without
23+
/// specifying an SDK constraint which ensures that their code will always be
24+
/// run on an SDK which supports the feature. But in the case of a legacy
25+
/// library which references record values or types indirectly via another
26+
/// library, the SDK constraint on the referenced library is sufficient to
27+
/// enforce this.
28+
///
29+
/// @description Check that a record values may flow into a legacy library via a
30+
/// reference to a member from another library, and a legacy library may freely
31+
/// call getters on record values
32+
/// @author [email protected]
33+
34+
// @dart = 2.18
35+
36+
// SharedOptions=--enable-experiment=records
37+
38+
import "interaction_with_legacy_lib.dart";
39+
import "../../Utils/expect.dart";
40+
41+
main() {
42+
Expect.equals(42, r1.$0);
43+
Expect.equals(1, r2.$0);
44+
Expect.equals("one", r2.$1);
45+
Expect.equals(3.14, r3.$0);
46+
Expect.equals("pi", r3.name);
47+
Expect.equals("Lily was here", r4.s);
48+
Expect.equals(1, rec.$0);
49+
Expect.equals(2, rec.$1);
50+
Expect.equals(3, rec.$2);
51+
Expect.equals("1", rec.one);
52+
Expect.equals("2", rec.two);
53+
Expect.equals("3", rec.three);
54+
}

0 commit comments

Comments
 (0)