Skip to content

Commit

Permalink
Issue 53335. Extension types. Ignore external fields.
Browse files Browse the repository at this point in the history
Bug: #53335
Change-Id: Idccb2bbd6b72c8293ab3a89ac0b327c21b94becd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/322982
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
  • Loading branch information
scheglov authored and Commit Queue committed Aug 28, 2023
1 parent 7acb650 commit 52143ec
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
5 changes: 3 additions & 2 deletions pkg/analyzer/lib/src/error/duplicate_definition_verifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,10 @@ class DuplicateDefinitionVerifier {
if (declarationElement == null) return;

final primaryConstructorName = element.constructors.first.name;
final representationGetter = element.representation.getter!;
_getElementContext(declarationElement)
.constructorNames
.add(primaryConstructorName);
..constructorNames.add(primaryConstructorName)
..instanceGetters[representationGetter.name] = representationGetter;

_checkClassMembers(element, node.members);
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/analyzer/lib/src/generated/error_verifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2870,7 +2870,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
return;
}

if (node.isStatic) {
if (node.isStatic || node.externalKeyword != null) {
return;
}

Expand Down
30 changes: 30 additions & 0 deletions pkg/analyzer/test/src/diagnostics/duplicate_definition_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1222,6 +1222,36 @@ extension type E(int it) {
]);
}

test_instance_representation_getter() async {
await assertErrorsInCode(r'''
extension type E(int it) {
int get it => 0;
}
''', [
error(CompileTimeErrorCode.DUPLICATE_DEFINITION, 37, 2,
contextMessages: [message('/home/test/lib/test.dart', 21, 2)]),
]);
}

test_instance_representation_method() async {
await assertErrorsInCode(r'''
extension type E(int it) {
void it() {}
}
''', [
error(CompileTimeErrorCode.DUPLICATE_DEFINITION, 34, 2,
contextMessages: [message('/home/test/lib/test.dart', 21, 2)]),
]);
}

test_instance_representation_setter() async {
await assertNoErrorsInCode(r'''
extension type E(int it) {
set it(int _) {}
}
''');
}

test_instance_setter_getter() async {
await assertNoErrorsInCode(r'''
extension type E(int it) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ extension type E(int it) {
]);
}

test_instance_field_external() async {
await assertNoErrorsInCode('''
extension type E(int it) {
external int foo;
}
''');
}

test_instance_getter() async {
await assertNoErrorsInCode('''
extension type E(int it) {
Expand Down

0 comments on commit 52143ec

Please sign in to comment.