mirror of
https://github.com/dart-lang/sdk
synced 2024-09-04 16:03:44 +00:00
Extension type. Issue 53625. Fixes for analyzer expectations.
Bug: https://github.com/dart-lang/sdk/issues/53625 Change-Id: I17994508f2e50c63d656d89e102c8a0d06e45d96 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/329821 Commit-Queue: Konstantin Shcheglov <scheglov@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
5c9c383224
commit
879f82acc9
|
@ -2811,10 +2811,12 @@ class AstBuilder extends StackListener {
|
|||
break;
|
||||
}
|
||||
if (firstFormalParameter.keyword case final keyword?) {
|
||||
errorReporter.errorReporter?.reportErrorForToken(
|
||||
ParserErrorCode.REPRESENTATION_FIELD_MODIFIER,
|
||||
keyword,
|
||||
);
|
||||
if (keyword.keyword != Keyword.CONST) {
|
||||
errorReporter.errorReporter?.reportErrorForToken(
|
||||
ParserErrorCode.REPRESENTATION_FIELD_MODIFIER,
|
||||
keyword,
|
||||
);
|
||||
}
|
||||
}
|
||||
fieldName = firstFormalParameter.name!;
|
||||
// Check for multiple fields.
|
||||
|
|
|
@ -15,6 +15,31 @@ main() {
|
|||
|
||||
@reflectiveTest
|
||||
class ExtensionTypeDeclarationParserTest extends ParserDiagnosticsTest {
|
||||
test_error_fieldModifier_const() {
|
||||
final parseResult = parseStringWithErrors(r'''
|
||||
extension type A(const int it) {}
|
||||
''');
|
||||
parseResult.assertErrors([
|
||||
error(ParserErrorCode.EXTRANEOUS_MODIFIER, 17, 5),
|
||||
]);
|
||||
|
||||
final node = parseResult.findNode.singleExtensionTypeDeclaration;
|
||||
assertParsedNodeText(node, r'''
|
||||
ExtensionTypeDeclaration
|
||||
extensionKeyword: extension
|
||||
typeKeyword: type
|
||||
name: A
|
||||
representation: RepresentationDeclaration
|
||||
leftParenthesis: (
|
||||
fieldType: NamedType
|
||||
name: int
|
||||
fieldName: it
|
||||
rightParenthesis: )
|
||||
leftBracket: {
|
||||
rightBracket: }
|
||||
''');
|
||||
}
|
||||
|
||||
test_error_fieldModifier_final() {
|
||||
final parseResult = parseStringWithErrors(r'''
|
||||
extension type A(final int it) {}
|
||||
|
@ -40,6 +65,56 @@ ExtensionTypeDeclaration
|
|||
''');
|
||||
}
|
||||
|
||||
test_error_fieldModifier_required() {
|
||||
final parseResult = parseStringWithErrors(r'''
|
||||
extension type A(required int it) {}
|
||||
''');
|
||||
parseResult.assertErrors([
|
||||
error(ParserErrorCode.EXTRANEOUS_MODIFIER, 17, 8),
|
||||
]);
|
||||
|
||||
final node = parseResult.findNode.singleExtensionTypeDeclaration;
|
||||
assertParsedNodeText(node, r'''
|
||||
ExtensionTypeDeclaration
|
||||
extensionKeyword: extension
|
||||
typeKeyword: type
|
||||
name: A
|
||||
representation: RepresentationDeclaration
|
||||
leftParenthesis: (
|
||||
fieldType: NamedType
|
||||
name: int
|
||||
fieldName: it
|
||||
rightParenthesis: )
|
||||
leftBracket: {
|
||||
rightBracket: }
|
||||
''');
|
||||
}
|
||||
|
||||
test_error_fieldModifier_static() {
|
||||
final parseResult = parseStringWithErrors(r'''
|
||||
extension type A(static int it) {}
|
||||
''');
|
||||
parseResult.assertErrors([
|
||||
error(ParserErrorCode.EXTRANEOUS_MODIFIER, 17, 6),
|
||||
]);
|
||||
|
||||
final node = parseResult.findNode.singleExtensionTypeDeclaration;
|
||||
assertParsedNodeText(node, r'''
|
||||
ExtensionTypeDeclaration
|
||||
extensionKeyword: extension
|
||||
typeKeyword: type
|
||||
name: A
|
||||
representation: RepresentationDeclaration
|
||||
leftParenthesis: (
|
||||
fieldType: NamedType
|
||||
name: int
|
||||
fieldName: it
|
||||
rightParenthesis: )
|
||||
leftBracket: {
|
||||
rightBracket: }
|
||||
''');
|
||||
}
|
||||
|
||||
test_error_multipleFields() {
|
||||
final parseResult = parseStringWithErrors(r'''
|
||||
extension type A(int a, String b) {}
|
||||
|
@ -115,6 +190,31 @@ ExtensionTypeDeclaration
|
|||
''');
|
||||
}
|
||||
|
||||
test_error_superFormalParameter() {
|
||||
final parseResult = parseStringWithErrors(r'''
|
||||
extension type A(super.it) {}
|
||||
''');
|
||||
parseResult.assertErrors([
|
||||
error(ParserErrorCode.EXPECTED_REPRESENTATION_FIELD, 17, 5),
|
||||
]);
|
||||
|
||||
final node = parseResult.findNode.singleExtensionTypeDeclaration;
|
||||
assertParsedNodeText(node, r'''
|
||||
ExtensionTypeDeclaration
|
||||
extensionKeyword: extension
|
||||
typeKeyword: type
|
||||
name: A
|
||||
representation: RepresentationDeclaration
|
||||
leftParenthesis: (
|
||||
fieldType: NamedType
|
||||
name: <empty> <synthetic>
|
||||
fieldName: <empty> <synthetic>
|
||||
rightParenthesis: )
|
||||
leftBracket: {
|
||||
rightBracket: }
|
||||
''');
|
||||
}
|
||||
|
||||
test_error_trailingComma() {
|
||||
final parseResult = parseStringWithErrors(r'''
|
||||
extension type A(int it,) {}
|
||||
|
|
|
@ -51,7 +51,7 @@ extension type E05(covariant int x) {}
|
|||
|
||||
extension type E06(required int x) {}
|
||||
// ^^^^^^^^
|
||||
// [analyzer] SYNTACTIC_ERROR.REPRESENTATION_FIELD_MODIFIER
|
||||
// [analyzer] SYNTACTIC_ERROR.EXTRANEOUS_MODIFIER
|
||||
// [cfe] unspecified
|
||||
|
||||
extension type E07(int this.x) {} // Initializing formal.
|
||||
|
@ -70,8 +70,9 @@ extension type E09(int super.x) implements E {} // Constructor super-parameter.
|
|||
// [cfe] unspecified
|
||||
|
||||
extension type E10(super.x) implements E {} // Constructor super-parameter.
|
||||
// ^^^^^^^
|
||||
// ^^^^^
|
||||
// [analyzer] SYNTACTIC_ERROR.EXPECTED_REPRESENTATION_FIELD
|
||||
// ^^^^^^^
|
||||
// [cfe] unspecified
|
||||
|
||||
extension type E11(int x()) {} // Old-style function parameter syntax.
|
||||
|
@ -84,7 +85,7 @@ extension type E11(int x()) {} // Old-style function parameter syntax.
|
|||
|
||||
extension type E12(late int x) {}
|
||||
// ^^^^
|
||||
// [analyzer] SYNTACTIC_ERROR.REPRESENTATION_FIELD_MODIFIER
|
||||
// [analyzer] SYNTACTIC_ERROR.EXTRANEOUS_MODIFIER
|
||||
// [cfe] unspecified
|
||||
|
||||
extension type E13(int x = 0) {}
|
||||
|
@ -94,12 +95,12 @@ extension type E13(int x = 0) {}
|
|||
|
||||
extension type E14(static int x) {}
|
||||
// ^^^^^^
|
||||
// [analyzer] SYNTACTIC_ERROR.REPRESENTATION_FIELD_MODIFIER
|
||||
// [analyzer] SYNTACTIC_ERROR.EXTRANEOUS_MODIFIER
|
||||
// [cfe] unspecified
|
||||
|
||||
extension type const E15(const int x) {}
|
||||
// ^^^^^
|
||||
// [analyzer] SYNTACTIC_ERROR.REPRESENTATION_FIELD_MODIFIER
|
||||
// [analyzer] SYNTACTIC_ERROR.EXTRANEOUS_MODIFIER
|
||||
// [cfe] unspecified
|
||||
|
||||
// Precisely one parameter is allowed and required.
|
||||
|
|
Loading…
Reference in a new issue