File tree Expand file tree Collapse file tree 2 files changed +37
-1
lines changed
lib/src/services/correction/dart
test/src/services/correction/fix Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -116,8 +116,9 @@ class RemoveUnusedField extends _RemoveUnused {
116116 sourceRanges.add (sourceRange);
117117 }
118118
119+ final uniqueSourceRanges = _uniqueSourceRanges (sourceRanges);
119120 await builder.addDartFileEdit (file, (builder) {
120- for (var sourceRange in sourceRanges ) {
121+ for (var sourceRange in uniqueSourceRanges ) {
121122 builder.addDeletion (sourceRange);
122123 }
123124 });
@@ -182,6 +183,24 @@ class RemoveUnusedField extends _RemoveUnused {
182183 }
183184 }
184185
186+ /// Return [SourceRange] s that are not covered by other in [ranges] .
187+ /// If there is any intersection, it must be fully covered, never partially.
188+ List <SourceRange > _uniqueSourceRanges (List <SourceRange > ranges) {
189+ var result = < SourceRange > [];
190+ candidates:
191+ for (var candidate in ranges) {
192+ for (var other in ranges) {
193+ if (identical (candidate, other)) {
194+ continue ;
195+ } else if (candidate.coveredBy (other)) {
196+ continue candidates;
197+ }
198+ }
199+ result.add (candidate);
200+ }
201+ return result;
202+ }
203+
185204 /// Return an instance of this class. Used as a tear-off in `FixProcessor` .
186205 static RemoveUnusedField newInstance () => RemoveUnusedField ();
187206}
Original file line number Diff line number Diff line change @@ -192,6 +192,23 @@ class A {
192192''' );
193193 }
194194
195+ Future <void > test_unusedField_notUsed_assign_nested () async {
196+ await resolveTestCode (r'''
197+ class A {
198+ var _f;
199+ main() {
200+ _f = () { _f = 0; };
201+ }
202+ }
203+ ''' );
204+ await assertHasFix (r'''
205+ class A {
206+ main() {
207+ }
208+ }
209+ ''' );
210+ }
211+
195212 Future <void > test_unusedField_notUsed_compoundAssign () async {
196213 await resolveTestCode (r'''
197214class A {
You can’t perform that action at this time.
0 commit comments