Skip to content

Commit

Permalink
Parts. Consider 'part' of 'part of lib.name' as an error.
Browse files Browse the repository at this point in the history
Maybe? dart-lang/co19#2907

Change-Id: If64ba74bf8d3ad3f5e1b926f19705ae469c76a5b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/387820
Commit-Queue: Konstantin Shcheglov <[email protected]>
Reviewed-by: Brian Wilkerson <[email protected]>
  • Loading branch information
scheglov authored and Commit Queue committed Oct 2, 2024
1 parent 07e7ec4 commit 4fe2944
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5025,7 +5025,6 @@ suggestions

Future<void> test_partFile_typeName() async {
newFile('$testPackageLibPath/b.dart', '''
library B;
int T0 = 0;
F0() {}
class X {
Expand All @@ -5037,14 +5036,13 @@ class X {
}
''');
newFile('$testPackageLibPath/a.dart', '''
library libA;
import 'b.dart';
part "test.dart";
class A0 {}
var m0 = T0;
''');
await computeSuggestions('''
part of libA;
part of 'a.dart';
class B {
B.bar(int x);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,11 @@ suggestions
Future<void> test_beforeRightBrace_deferred_inPart() async {
allowedIdentifiers = {'Future', 'loadLibrary'};
newFile('$testPackageLibPath/a.dart', '''
library testA;
import "dart:async" deferred as bar;
part "test.dart";
''');
await computeSuggestions('''
part of testA;
part of 'a.dart';
f0() {
bar.^
}
Expand Down Expand Up @@ -284,14 +283,13 @@ class X0 {}
class Y0 {}
''');
newFile('$testPackageLibPath/a.dart', '''
library testA;
import "b.dart" as b0;
part "test.dart";
var T2;
class A0 {}
''');
await computeSuggestions('''
part of testA;
part of 'a.dart';
void f() {
b0.^
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,6 @@ class C {
newFile(testFilePath, 'part of testB;');
newFile('$testPackageLibPath/b.dart', '''
// ignore_for_file: unused_import
library testB;
import "a.dart" as t0;
import "dart:math" as m0;
part "test.dart";
Expand All @@ -363,7 +362,7 @@ void f() {
}
''');
await computeSuggestions('''
part of testB;
part of 'b.dart';
void f() {
new ^
String x = "hello";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4188,7 +4188,6 @@ suggestions

Future<void> test_partFile_TypeName() async {
newFile('$testPackageLibPath/b.dart', '''
library B;
int T0 = 0;
F0() {}
class X {
Expand All @@ -4200,14 +4199,13 @@ class X {
}
''');
newFile('$testPackageLibPath/a.dart', '''
library libA;
import "b.dart";
part "${resourceProvider.pathContext.basename(testFile.path)}";
class A0 {}
var m0 = T0;
''');
await computeSuggestions('''
part of libA;
part of 'a.dart';
class B {
B.bar(int x);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@ void f(A a, B b) {

Future<void> test_createChange_outsideOfProject_referenceInPart() async {
newFile('/home/part.dart', r'''
part of test;
part of 'test/bin/test.dart';
void foo(A a) {
a.test();
Expand All @@ -995,8 +995,6 @@ void foo(A a) {
testFilePath = convertPath('/home/test/bin/test.dart');

await indexTestUnit('''
library test;
part '../../part.dart';
class A {
Expand All @@ -1011,8 +1009,6 @@ void f(A a) {
refactoring.newName = 'newName';

await assertSuccessfulRefactoring('''
library test;
part '../../part.dart';
class A {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ void main() {
class RenameLibraryTest extends RenameRefactoringTest {
Future<void> test_checkNewName() async {
await indexTestUnit('''
// @dart = 3.4
library my.app;
''');
_createRenameRefactoring();
Expand All @@ -36,9 +37,11 @@ library my.app;

Future<void> test_createChange() async {
newFile('$testPackageLibPath/part.dart', '''
// @dart = 3.4
part of my.app;
''');
await indexTestUnit('''
// @dart = 3.4
library my.app;
part 'part.dart';
''');
Expand All @@ -49,19 +52,23 @@ part 'part.dart';
refactoring.newName = 'the.new.name';
// validate change
await assertSuccessfulRefactoring('''
// @dart = 3.4
library the.new.name;
part 'part.dart';
''');
assertFileChangeResult('$testPackageLibPath/part.dart', '''
// @dart = 3.4
part of the.new.name;
''');
}

Future<void> test_createChange_hasWhitespaces() async {
newFile('$testPackageLibPath/part.dart', '''
// @dart = 3.4
part of my . app;
''');
await indexTestUnit('''
// @dart = 3.4
library my . app;
part 'part.dart';
''');
Expand All @@ -72,10 +79,12 @@ part 'part.dart';
refactoring.newName = 'the.new.name';
// validate change
await assertSuccessfulRefactoring('''
// @dart = 3.4
library the.new.name;
part 'part.dart';
''');
assertFileChangeResult('$testPackageLibPath/part.dart', '''
// @dart = 3.4
part of the.new.name;
''');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ foo() {}

Future<void> test_createChange_outsideOfProject_referenceInPart() async {
newFile('/home/part.dart', r'''
part of test;
part of 'test/bin/test.dart';
Test test2;
''');
Expand All @@ -803,8 +803,6 @@ Test test2;
testFilePath = convertPath('/home/test/bin/test.dart');

await indexTestUnit('''
library test;
part '../../part.dart';
class Test {}
Expand All @@ -815,8 +813,6 @@ void f(Test a) {}
refactoring.newName = 'NewName';

await assertSuccessfulRefactoring('''
library test;
part '../../part.dart';
class NewName {}
Expand Down
6 changes: 1 addition & 5 deletions pkg/analyzer/messages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4102,15 +4102,13 @@ CompileTimeErrorCode:

```dart
%uri="lib/part.dart"
part of lib;
part of 'test.dart';
```

The following code produces this diagnostic because the file `part.dart` is
included multiple times:

```dart
library lib;

part 'part.dart';
part [!'part.dart'!];
```
Expand All @@ -4120,8 +4118,6 @@ CompileTimeErrorCode:
Remove all except the first of the duplicated part directives:

```dart
library lib;

part 'part.dart';
```
DUPLICATE_PATTERN_ASSIGNMENT_VARIABLE:
Expand Down
6 changes: 4 additions & 2 deletions pkg/analyzer/test/generated/non_error_resolver_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,12 @@ main() {

test_annotated_partOfDeclaration() async {
newFile('$testPackageLibPath/part.dart', '''
@deprecated part of L;
@deprecated
part of 'test.dart';
''');

await assertNoErrorsInCode('''
library L; part "part.dart";
part "part.dart";
''');
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/analyzer/test/src/dart/resolution/part_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -545,18 +545,18 @@ PartDirective

test_inLibrary_withPart_partOfName() async {
var a = newFile('$testPackageLibPath/a.dart', r'''
// @dart = 3.4
library my.lib;
part 'b.dart';
''');

var b = newFile('$testPackageLibPath/b.dart', r'''
// @dart = 3.4
part of my.lib;
''');

await resolveFile2(b);
assertErrorsInResult([
error(ParserErrorCode.PART_OF_NAME, 8, 6),
]);
assertNoErrorsInResult();

await resolveFile2(a);
assertNoErrorsInResult();
Expand Down
23 changes: 14 additions & 9 deletions pkg/analyzer/test/src/diagnostics/duplicate_part_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,41 @@ main() {
@reflectiveTest
class DuplicatePartTest extends PubPackageResolutionTest {
test_library_sameSource() async {
newFile('$testPackageLibPath/part.dart', 'part of lib;');
newFile('$testPackageLibPath/part.dart', r'''
part of 'test.dart';
''');

await assertErrorsInCode(r'''
library lib;
part 'part.dart';
part 'foo/../part.dart';
''', [
error(CompileTimeErrorCode.DUPLICATE_PART, 36, 18),
error(CompileTimeErrorCode.DUPLICATE_PART, 23, 18),
]);
}

test_library_sameUri() async {
newFile('$testPackageLibPath/part.dart', 'part of lib;');
newFile('$testPackageLibPath/part.dart', r'''
part of 'test.dart';
''');

await assertErrorsInCode(r'''
library lib;
part 'part.dart';
part 'part.dart';
''', [
error(CompileTimeErrorCode.DUPLICATE_PART, 36, 11),
error(CompileTimeErrorCode.DUPLICATE_PART, 23, 11),
]);
}

test_no_duplicates() async {
newFile('$testPackageLibPath/part1.dart', '''
part of lib;
part of 'test.dart';
''');

newFile('$testPackageLibPath/part2.dart', '''
part of lib;
part of 'test.dart';
''');

await assertNoErrorsInCode(r'''
library lib;
part 'part1.dart';
part 'part2.dart';
''');
Expand Down
14 changes: 13 additions & 1 deletion pkg/analyzer/test/src/diagnostics/part_of_non_part_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ main() {

@reflectiveTest
class PartOfNonPartTest extends PubPackageResolutionTest {
test_part_of_non_part() async {
test_noPartOf() async {
newFile('$testPackageLibPath/l2.dart', '''
library l2;
''');
Expand All @@ -27,6 +27,18 @@ part 'l2.dart';
]);
}

test_partOf_dotted() async {
newFile('$testPackageLibPath/a.dart', '''
part of foo.bar;
''');

// No error reported in the library, only in the part.
await assertNoErrorsInCode(r'''
library foo.bar;
part 'a.dart';
''');
}

test_self() async {
await assertErrorsInCode(r'''
library lib;
Expand Down
6 changes: 1 addition & 5 deletions pkg/analyzer/tool/diagnostics/diagnostics.md
Original file line number Diff line number Diff line change
Expand Up @@ -4887,15 +4887,13 @@ multiple part directives.
Given a file `part.dart` containing

```dart
part of lib;
part of 'test.dart';
```

The following code produces this diagnostic because the file `part.dart` is
included multiple times:

```dart
library lib;

part 'part.dart';
part [!'part.dart'!];
```
Expand All @@ -4905,8 +4903,6 @@ part [!'part.dart'!];
Remove all except the first of the duplicated part directives:

```dart
library lib;

part 'part.dart';
```

Expand Down

0 comments on commit 4fe2944

Please sign in to comment.