Skip to content

Commit

Permalink
Extension type. Issue 54593. Report ParserErrorCode.MEMBER_WITH_CLASS…
Browse files Browse the repository at this point in the history
…_NAME for the representation field.

Bug: #54593
Change-Id: Ia8f6d6b78f4a49d20c5573e8fa31115c5dbda415
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/345829
Reviewed-by: Phil Quitslund <[email protected]>
Commit-Queue: Konstantin Shcheglov <[email protected]>
Reviewed-by: Brian Wilkerson <[email protected]>
  • Loading branch information
scheglov authored and Commit Queue committed Jan 16, 2024
1 parent 66d3eed commit e9983a5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/analyzer/lib/src/fasta/ast_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1656,6 +1656,14 @@ class AstBuilder extends StackListener {
rightParenthesis: rightParenthesis,
);
}
// Check for extension type name conflict.
var representationName = representation.fieldName;
if (representationName.lexeme == builder.name.lexeme) {
errorReporter.errorReporter?.reportErrorForToken(
ParserErrorCode.MEMBER_WITH_CLASS_NAME,
representationName,
);
}
declarations.add(
builder.build(
typeKeyword: typeKeyword,
Expand Down
25 changes: 25 additions & 0 deletions pkg/analyzer/test/src/dart/parser/extension_type_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,31 @@ ExtensionTypeDeclaration
''');
}

test_error_fieldName_asDeclaration() {
final parseResult = parseStringWithErrors(r'''
extension type A(int A) {}
''');
parseResult.assertErrors([
error(ParserErrorCode.MEMBER_WITH_CLASS_NAME, 21, 1),
]);

final node = parseResult.findNode.singleExtensionTypeDeclaration;
assertParsedNodeText(node, r'''
ExtensionTypeDeclaration
extensionKeyword: extension
typeKeyword: type
name: A
representation: RepresentationDeclaration
leftParenthesis: (
fieldType: NamedType
name: int
fieldName: A
rightParenthesis: )
leftBracket: {
rightBracket: }
''');
}

test_error_formalParameterModifier_covariant_method_instance() {
final parseResult = parseStringWithErrors(r'''
extension type A(int it) {
Expand Down

0 comments on commit e9983a5

Please sign in to comment.