Issue 25860. Fix for changeFile() directly after removeFile().
Reverts 561d892d296c20528ecbf79f5673a365299220ef
R=brianwilkerson@google.com, paulberry@google.com
Bug: https://github.com/flutter/flutter/issues/25860
Change-Id: I2a7d725d3637754c096b088c85e862ec2917dc71
Reviewed-on: https://dart-review.googlesource.com/c/89380
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analyzer/lib/src/dart/analysis/driver.dart b/pkg/analyzer/lib/src/dart/analysis/driver.dart
index 9369ec0..cb6705e 100644
--- a/pkg/analyzer/lib/src/dart/analysis/driver.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/driver.dart
@@ -550,7 +550,13 @@
}
if (AnalysisEngine.isDartFileName(path)) {
_fileTracker.addFile(path);
- _changeFile(path);
+ // If the file is known, it has already been read, even if it did not
+ // exist. Now we are notified that the file exists, so we need to
+ // re-read it and make sure that we invalidate signature of the files
+ // that reference it.
+ if (_fsState.knownFilePaths.contains(path)) {
+ _changeFile(path);
+ }
}
}
@@ -1330,15 +1336,9 @@
* Implementation for [changeFile].
*/
void _changeFile(String path) {
- // If the file is known, it has already been read, even if it din't exist.
- // Now we are notified that the file changed (just changed or added), so we
- // need to re-read it and make sure that we invalidate signature of the
- // files that reference it.
- if (_fsState.knownFilePaths.contains(path)) {
- _fileTracker.changeFile(path);
- _libraryContext = null;
- _priorityResults.clear();
- }
+ _fileTracker.changeFile(path);
+ _libraryContext = null;
+ _priorityResults.clear();
}
/**
diff --git a/pkg/analyzer/test/src/dart/analysis/driver_test.dart b/pkg/analyzer/test/src/dart/analysis/driver_test.dart
index 12505a4..aef3c08 100644
--- a/pkg/analyzer/test/src/dart/analysis/driver_test.dart
+++ b/pkg/analyzer/test/src/dart/analysis/driver_test.dart
@@ -2337,19 +2337,11 @@
}
test_hasFilesToAnalyze() async {
- var a = convertPath('/test/lib/a.dart');
- var b = convertPath('/test/lib/b.dart');
- var c = convertPath('/test/lib/c.dart');
-
// No files yet, nothing to analyze.
expect(driver.hasFilesToAnalyze, isFalse);
// Add a new file, it should be analyzed.
- newFile(a, content: r'''
-import 'b.dart';
-main() {}
-''');
- driver.addFile(a);
+ addTestFile('main() {}', priority: false);
expect(driver.hasFilesToAnalyze, isTrue);
// Wait for idle, nothing to do.
@@ -2357,25 +2349,19 @@
expect(driver.hasFilesToAnalyze, isFalse);
// Ask to analyze the file, so there is a file to analyze.
- Future<ResolvedUnitResult> future = driver.getResult(a);
+ Future<ResolvedUnitResult> future = driver.getResult(testFile);
expect(driver.hasFilesToAnalyze, isTrue);
// Once analysis is done, there is nothing to analyze.
await future;
expect(driver.hasFilesToAnalyze, isFalse);
- // Change a file that is not added, but referenced, so known.
- driver.changeFile(b);
+ // Change a file, even if not added, it still might affect analysis.
+ driver.changeFile(convertPath('/not/added.dart'));
expect(driver.hasFilesToAnalyze, isTrue);
await waitForIdleWithoutExceptions();
expect(driver.hasFilesToAnalyze, isFalse);
- // Change a file that is not known - neither added, nor referenced.
- driver.changeFile(c);
- expect(driver.hasFilesToAnalyze, isFalse);
- await waitForIdleWithoutExceptions();
- expect(driver.hasFilesToAnalyze, isFalse);
-
// Request of referenced names is not analysis of a file.
driver.getFilesReferencingName('X');
expect(driver.hasFilesToAnalyze, isFalse);
@@ -3376,6 +3362,28 @@
expect(result.errors, hasLength(0));
}
+ test_results_removeFile_changeFile() async {
+ var a = convertPath('/test/lib/a.dart');
+ var b = convertPath('/test/lib/b.dart');
+
+ newFile(a, content: r'''
+var v = 0;
+''');
+ driver.addFile(a);
+
+ await waitForIdleWithoutExceptions();
+ expect(allResults.singleWhere((r) => r.path == a).errors, hasLength(0));
+ allResults.clear();
+
+ newFile(a, content: r'''
+var v = 0
+''');
+ driver.removeFile(b);
+ driver.changeFile(a);
+ await waitForIdleWithoutExceptions();
+ expect(allResults.singleWhere((r) => r.path == a).errors, hasLength(1));
+ }
+
test_results_skipNotAffected() async {
var a = convertPath('/test/lib/a.dart');
var b = convertPath('/test/lib/b.dart');