Skip to content

Commit a757d2a

Browse files
stereotype441Commit Queue
authored and
Commit Queue
committed
Enable sound-flow-analysis for Dart 3.9.
Bug: #60438 Change-Id: I908d4e4a9143142281d8198870f40eba6cf6f67f Tested: trybots Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/427500 Reviewed-by: Ivan Inozemtsev <iinozemtsev@google.com> Commit-Queue: Paul Berry <paulberry@google.com> Reviewed-by: Morgan :) <davidmorgan@google.com> Reviewed-by: Daco Harkes <dacoharkes@google.com> Reviewed-by: Samuel Rawlins <srawlins@google.com>
1 parent a42401a commit a757d2a

31 files changed

+259
-147
lines changed

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
## 3.9.0
22

3+
### Language
4+
5+
Dart 3.9 assumes null safety when computing type promotion, reachability, and
6+
definite assignment. This makes these features produce more accurate results for
7+
modern Dart programs. As a result of this change, more dead_code warnings may be
8+
produced. To take advantage of these improvements, set your package's [SDK
9+
constraint][language version] lower bound to 3.9 or greater (`sdk: '^3.9.0'`).
10+
11+
[language version]: https://dart.dev/guides/language/evolution
12+
313
### Tools
414

515
#### Dart Development Compiler (dartdevc)

pkg/_fe_analyzer_shared/lib/src/experiments/flags.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,10 @@ enum ExperimentalFlag {
222222

223223
soundFlowAnalysis(
224224
name: 'sound-flow-analysis',
225-
isEnabledByDefault: false,
225+
isEnabledByDefault: true,
226226
isExpired: false,
227-
experimentEnabledVersion: defaultLanguageVersion,
228-
experimentReleasedVersion: defaultLanguageVersion),
227+
experimentEnabledVersion: const Version(3, 9),
228+
experimentReleasedVersion: const Version(3, 9)),
229229

230230
spreadCollections(
231231
name: 'spread-collections',

pkg/_fe_analyzer_shared/test/flow_analysis/reachability/data/equality_operator.dart

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ void nullableValue(int? x) {
3535
}
3636

3737
void nonNullableValue(int x) {
38-
if (x == null) {
38+
if (x == null) /*unreachable*/{
3939
// Reachable since the value of x might come from legacy code
40-
1;
40+
/*stmt: unreachable*/1;
4141
} else {
4242
2;
4343
}
@@ -68,9 +68,9 @@ void potentiallyNullableTypeVar_nullableBound<T extends Object?>(T x) {
6868
}
6969

7070
void nonNullableTypeVar<T extends Object>(T x) {
71-
if (x == null) {
71+
if (x == null) /*unreachable*/{
7272
// Reachable since the value of x might come from legacy code
73-
1;
73+
/*stmt: unreachable*/1;
7474
} else {
7575
2;
7676
}

pkg/_fe_analyzer_shared/test/flow_analysis/reachability/data/if_null.dart

+27-27
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ void variable_if_null_assign_reachable(int? i) {
1212

1313
void variable_if_null_unreachable(int i) {
1414
// Reachable since the value of i might come from legacy code
15-
i ?? 0;
15+
i ?? /*unreachable*/0;
1616
}
1717

1818
void variable_if_null_assign_unreachable(int i) {
1919
// Reachable since the value of i might come from legacy code
20-
i ??= 0;
20+
/*cfe.update: unreachable*/i ??= /*unreachable*/0;
2121
}
2222

2323
void variable_if_null_assign_unreachable_due_to_promotion(int? i) {
2424
if (i == null) return;
2525
// Reachable since the value of i might come from legacy code
26-
i ??= 0;
26+
/*cfe.update: unreachable*/i ??= /*unreachable*/0;
2727
}
2828

2929
/*member: topLevelNullable:doesNotComplete*/
@@ -45,13 +45,13 @@ void top_level_if_null_assign_reachable() {
4545
void top_level_if_null_unreachable() {
4646
// Reachable since the value returned by topLevelNonNullGet might come from
4747
// legacy code
48-
topLevelNonNullGet ?? 0;
48+
topLevelNonNullGet ?? /*unreachable*/0;
4949
}
5050

5151
void top_level_if_null_assign_unreachable() {
5252
// Reachable since the value returned by topLevelNonNullGet might come from
5353
// legacy code
54-
topLevelNonNullGet ??= 0;
54+
topLevelNonNullGet /*cfe.update: unreachable*/??= /*unreachable*/0;
5555
}
5656

5757
class HasProperty<T> {
@@ -70,12 +70,12 @@ void property_if_null_assign_reachable(HasProperty<int?> x) {
7070

7171
void property_if_null_unreachable(HasProperty<int> x) {
7272
// Reachable since the value returned by prop might come from legacy code
73-
x.prop ?? 0;
73+
x.prop ?? /*unreachable*/0;
7474
}
7575

7676
void property_if_null_assign_unreachable(HasProperty<int> x) {
7777
// Reachable since the value returned by prop might come from legacy code
78-
x.prop ??= 0;
78+
x.prop ??= /*unreachable*/0;
7979
}
8080

8181
void null_aware_property_if_null_reachable(HasProperty<int?>? x) {
@@ -94,7 +94,7 @@ void null_aware_property_if_null_not_shortened(HasProperty<int>? x) {
9494

9595
void null_aware_property_if_null_assign_unreachable(HasProperty<int>? x) {
9696
// Reachable since the value returned by prop might come from legacy code.
97-
x?.prop ??= 0;
97+
x?.prop ??= /*unreachable*/0;
9898
}
9999

100100
class SuperIntQuestionProperty extends HasProperty<int?> {
@@ -110,12 +110,12 @@ class SuperIntQuestionProperty extends HasProperty<int?> {
110110
class SuperIntProperty extends HasProperty<int> {
111111
void if_null_unreachable() {
112112
// Reachable since the value returned by prop might come from legacy code.
113-
super.prop ?? 0;
113+
super.prop ?? /*unreachable*/0;
114114
}
115115

116116
void if_null_assign_unreachable() {
117117
// Reachable since the value returned by prop might come from legacy code.
118-
super.prop ??= 0;
118+
super.prop ??= /*unreachable*/0;
119119
}
120120
}
121121

@@ -138,13 +138,13 @@ void extended_property_if_null_assign_reachable(HasProperty<int?> x) {
138138
void extended_property_if_null_unreachable(HasProperty<int> x) {
139139
// Reachable since the value returned by extendedProp might come from legacy
140140
// code.
141-
x.extendedProp ?? 0;
141+
x.extendedProp ?? /*unreachable*/0;
142142
}
143143

144144
void extended_property_if_null_assign_unreachable(HasProperty<int> x) {
145145
// Reachable since the value returned by extendedProp might come from legacy
146146
// code.
147-
x.extendedProp ??= 0;
147+
x.extendedProp ??= /*unreachable*/0;
148148
}
149149

150150
void null_aware_extended_property_if_null_reachable(HasProperty<int?>? x) {
@@ -166,7 +166,7 @@ void null_aware_extended_property_if_null_assign_unreachable(
166166
HasProperty<int>? x) {
167167
// Reachable since the value returned by extendedProp might come from legacy
168168
// code.
169-
x?.extendedProp ??= 0;
169+
x?.extendedProp ??= /*unreachable*/0;
170170
}
171171

172172
void explicit_extended_property_if_null_reachable(HasProperty<int?> x) {
@@ -180,13 +180,13 @@ void explicit_extended_property_if_null_assign_reachable(HasProperty<int?> x) {
180180
void explicit_extended_property_if_null_unreachable(HasProperty<int> x) {
181181
// Reachable since the value returned by extendedProp might come from legacy
182182
// code.
183-
ExtensionProperty(x).extendedProp ?? 0;
183+
ExtensionProperty(x).extendedProp ?? /*unreachable*/0;
184184
}
185185

186186
void explicit_extended_property_if_null_assign_unreachable(HasProperty<int> x) {
187187
// Reachable since the value returned by extendedProp might come from legacy
188188
// code.
189-
ExtensionProperty(x).extendedProp ??= 0;
189+
ExtensionProperty(x).extendedProp ??= /*unreachable*/0;
190190
}
191191

192192
void null_aware_explicit_extended_property_if_null_reachable(
@@ -210,7 +210,7 @@ void null_aware_explicit_extended_property_if_null_assign_unreachable(
210210
HasProperty<int>? x) {
211211
// Reachable since the value returned by extendedProp might come from legacy
212212
// code.
213-
ExtensionProperty(x)?.extendedProp ??= 0;
213+
ExtensionProperty(x)?.extendedProp ??= /*unreachable*/0;
214214
}
215215

216216
class Indexable<T> {
@@ -226,7 +226,7 @@ void index_if_null_reachable(Indexable<int?> x) {
226226
void index_if_null_unreachable(Indexable<int> x) {
227227
// Reachable since the value returned by operator[] might come from legacy
228228
// code.
229-
x[0] ?? 0;
229+
x[0] ?? /*unreachable*/0;
230230
}
231231

232232
void index_if_null_assign_reachable(Indexable<int?> x) {
@@ -236,7 +236,7 @@ void index_if_null_assign_reachable(Indexable<int?> x) {
236236
void index_if_null_assign_unreachable(Indexable<int> x) {
237237
// Reachable since the value returned by operator[] might come from legacy
238238
// code.
239-
x[0] ??= 0;
239+
x[0] ??= /*unreachable*/0;
240240
}
241241

242242
void null_aware_index_if_null_reachable(Indexable<int?>? x) {
@@ -256,7 +256,7 @@ void null_aware_index_if_null_assign_reachable(Indexable<int?>? x) {
256256
void null_aware_index_if_null_assign_unreachable(Indexable<int>? x) {
257257
// Reachable since the value returned by operator[] might come from legacy
258258
// code.
259-
x?[0] ??= 0;
259+
x?[0] ??= /*unreachable*/0;
260260
}
261261

262262
class SuperIntQuestionIndex extends Indexable<int?> {
@@ -273,13 +273,13 @@ class SuperIntIndex extends Indexable<int> {
273273
void if_null_unreachable() {
274274
// Reachable since the value returned by operator[] might come from legacy
275275
// code.
276-
super[0] ?? 0;
276+
super[0] ?? /*unreachable*/0;
277277
}
278278

279279
void if_null_assign_unreachable() {
280280
// Reachable since the value returned by operator[] might come from legacy
281281
// code.
282-
super[0] ??= 0;
282+
super[0] ??= /*unreachable*/0;
283283
}
284284
}
285285

@@ -302,13 +302,13 @@ void extended_index_if_null_assign_reachable(HasProperty<int?> x) {
302302
void extended_index_if_null_unreachable(HasProperty<int> x) {
303303
// Reachable since the value returned by operator[] might come from legacy
304304
// code.
305-
x[0] ?? 0;
305+
x[0] ?? /*unreachable*/0;
306306
}
307307

308308
void extended_index_if_null_assign_unreachable(HasProperty<int> x) {
309309
// Reachable since the value returned by operator[] might come from legacy
310310
// code.
311-
x[0] ??= 0;
311+
x[0] ??= /*unreachable*/0;
312312
}
313313

314314
void null_aware_extended_index_if_null_reachable(HasProperty<int?>? x) {
@@ -328,7 +328,7 @@ void null_aware_extended_index_if_null_not_shortened(HasProperty<int>? x) {
328328
void null_aware_extended_index_if_null_assign_unreachable(HasProperty<int>? x) {
329329
// Reachable since the value returned by operator[] might come from legacy
330330
// code.
331-
x?[0] ??= 0;
331+
x?[0] ??= /*unreachable*/0;
332332
}
333333

334334
void explicit_extended_index_if_null_reachable(HasProperty<int?> x) {
@@ -342,13 +342,13 @@ void explicit_extended_index_if_null_assign_reachable(HasProperty<int?> x) {
342342
void explicit_extended_index_if_null_unreachable(HasProperty<int> x) {
343343
// Reachable since the value returned by operator[] might come from legacy
344344
// code.
345-
ExtensionIndex(x)[0] ?? 0;
345+
ExtensionIndex(x)[0] ?? /*unreachable*/0;
346346
}
347347

348348
void explicit_extended_index_if_null_assign_unreachable(HasProperty<int> x) {
349349
// Reachable since the value returned by operator[] might come from legacy
350350
// code.
351-
ExtensionIndex(x)[0] ??= 0;
351+
ExtensionIndex(x)[0] ??= /*unreachable*/0;
352352
}
353353

354354
void null_aware_explicit_extended_index_if_null_reachable(
@@ -372,5 +372,5 @@ void null_aware_explicit_extended_index_if_null_assign_unreachable(
372372
HasProperty<int>? x) {
373373
// Reachable since the value returned by operator[] might come from legacy
374374
// code.
375-
ExtensionIndex(x)?[0] ??= 0;
375+
ExtensionIndex(x)?[0] ??= /*unreachable*/0;
376376
}

0 commit comments

Comments
 (0)