Skip to content

Commit 4a1cd79

Browse files
committed
dart-lang#2313. [Extension types] Add nullability tests
1 parent b605171 commit 4a1cd79

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright (c) 2023, 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 Let V be an extension type of the form Name<T1, .. Ts>, and let R
6+
/// be the corresponding instantiated representation type. If R is non-nullable
7+
/// then V is a proper subtype of Object, and V is non-nullable. Otherwise, V is
8+
/// a proper subtype of Object?, and V is potentially nullable.
9+
///
10+
/// @description Checks that an extension type is not-nullable even if its
11+
/// representation type is nullable
12+
/// @author [email protected]
13+
14+
// SharedOptions=--enable-experiment=inline-class
15+
16+
import "dart:async" show FutureOr;
17+
18+
extension type ET1(int? _) {}
19+
20+
extension type ET2(Null _) {}
21+
22+
extension type ET3(dynamic _) {}
23+
24+
extension type ET4(void _) {}
25+
26+
extension type ET5(FutureOr<Null> _) {}
27+
28+
main() {
29+
ET1 et11 = null;
30+
// ^^^^
31+
// [analyzer] unspecified
32+
// [cfe] unspecified
33+
ET1? et12 = null;
34+
35+
ET2 et21 = null;
36+
// ^^^^
37+
// [analyzer] unspecified
38+
// [cfe] unspecified
39+
ET2? et22 = null;
40+
41+
ET3 et31 = null;
42+
// ^^^^
43+
// [analyzer] unspecified
44+
// [cfe] unspecified
45+
ET3? et32 = null;
46+
47+
ET4 et41 = null;
48+
// ^^^^
49+
// [analyzer] unspecified
50+
// [cfe] unspecified
51+
ET4? et42 = null;
52+
53+
ET5 et51 = null;
54+
// ^^^^
55+
// [analyzer] unspecified
56+
// [cfe] unspecified
57+
ET5? et52 = null;
58+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright (c) 2023, 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 Let V be an extension type of the form Name<T1, .. Ts>, and let R
6+
/// be the corresponding instantiated representation type. If R is non-nullable
7+
/// then V is a proper subtype of Object, and V is non-nullable. Otherwise, V is
8+
/// a proper subtype of Object?, and V is potentially nullable.
9+
///
10+
/// @description Checks that null can be assigned to an extension type at run
11+
/// time if its representation type is nullable
12+
/// @author [email protected]
13+
14+
// SharedOptions=--enable-experiment=inline-class
15+
16+
import "dart:async" show FutureOr;
17+
import "../../Utils/expect.dart";
18+
19+
extension type ET1(int? _) {}
20+
21+
extension type ET2(Null _) {}
22+
23+
extension type ET3(dynamic _) {}
24+
25+
extension type ET4(void _) {}
26+
27+
extension type ET5(FutureOr<Null> _) {}
28+
29+
main() {
30+
ET1 et1 = null as dynamic;
31+
Expect.isNull(et1);
32+
ET2 et2 = null as dynamic;
33+
Expect.isNull(et2);
34+
ET3 et3 = null as dynamic;
35+
Expect.isNull(et3);
36+
ET4 et4 = null as dynamic;
37+
Expect.isNull(et4);
38+
ET5 et5 = null as dynamic;
39+
Expect.isNull(et5);
40+
}

0 commit comments

Comments
 (0)