Skip to content

Commit 61747ae

Browse files
stereotype441commit-bot@chromium.org
authored andcommitted
Update "why not promoted" language tests with analyzer expectations.
This is possible now that the test runner uses the analyzer's new JSON output format. Bug: #44898 Change-Id: Ib38e52e0c6a8f73074ef702b8a8b18bd9b128743 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/194014 Reviewed-by: Bob Nystrom <[email protected]> Commit-Queue: Paul Berry <[email protected]>
1 parent 7f009e5 commit 61747ae

11 files changed

+480
-404
lines changed

tests/language/why_not_promoted/argument_type_not_assignable_nullability_error_test.dart

Lines changed: 202 additions & 152 deletions
Large diffs are not rendered by default.

tests/language/why_not_promoted/assignment_error_test.dart

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,104 +10,105 @@ abstract class C {
1010
direct_assignment(int? i, int? j) {
1111
if (i == null) return;
1212
i = j;
13-
//^
14-
// [context 1] Variable 'i' could not be promoted due to an assignment.
13+
//^^^^^
14+
// [context 6] Variable 'i' could not be promoted due to an assignment. See http://dart.dev/go/non-promo-write
15+
// [context 10] Variable 'i' could not be promoted due to an assignment.
1516
i.isEven;
1617
// ^^^^^^
17-
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
18-
//^
19-
// [cfe 1] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
18+
// [analyzer 6] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
19+
// [cfe 10] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
2020
}
2121

2222
compound_assignment(C? c, int i) {
2323
if (c == null) return;
2424
c += i;
25-
//^
26-
// [context 2] Variable 'c' could not be promoted due to an assignment.
25+
//^^^^^^
26+
// [context 7] Variable 'c' could not be promoted due to an assignment. See http://dart.dev/go/non-promo-write
27+
// [context 11] Variable 'c' could not be promoted due to an assignment.
2728
c.cProperty;
2829
// ^^^^^^^^^
29-
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
30-
//^
31-
// [cfe 2] Property 'cProperty' cannot be accessed on 'C?' because it is potentially null.
30+
// [analyzer 7] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
31+
// [cfe 11] Property 'cProperty' cannot be accessed on 'C?' because it is potentially null.
3232
}
3333

3434
via_postfix_op(C? c) {
3535
if (c == null) return;
3636
c++;
37-
//^
38-
// [context 3] Variable 'c' could not be promoted due to an assignment.
37+
//^^^
38+
// [context 4] Variable 'c' could not be promoted due to an assignment. See http://dart.dev/go/non-promo-write
39+
// [context 12] Variable 'c' could not be promoted due to an assignment.
3940
c.cProperty;
4041
// ^^^^^^^^^
41-
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
42-
//^
43-
// [cfe 3] Property 'cProperty' cannot be accessed on 'C?' because it is potentially null.
42+
// [analyzer 4] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
43+
// [cfe 12] Property 'cProperty' cannot be accessed on 'C?' because it is potentially null.
4444
}
4545

4646
via_prefix_op(C? c) {
4747
if (c == null) return;
4848
++c;
49+
//^^^
50+
// [context 9] Variable 'c' could not be promoted due to an assignment. See http://dart.dev/go/non-promo-write
4951
//^
50-
// [context 4] Variable 'c' could not be promoted due to an assignment.
52+
// [context 13] Variable 'c' could not be promoted due to an assignment.
5153
c.cProperty;
5254
// ^^^^^^^^^
53-
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
54-
//^
55-
// [cfe 4] Property 'cProperty' cannot be accessed on 'C?' because it is potentially null.
55+
// [analyzer 9] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
56+
// [cfe 13] Property 'cProperty' cannot be accessed on 'C?' because it is potentially null.
5657
}
5758

5859
via_for_each_statement(int? i, List<int?> list) {
5960
if (i == null) return;
6061
for (i in list) {
6162
// ^
62-
// [context 5] Variable 'i' could not be promoted due to an assignment.
63+
// [context 3] Variable 'i' could not be promoted due to an assignment. See http://dart.dev/go/non-promo-write
64+
// [context 14] Variable 'i' could not be promoted due to an assignment.
6365
i.isEven;
6466
// ^^^^^^
65-
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
66-
//^
67-
// [cfe 5] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
67+
// [analyzer 3] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
68+
// [cfe 14] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
6869
}
6970
}
7071

7172
via_for_each_list_element(int? i, List<int?> list) {
7273
if (i == null) return;
7374
[for (i in list) i.isEven];
7475
// ^
75-
// [context 6] Variable 'i' could not be promoted due to an assignment.
76+
// [context 8] Variable 'i' could not be promoted due to an assignment. See http://dart.dev/go/non-promo-write
77+
// [context 15] Variable 'i' could not be promoted due to an assignment.
7678
// ^^^^^^
77-
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
78-
// ^
79-
// [cfe 6] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
79+
// [analyzer 8] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
80+
// [cfe 15] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
8081
}
8182

8283
via_for_each_set_element(int? i, List<int?> list) {
8384
if (i == null) return;
8485
({for (i in list) i.isEven});
8586
// ^
86-
// [context 7] Variable 'i' could not be promoted due to an assignment.
87+
// [context 1] Variable 'i' could not be promoted due to an assignment. See http://dart.dev/go/non-promo-write
88+
// [context 16] Variable 'i' could not be promoted due to an assignment.
8789
// ^^^^^^
88-
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
89-
// ^
90-
// [cfe 7] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
90+
// [analyzer 1] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
91+
// [cfe 16] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
9192
}
9293

9394
via_for_each_map_key(int? i, List<int?> list) {
9495
if (i == null) return;
9596
({for (i in list) i.isEven: null});
9697
// ^
97-
// [context 8] Variable 'i' could not be promoted due to an assignment.
98+
// [context 2] Variable 'i' could not be promoted due to an assignment. See http://dart.dev/go/non-promo-write
99+
// [context 17] Variable 'i' could not be promoted due to an assignment.
98100
// ^^^^^^
99-
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
100-
// ^
101-
// [cfe 8] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
101+
// [analyzer 2] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
102+
// [cfe 17] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
102103
}
103104

104105
via_for_each_map_value(int? i, List<int?> list) {
105106
if (i == null) return;
106107
({for (i in list) null: i.isEven});
107108
// ^
108-
// [context 9] Variable 'i' could not be promoted due to an assignment.
109+
// [context 5] Variable 'i' could not be promoted due to an assignment. See http://dart.dev/go/non-promo-write
110+
// [context 18] Variable 'i' could not be promoted due to an assignment.
109111
// ^^^^^^
110-
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
111-
// ^
112-
// [cfe 9] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
112+
// [analyzer 5] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
113+
// [cfe 18] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
113114
}

tests/language/why_not_promoted/extension_property_error_test.dart

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,40 @@ class C {
77
if (this.i == null) return;
88
this.i.isEven;
99
// ^^^^^^
10-
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
11-
// ^
12-
// [cfe 1] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
10+
// [analyzer 4] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
11+
// [cfe 6] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
1312
}
1413

1514
get_property_via_explicit_this_parenthesized() {
1615
if ((this).i == null) return;
1716
(this).i.isEven;
1817
// ^^^^^^
19-
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
20-
// ^
21-
// [cfe 2] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
18+
// [analyzer 1] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
19+
// [cfe 7] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
2220
}
2321

2422
get_property_by_implicit_this() {
2523
if (i == null) return;
2624
i.isEven;
2725
// ^^^^^^
28-
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
29-
// ^
30-
// [cfe 3] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
26+
// [analyzer 2] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
27+
// [cfe 8] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
3128
}
3229
}
3330

3431
extension E on C {
3532
int? get i => null;
3633
// ^
37-
// [context 1] 'i' refers to a property so it couldn't be promoted.
38-
// [context 2] 'i' refers to a property so it couldn't be promoted.
39-
// [context 3] 'i' refers to a property so it couldn't be promoted.
40-
// [context 4] 'i' refers to a property so it couldn't be promoted.
41-
// [context 5] 'i' refers to a property so it couldn't be promoted.
34+
// [context 1] 'i' refers to a property so it couldn't be promoted. See http://dart.dev/go/non-promo-property
35+
// [context 2] 'i' refers to a property so it couldn't be promoted. See http://dart.dev/go/non-promo-property
36+
// [context 3] 'i' refers to a property so it couldn't be promoted. See http://dart.dev/go/non-promo-property
37+
// [context 4] 'i' refers to a property so it couldn't be promoted. See http://dart.dev/go/non-promo-property
38+
// [context 5] 'i' refers to a property so it couldn't be promoted. See http://dart.dev/go/non-promo-property
39+
// [context 6] 'i' refers to a property so it couldn't be promoted.
40+
// [context 7] 'i' refers to a property so it couldn't be promoted.
41+
// [context 8] 'i' refers to a property so it couldn't be promoted.
42+
// [context 9] 'i' refers to a property so it couldn't be promoted.
43+
// [context 10] 'i' refers to a property so it couldn't be promoted.
4244
int? get j => null;
4345
}
4446

@@ -47,19 +49,17 @@ class D extends C {
4749
if (i == null) return;
4850
i.isEven;
4951
// ^^^^^^
50-
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
51-
// ^
52-
// [cfe 4] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
52+
// [analyzer 5] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
53+
// [cfe 9] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
5354
}
5455
}
5556

5657
get_property_via_prefixed_identifier(C c) {
5758
if (c.i == null) return;
5859
c.i.isEven;
5960
// ^^^^^^
60-
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
61-
// ^
62-
// [cfe 5] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
61+
// [analyzer 3] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
62+
// [cfe 10] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
6363
}
6464

6565
get_property_via_prefixed_identifier_mismatched_target(C c1, C c2) {
@@ -69,7 +69,6 @@ get_property_via_prefixed_identifier_mismatched_target(C c1, C c2) {
6969
c2.i.isEven;
7070
// ^^^^^^
7171
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
72-
// ^
7372
// [cfe] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
7473
}
7574

@@ -80,6 +79,5 @@ get_property_via_prefixed_identifier_mismatched_property(C c) {
8079
c.j.isEven;
8180
// ^^^^^^
8281
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
83-
// ^
8482
// [cfe] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
8583
}

tests/language/why_not_promoted/field_error_test.dart

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,42 @@
55
class C {
66
int? i;
77
// ^
8-
// [context 1] 'i' refers to a property so it couldn't be promoted.
9-
// [context 2] 'i' refers to a property so it couldn't be promoted.
10-
// [context 3] 'i' refers to a property so it couldn't be promoted.
11-
// [context 4] 'i' refers to a property so it couldn't be promoted.
12-
// [context 5] 'i' refers to a property so it couldn't be promoted.
13-
// [context 6] 'i' refers to a property so it couldn't be promoted.
8+
// [context 1] 'i' refers to a property so it couldn't be promoted. See http://dart.dev/go/non-promo-property
9+
// [context 2] 'i' refers to a property so it couldn't be promoted. See http://dart.dev/go/non-promo-property
10+
// [context 3] 'i' refers to a property so it couldn't be promoted. See http://dart.dev/go/non-promo-property
11+
// [context 4] 'i' refers to a property so it couldn't be promoted. See http://dart.dev/go/non-promo-property
12+
// [context 5] 'i' refers to a property so it couldn't be promoted. See http://dart.dev/go/non-promo-property
13+
// [context 6] 'i' refers to a property so it couldn't be promoted. See http://dart.dev/go/non-promo-property
14+
// [context 7] 'i' refers to a property so it couldn't be promoted.
15+
// [context 8] 'i' refers to a property so it couldn't be promoted.
16+
// [context 9] 'i' refers to a property so it couldn't be promoted.
17+
// [context 10] 'i' refers to a property so it couldn't be promoted.
18+
// [context 11] 'i' refers to a property so it couldn't be promoted.
19+
// [context 12] 'i' refers to a property so it couldn't be promoted.
1420
int? j;
1521

1622
get_field_via_explicit_this() {
1723
if (this.i == null) return;
1824
this.i.isEven;
1925
// ^^^^^^
20-
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
21-
// ^
22-
// [cfe 1] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
26+
// [analyzer 2] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
27+
// [cfe 7] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
2328
}
2429

2530
get_field_via_explicit_this_parenthesized() {
2631
if ((this).i == null) return;
2732
(this).i.isEven;
2833
// ^^^^^^
29-
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
30-
// ^
31-
// [cfe 2] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
34+
// [analyzer 3] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
35+
// [cfe 8] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
3236
}
3337

3438
get_field_by_implicit_this() {
3539
if (i == null) return;
3640
i.isEven;
3741
// ^^^^^^
38-
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
39-
// ^
40-
// [cfe 3] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
42+
// [analyzer 5] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
43+
// [cfe 9] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
4144
}
4245
}
4346

@@ -46,28 +49,25 @@ class D extends C {
4649
if (super.i == null) return;
4750
super.i.isEven;
4851
// ^^^^^^
49-
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
50-
// ^
51-
// [cfe 4] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
52+
// [analyzer 4] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
53+
// [cfe 10] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
5254
}
5355

5456
get_field_by_implicit_super() {
5557
if (i == null) return;
5658
i.isEven;
5759
// ^^^^^^
58-
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
59-
// ^
60-
// [cfe 5] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
60+
// [analyzer 1] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
61+
// [cfe 11] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
6162
}
6263
}
6364

6465
get_field_via_prefixed_identifier(C c) {
6566
if (c.i == null) return;
6667
c.i.isEven;
6768
// ^^^^^^
68-
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
69-
// ^
70-
// [cfe 6] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
69+
// [analyzer 6] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
70+
// [cfe 12] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
7171
}
7272

7373
get_field_via_prefixed_identifier_mismatched_target(C c1, C c2) {
@@ -77,7 +77,6 @@ get_field_via_prefixed_identifier_mismatched_target(C c1, C c2) {
7777
c2.i.isEven;
7878
// ^^^^^^
7979
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
80-
// ^
8180
// [cfe] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
8281
}
8382

@@ -88,6 +87,5 @@ get_field_via_prefixed_identifier_mismatched_property(C c) {
8887
c.j.isEven;
8988
// ^^^^^^
9089
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
91-
// ^
9290
// [cfe] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
9391
}

0 commit comments

Comments
 (0)