Skip to content

Commit 26f2ff4

Browse files
scheglovCommit Queue
authored andcommitted
Parts. Prefer the first 'part of uri' directive if multiple.
Related to co19/LanguageFeatures/Parts-with-imports/grammar_A04_t01 Change-Id: I20402b8c51fe8167efdb9d6811fe5b41645418b5 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388980 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent 95d5e62 commit 26f2ff4

File tree

2 files changed

+66
-2
lines changed

2 files changed

+66
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,7 @@ class FileState {
10621062
var libraryName = directive.libraryName;
10631063
var uri = directive.uri;
10641064
if (libraryName != null) {
1065-
partOfNameDirective = UnlinkedPartOfNameDirective(
1065+
partOfNameDirective ??= UnlinkedPartOfNameDirective(
10661066
docImports: buildDocImports(directive),
10671067
name: libraryName.name,
10681068
nameRange: UnlinkedSourceRange(
@@ -1071,7 +1071,7 @@ class FileState {
10711071
),
10721072
);
10731073
} else if (uri != null) {
1074-
partOfUriDirective = UnlinkedPartOfUriDirective(
1074+
partOfUriDirective ??= UnlinkedPartOfUriDirective(
10751075
docImports: buildDocImports(directive),
10761076
uri: uri.stringValue,
10771077
uriRange: UnlinkedSourceRange(

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

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3008,6 +3008,70 @@ elementFactory
30083008
''');
30093009
}
30103010

3011+
test_newFile_partOfUri_duplicate() async {
3012+
var a = newFile('$testPackageLibPath/a.dart', r'''
3013+
part 'c.dart';
3014+
''');
3015+
3016+
var b = newFile('$testPackageLibPath/b.dart', r'''
3017+
part 'c.dart';
3018+
''');
3019+
3020+
var c = newFile('$testPackageLibPath/c.dart', r'''
3021+
part of 'a.dart';
3022+
part of 'b.dart';
3023+
''');
3024+
3025+
fileStateFor(a);
3026+
fileStateFor(b);
3027+
fileStateFor(c);
3028+
3029+
assertDriverStateString(testFile, r'''
3030+
files
3031+
/home/test/lib/a.dart
3032+
uri: package:test/a.dart
3033+
current
3034+
id: file_0
3035+
kind: library_0
3036+
libraryImports
3037+
library_3 dart:core synthetic
3038+
partIncludes
3039+
partOfUriKnown_2
3040+
fileKinds: library_0 partOfUriKnown_2
3041+
cycle_0
3042+
dependencies: dart:core
3043+
libraries: library_0
3044+
apiSignature_0
3045+
unlinkedKey: k00
3046+
/home/test/lib/b.dart
3047+
uri: package:test/b.dart
3048+
current
3049+
id: file_1
3050+
kind: library_1
3051+
libraryImports
3052+
library_3 dart:core synthetic
3053+
partIncludes
3054+
notPart file_2
3055+
fileKinds: library_1
3056+
cycle_1
3057+
dependencies: dart:core
3058+
libraries: library_1
3059+
apiSignature_1
3060+
unlinkedKey: k00
3061+
/home/test/lib/c.dart
3062+
uri: package:test/c.dart
3063+
current
3064+
id: file_2
3065+
kind: partOfUriKnown_2
3066+
uriFile: file_0
3067+
library: library_0
3068+
referencingFiles: file_0 file_1
3069+
unlinkedKey: k01
3070+
libraryCycles
3071+
elementFactory
3072+
''');
3073+
}
3074+
30113075
test_newFile_partOfUri_noRelativeUri() async {
30123076
var a = newFile('$testPackageLibPath/a.dart', r'''
30133077
part of ':net';

0 commit comments

Comments
 (0)