mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 16:41:07 +00:00
Fix RemoveUnusedField when some SourceRange(s) being removed are fully covered.
Change-Id: I7ae8b9286c473a368def9c9db22b2f2b828c7b81 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/214260 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
parent
19b7a3e2b5
commit
57e71e33c5
|
@ -116,8 +116,9 @@ class RemoveUnusedField extends _RemoveUnused {
|
|||
sourceRanges.add(sourceRange);
|
||||
}
|
||||
|
||||
final uniqueSourceRanges = _uniqueSourceRanges(sourceRanges);
|
||||
await builder.addDartFileEdit(file, (builder) {
|
||||
for (var sourceRange in sourceRanges) {
|
||||
for (var sourceRange in uniqueSourceRanges) {
|
||||
builder.addDeletion(sourceRange);
|
||||
}
|
||||
});
|
||||
|
@ -182,6 +183,24 @@ class RemoveUnusedField extends _RemoveUnused {
|
|||
}
|
||||
}
|
||||
|
||||
/// Return [SourceRange]s that are not covered by other in [ranges].
|
||||
/// If there is any intersection, it must be fully covered, never partially.
|
||||
List<SourceRange> _uniqueSourceRanges(List<SourceRange> ranges) {
|
||||
var result = <SourceRange>[];
|
||||
candidates:
|
||||
for (var candidate in ranges) {
|
||||
for (var other in ranges) {
|
||||
if (identical(candidate, other)) {
|
||||
continue;
|
||||
} else if (candidate.coveredBy(other)) {
|
||||
continue candidates;
|
||||
}
|
||||
}
|
||||
result.add(candidate);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Return an instance of this class. Used as a tear-off in `FixProcessor`.
|
||||
static RemoveUnusedField newInstance() => RemoveUnusedField();
|
||||
}
|
||||
|
|
|
@ -192,6 +192,23 @@ class A {
|
|||
''');
|
||||
}
|
||||
|
||||
Future<void> test_unusedField_notUsed_assign_nested() async {
|
||||
await resolveTestCode(r'''
|
||||
class A {
|
||||
var _f;
|
||||
main() {
|
||||
_f = () { _f = 0; };
|
||||
}
|
||||
}
|
||||
''');
|
||||
await assertHasFix(r'''
|
||||
class A {
|
||||
main() {
|
||||
}
|
||||
}
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_unusedField_notUsed_compoundAssign() async {
|
||||
await resolveTestCode(r'''
|
||||
class A {
|
||||
|
|
Loading…
Reference in a new issue