Let a part have its own LibraryCycle if requested.

Change-Id: Ic724342040f951cfc670a6daa3e6be08e33d2fc2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/213531
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Konstantin Shcheglov 2021-09-15 22:55:06 +00:00 committed by commit-bot@chromium.org
parent 7015c192ab
commit 532214b033
2 changed files with 31 additions and 7 deletions

View file

@ -259,13 +259,6 @@ class FileState {
/// Return the [LibraryCycle] this file belongs to, even if it consists of
/// just this file. If the library cycle is not known yet, compute it.
LibraryCycle get libraryCycle {
if (isPart) {
final library = this.library;
if (library != null && !identical(library, this)) {
return library.libraryCycle;
}
}
if (_libraryCycle == null) {
computeLibraryCycle(_fsState._saltForElements, this);
}

View file

@ -498,6 +498,7 @@ class D implements C {}
// It's a cycle.
_assertLibraryCycle(fa, [fa, fb], []);
_assertLibraryCycle(fb, [fa, fb], []);
expect(fa.libraryCycle, same(fb.libraryCycle));
// Update a.dart so that it does not import b.dart anymore.
newFile(pa);
@ -520,6 +521,36 @@ part 'a.dart';
_assertLibraryCycle(fa, [fa], []);
}
test_libraryCycle_part() {
var a_path = convertPath('/aaa/lib/a.dart');
var b_path = convertPath('/aaa/lib/b.dart');
newFile(a_path, content: r'''
part 'b.dart';
''');
newFile(b_path, content: r'''
part of 'a.dart';
''');
var a_file = fileSystemState.getFileForPath(a_path);
var b_file = fileSystemState.getFileForPath(b_path);
_assertFilesWithoutLibraryCycle([a_file, b_file]);
// Compute the library cycle for 'a.dart', the library.
var a_libraryCycle = a_file.libraryCycle;
_assertFilesWithoutLibraryCycle([b_file]);
// The part 'b.dart' has its own library cycle.
// If the user chooses to import a part, it is a compile-time error.
// We could handle this in different ways:
// 1. Completely ignore an import of a file with a `part of` directive.
// 2. Treat such file as a library anyway.
// By giving a part its own library cycle we support (2).
var b_libraryCycle = b_file.libraryCycle;
expect(b_libraryCycle, isNot(same(a_libraryCycle)));
_assertFilesWithoutLibraryCycle([]);
}
test_referencedNames() {
String path = convertPath('/aaa/lib/a.dart');
newFile(path, content: r'''