Extension type. Issue 54593. Report ParserErrorCode.MEMBER_WITH_CLASS_NAME for the representation field.

Bug: https://github.com/dart-lang/sdk/issues/54593
Change-Id: Ia8f6d6b78f4a49d20c5573e8fa31115c5dbda415
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/345829
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
Konstantin Shcheglov 2024-01-16 20:45:08 +00:00 committed by Commit Queue
parent 66d3eedb33
commit e9983a51b2
2 changed files with 33 additions and 0 deletions

View file

@ -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,

View file

@ -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) {