Skip to content

Commit 1bf33f5

Browse files
johnniwintherCommit Bot
authored andcommitted
[cfe] Change LibraryBuilder.origin to use effective origin
This updates the SourceLibraryBuilder.origin to return the effective origin library and not just the immediate origin. In case of an 'import augment' in a part file, the immediate origin is set to the part "library". Since the part is not a real library, the augmentation library should not (try to) depend on that library but instead the library containing the part. Change-Id: I8ca1345c2e7c5bef71a7a1f9bed41a3bc4e538d0 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/255256 Reviewed-by: Chloe Stefantsova <[email protected]> Commit-Queue: Johnni Winther <[email protected]>
1 parent 4ba6621 commit 1bf33f5

File tree

5 files changed

+29
-5
lines changed

5 files changed

+29
-5
lines changed

pkg/front_end/lib/src/fasta/builder/library_builder.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ abstract class LibraryBuilder implements ModifierBuilder {
4444

4545
List<Export> get exporters;
4646

47+
@override
48+
LibraryBuilder get origin;
49+
4750
abstract LibraryBuilder? partOfLibrary;
4851

4952
LibraryBuilder get nameOriginBuilder;
@@ -380,6 +383,6 @@ abstract class LibraryBuilderImpl extends ModifierBuilderImpl
380383

381384
@override
382385
StringBuffer printOn(StringBuffer buffer) {
383-
return buffer..write(name ?? (isPart ? fileUri : importUri));
386+
return buffer..write(isPart || isPatch ? fileUri : importUri);
384387
}
385388
}

pkg/front_end/lib/src/fasta/dill/dill_library_builder.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ class DillLibraryBuilder extends LibraryBuilderImpl {
8888
lazyExportScope.libraryBuilder = this;
8989
}
9090

91+
@override
92+
LibraryBuilder get origin => this;
93+
9194
void ensureLoaded() {
9295
if (!isReadyToBuild) throw new StateError("Not ready to build.");
9396
if (isBuilt && !isBuiltAndMarked) {

pkg/front_end/lib/src/fasta/source/source_library_builder.dart

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ class SourceLibraryBuilder extends LibraryBuilderImpl {
174174
@override
175175
final Library library;
176176

177-
final SourceLibraryBuilder? _origin;
177+
final SourceLibraryBuilder? _immediateOrigin;
178178

179179
final List<SourceFunctionBuilder> nativeMethods = <SourceFunctionBuilder>[];
180180

@@ -307,7 +307,7 @@ class SourceLibraryBuilder extends LibraryBuilderImpl {
307307
currentTypeParameterScopeBuilder = _libraryTypeParameterScopeBuilder,
308308
referencesFromIndexed =
309309
referencesFrom == null ? null : new IndexedLibrary(referencesFrom),
310-
_origin = origin,
310+
_immediateOrigin = origin,
311311
_omittedTypeDeclarationBuilders = omittedTypes,
312312
super(
313313
fileUri,
@@ -1587,7 +1587,16 @@ class SourceLibraryBuilder extends LibraryBuilderImpl {
15871587
}
15881588

15891589
@override
1590-
SourceLibraryBuilder get origin => _origin ?? this;
1590+
bool get isPatch => _immediateOrigin != null;
1591+
1592+
@override
1593+
SourceLibraryBuilder get origin {
1594+
SourceLibraryBuilder? origin = _immediateOrigin;
1595+
if (origin != null && origin.isPart) {
1596+
origin = origin.partOfLibrary as SourceLibraryBuilder;
1597+
}
1598+
return origin?.origin ?? this;
1599+
}
15911600

15921601
@override
15931602
Uri get importUri => library.importUri;

pkg/front_end/messages.status

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,7 @@ UndefinedExtensionSetter/example: Fail
888888
UnexpectedToken/part_wrapped_script1: Fail
889889
UnexpectedToken/script1: Fail
890890
UnmatchedAugmentationClassMember/analyzerCode: Fail
891-
UnmatchedAugmentationClassMember/example: Fail
891+
UnmatchedAugmentationClassMember/part_wrapped_script: Fail # Uses imports
892892
UnmatchedToken/part_wrapped_script1: Fail
893893
UnmatchedToken/part_wrapped_script3: Fail
894894
UnmatchedToken/script1: Fail

pkg/front_end/messages.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5622,6 +5622,15 @@ MacroClassNotDeclaredMacro:
56225622
UnmatchedAugmentationClassMember:
56235623
problemMessage: "Augmentation member '#name' doesn't match a member in the augmented class."
56245624
correctionMessage: "Try changing the name to an existing member or removing the 'augment' modifier."
5625+
experiments: macros
5626+
script:
5627+
main.dart:
5628+
import augment 'lib.dart';
5629+
class Class {}
5630+
lib.dart:
5631+
augment class Class {
5632+
augment void method() {}
5633+
}
56255634

56265635
NonAugmentationClassMemberConflict:
56275636
problemMessage: "Member '#name' conflicts with an existing member of the same name in the augmented class."

0 commit comments

Comments
 (0)