commit | e8d4569e37cdffd89015f5fa1f49971dcc0b0140 | [log] [tgz] |
---|---|---|
author | Konstantin Shcheglov <scheglov@google.com> | Mon Jan 18 07:08:49 2021 +0000 |
committer | commit-bot@chromium.org <commit-bot@chromium.org> | Mon Jan 18 07:08:49 2021 +0000 |
tree | 49c012be9f42bfddff8b62755a13f5696c7284f0 | |
parent | 693b9f730d413d193ec1cca9a4de8f6f597f7abf [diff] |
Fix for ConflictingEditException in RemoveUnusedLocalVariable. R=brianwilkerson@google.com, pquitslund@google.com Change-Id: I5614e83b5b7dca720b5de09a5ee7fd457a13b2e1 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/179820 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analysis_server/lib/src/services/correction/dart/remove_unused_local_variable.dart b/pkg/analysis_server/lib/src/services/correction/dart/remove_unused_local_variable.dart index 5120c45..e3b5cf2 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/remove_unused_local_variable.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/remove_unused_local_variable.dart
@@ -50,6 +50,19 @@ return; } + var isCovered = false; + for (var other in sourceRanges) { + if (other.covers(sourceRange)) { + isCovered = true; + } else if (other.intersects(sourceRange)) { + return; + } + } + + if (isCovered) { + continue; + } + sourceRanges.add(sourceRange); }
diff --git a/pkg/analysis_server/test/src/services/correction/fix/remove_unused_local_variable_test.dart b/pkg/analysis_server/test/src/services/correction/fix/remove_unused_local_variable_test.dart index c73b174..dac33f8 100644 --- a/pkg/analysis_server/test/src/services/correction/fix/remove_unused_local_variable_test.dart +++ b/pkg/analysis_server/test/src/services/correction/fix/remove_unused_local_variable_test.dart
@@ -20,6 +20,21 @@ @override FixKind get kind => DartFixKind.REMOVE_UNUSED_LOCAL_VARIABLE; + Future<void> test_assignmentInAssignment() async { + await resolveTestCode(r''' +main() { + var v = 1; + v = (v = 2); + print(0); +} +'''); + await assertHasFix(r''' +main() { + print(0); +} +'''); + } + Future<void> test_inArgumentList() async { await resolveTestCode(r''' main() {