Skip to content

Commit 3103e1e

Browse files
stereotype441commit-bot@chromium.org
authored andcommitted
Migration: don't overcount "whereOrNull" fixes.
Fixes #44174. Bug: #44174 Change-Id: Ida53a11afc2e265cd510b0ac63c50f6b5ac93fdd Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/171962 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Paul Berry <paulberry@google.com>
1 parent 8abc99d commit 3103e1e

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

pkg/nnbd_migration/lib/src/front_end/info_builder.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ class InfoBuilder {
361361

362362
var lineInfo = result.unit.lineInfo;
363363
var insertions = <int, List<AtomicEdit>>{};
364-
var hintsSeen = <HintComment>{};
364+
var infosSeen = Set<AtomicEditInfo>.identity();
365365

366366
// Apply edits and build the regions.
367367
var changes = sourceInfo.changes ?? {};
@@ -392,8 +392,7 @@ class InfoBuilder {
392392
? const <TraceInfo>[]
393393
: _computeTraces(info.fixReasons);
394394
var description = info?.description;
395-
var hint = info?.hintComment;
396-
var isCounted = hint == null || hintsSeen.add(hint);
395+
var isCounted = info != null && infosSeen.add(info);
397396
var explanation = description?.appliedMessage;
398397
var kind = description?.kind;
399398
if (edit.isInsertion) {

pkg/nnbd_migration/test/front_end/unit_renderer_test.dart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,26 @@ bool b = a!.isEven;
161161
['1 late final hint converted to late and final keywords']));
162162
}
163163

164+
Future<void> test_editList_countsWhereOrNullSingly() async {
165+
await buildInfoForSingleTestFile(
166+
'''
167+
import 'package:collection/collection.dart';
168+
169+
int firstEven(Iterable<int> x)
170+
=> x.firstWhere((x) => x.isEven, orElse: () => null);
171+
''',
172+
removeViaComments: false,
173+
migratedContent: '''
174+
import 'package:collection/collection.dart';
175+
176+
int? firstEven(Iterable<int > x)
177+
=> x.firstWherefirstWhereOrNull((x) => x.isEven, orElse: () => null);
178+
''');
179+
var output = renderUnits()[0];
180+
expect(output.edits.keys,
181+
unorderedEquals(['1 method name changed', '1 type made nullable']));
182+
}
183+
164184
Future<void> test_editList_pluralHeader() async {
165185
await buildInfoForSingleTestFile('''
166186
int a = null;

0 commit comments

Comments
 (0)