Skip to content

Commit 22fef10

Browse files
MichaelRFairhurstcommit-bot@chromium.org
authored andcommitted
[nnbd_migration] suppress fewer upstream exact nullable nodes
Change-Id: I1acd6b44c098868127e903d96baafa03bcd34b04 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/127421 Reviewed-by: Janice Collins <jcollins@google.com> Commit-Queue: Mike Fairhurst <mfairhurst@google.com>
1 parent b37f391 commit 22fef10

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

pkg/analysis_server/lib/src/edit/nnbd_migration/info_builder.dart

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,12 @@ class InfoBuilder {
9292
}
9393

9494
Iterable<EdgeInfo> upstreamTriggeredEdges(NullabilityNodeInfo node,
95-
[List<RegionDetail> details]) {
95+
{bool skipExactNullable = true}) {
9696
var edges = <EdgeInfo>[];
9797
for (EdgeInfo edge in node.upstreamEdges) {
98-
if (node.isExactNullable && edge.sourceNode.isExactNullable) {
98+
if (skipExactNullable &&
99+
node.isExactNullable &&
100+
edge.sourceNode.isExactNullable) {
99101
// When an exact nullable points here, the nullability propagated
100102
// in the other direction.
101103
continue;
@@ -105,7 +107,14 @@ class InfoBuilder {
105107
}
106108
}
107109
for (final containerNode in node.outerCompoundNodes) {
108-
edges.addAll(upstreamTriggeredEdges(containerNode, details));
110+
// We must include the exact nullable edges in the upstream triggered
111+
// edges of the container node. If this node is in a substitution node,
112+
// then it's possible it was marked exact nullable because it's container
113+
// was marked nullable. It's container could have been marked nullable by
114+
// another exact nullable node. We cannot tell. Err on the side of
115+
// surfacing too many reasons.
116+
edges.addAll(
117+
upstreamTriggeredEdges(containerNode, skipExactNullable: false));
109118
}
110119

111120
return edges;

pkg/analysis_server/test/src/edit/nnbd_migration/info_builder_test.dart

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,33 @@ void g() {
227227
assertDetail(detail: regions[0].details[0], offset: 104, length: 1);
228228
}
229229

230+
test_exactNullable_exactNullable() async {
231+
UnitInfo unit = await buildInfoForSingleTestFile('''
232+
void g(List<int> list1, List<int> list2) {
233+
list1[0] = null;
234+
list2[0] = list1[0];
235+
}
236+
''', migratedContent: '''
237+
void g(List<int?> list1, List<int?> list2) {
238+
list1[0] = null;
239+
list2[0] = list1[0];
240+
}
241+
''');
242+
List<RegionInfo> regions = unit.regions;
243+
expect(regions, hasLength(4));
244+
// regions[0] is the hard edge that list1 is unconditionally indexed
245+
assertRegion(region: regions[1], offset: 15, details: [
246+
"An explicit 'null' is assigned",
247+
// TODO(mfairhurst): Fix this bug.
248+
'exact nullable node with no info (Substituted(type(32), migrated))'
249+
]);
250+
// regions[2] is the hard edge that list2 is unconditionally indexed
251+
assertRegion(
252+
region: regions[3],
253+
offset: 33,
254+
details: ["A nullable value is assigned"]);
255+
}
256+
230257
test_exactNullable() async {
231258
UnitInfo unit = await buildInfoForSingleTestFile('''
232259
void f(List<int> list) {

0 commit comments

Comments
 (0)