Skip to content

Commit 3cb16d2

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Issue 35551. Invalidate library cycles of libraries when a part file API signature changes.
[email protected], [email protected] Fixes #35551 Change-Id: If4db0907fc62bdd12f528fe1a61895f6a18ec210 Reviewed-on: https://dart-review.googlesource.com/c/90520 Reviewed-by: Paul Berry <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 5812a3b commit 3cb16d2

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

pkg/analyzer/lib/src/dart/analysis/file_state.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,15 @@ class FileState {
510510
// Flush exported top-level declarations of all files.
511511
if (apiSignatureChanged) {
512512
_libraryCycle?.invalidate();
513+
514+
// If this is a part, invalidate the libraries.
515+
var libraries = _fsState._partToLibraries[this];
516+
if (libraries != null) {
517+
for (var library in libraries) {
518+
library.libraryCycle?.invalidate();
519+
}
520+
}
521+
513522
for (FileState file in _fsState._uriToFile.values) {
514523
file._exportedTopLevelDeclarations = null;
515524
}

pkg/analyzer/test/src/dart/analysis/driver_test.dart

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2781,6 +2781,32 @@ var b = new B();
27812781
expect(_getTopLevelVarType(result.unit, 'b'), 'B');
27822782
}
27832783

2784+
test_part_getResult_changePart_invalidatesLibraryCycle() async {
2785+
var a = convertPath('/test/lib/a.dart');
2786+
var b = convertPath('/test/lib/b.dart');
2787+
newFile(a, content: r'''
2788+
import 'dart:async';
2789+
part 'b.dart';
2790+
''');
2791+
driver.addFile(a);
2792+
2793+
// Analyze the library without the part.
2794+
await driver.getResult(a);
2795+
2796+
// Create the part file.
2797+
// This should invalidate library file state (specifically the library
2798+
// cycle), so that we can re-link the library, and get new dependencies.
2799+
newFile(b, content: r'''
2800+
part of 'a.dart';
2801+
Future<int> f;
2802+
''');
2803+
driver.changeFile(b);
2804+
2805+
// This should not crash.
2806+
var result = await driver.getResult(b);
2807+
expect(result.errors, isEmpty);
2808+
}
2809+
27842810
test_part_getResult_noLibrary() async {
27852811
var c = convertPath('/test/lib/c.dart');
27862812
newFile(c, content: r'''

0 commit comments

Comments
 (0)