Skip to content

Commit fc9f7e3

Browse files
chloestefantsovaCommit Bot
authored and
Commit Bot
committed
[parser] Add support for typed super-initializer parameters
Part of #47525 Closes #47741 Bug: #47741 Change-Id: I0558b33aa43cc73e67ca0d17bd5c8ec1afdc526f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/221634 Commit-Queue: Chloe Stefantsova <[email protected]> Reviewed-by: Johnni Winther <[email protected]>
1 parent 7da2117 commit fc9f7e3

16 files changed

+723
-173
lines changed

pkg/_fe_analyzer_shared/lib/src/parser/type_info_impl.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ class VoidType implements TypeInfo {
451451
bool looksLikeName(Token token) {
452452
return token.kind == IDENTIFIER_TOKEN ||
453453
optional('this', token) ||
454+
optional('super', token) ||
454455
(token.isIdentifier &&
455456
// Although `typedef` is a legal identifier,
456457
// type `typedef` identifier is not legal and in this situation
@@ -794,7 +795,9 @@ class ComplexTypeInfo implements TypeInfo {
794795
if (optional('?', next)) {
795796
next = next.next!;
796797
}
797-
if (!(next.isIdentifier || optional('this', next))) {
798+
if (!(next.isIdentifier ||
799+
optional('this', next) ||
800+
optional('super', next))) {
798801
break; // `Function` used as the name in a function declaration.
799802
}
800803
}

pkg/analyzer/test/generated/utilities_test.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2120,7 +2120,6 @@ void f() {
21202120
node, Getter_NodeReplacerTest_test_superConstructorInvocation_2());
21212121
}
21222122

2123-
@FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/47741')
21242123
void test_superFormalParameter() {
21252124
var findNode = _parseStringToFindNode(r'''
21262125
class A {

pkg/front_end/parser_testcases/error_recovery/keyword_named_class_fields.dart.intertwined.expect

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,28 +1471,27 @@ parseUnit(class)
14711471
listener: beginMetadataStar(int)
14721472
listener: endMetadataStar(0)
14731473
listener: beginMember()
1474-
isReservedKeyword(super)
1475-
indicatesMethodOrField(=)
1476-
parseFields(;, null, null, null, null, null, null, ;, Instance of 'SimpleType', super, DeclarationKind.Class, WrapperClass, true)
1477-
listener: beginFields(DeclarationKind.Class, null, null, null, null, null, null, ;)
1478-
listener: handleIdentifier(int, typeReference)
1479-
listener: handleNoTypeArguments(super)
1480-
listener: handleType(int, null)
1481-
ensureIdentifierPotentiallyRecovered(int, fieldDeclaration, true)
1482-
reportRecoverableErrorWithToken(super, Instance of 'Template<(Token) => Message>')
1483-
listener: handleRecoverableError(Message[ExpectedIdentifierButGotKeyword, 'super' can't be used as an identifier because it's a keyword., Try renaming this to be an identifier that isn't a keyword., {lexeme: super}], super, super)
1484-
listener: handleIdentifier(super, fieldDeclaration)
1485-
parseFieldInitializerOpt(super, super, null, null, null, null, DeclarationKind.Class, WrapperClass)
1486-
listener: beginFieldInitializer(=)
1487-
parseExpression(=)
1488-
parsePrecedenceExpression(=, 1, true)
1489-
parseUnaryExpression(=, true)
1490-
parsePrimary(=, expression)
1491-
parseLiteralInt(=)
1492-
listener: handleLiteralInt(42)
1493-
listener: endFieldInitializer(=, ;)
1494-
listener: endClassFields(null, null, null, null, null, null, 1, int, ;)
1495-
listener: endMember()
1474+
recoverFromInvalidMember(int, ;, null, null, null, null, null, null, ;, Instance of 'SimpleType', null, DeclarationKind.Class, WrapperClass)
1475+
parseFields(;, null, null, null, null, null, null, ;, Instance of 'SimpleType', super, DeclarationKind.Class, WrapperClass, false)
1476+
listener: beginFields(DeclarationKind.Class, null, null, null, null, null, null, ;)
1477+
listener: handleIdentifier(int, typeReference)
1478+
listener: handleNoTypeArguments(super)
1479+
listener: handleType(int, null)
1480+
ensureIdentifierPotentiallyRecovered(int, fieldDeclaration, false)
1481+
reportRecoverableErrorWithToken(super, Instance of 'Template<(Token) => Message>')
1482+
listener: handleRecoverableError(Message[ExpectedIdentifierButGotKeyword, 'super' can't be used as an identifier because it's a keyword., Try renaming this to be an identifier that isn't a keyword., {lexeme: super}], super, super)
1483+
listener: handleIdentifier(super, fieldDeclaration)
1484+
parseFieldInitializerOpt(super, super, null, null, null, null, DeclarationKind.Class, WrapperClass)
1485+
listener: beginFieldInitializer(=)
1486+
parseExpression(=)
1487+
parsePrecedenceExpression(=, 1, true)
1488+
parseUnaryExpression(=, true)
1489+
parsePrimary(=, expression)
1490+
parseLiteralInt(=)
1491+
listener: handleLiteralInt(42)
1492+
listener: endFieldInitializer(=, ;)
1493+
listener: endClassFields(null, null, null, null, null, null, 1, int, ;)
1494+
listener: endMember()
14961495
notEofOrValue(}, int)
14971496
parseClassOrMixinOrExtensionOrEnumMemberImpl(;, DeclarationKind.Class, WrapperClass)
14981497
parseMetadataStar(;)

pkg/front_end/parser_testcases/error_recovery/keyword_named_class_methods.dart.expect

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,14 @@ parser/error_recovery/keyword_named_class_methods:282:7: 'super' can't be used a
308308
int super(int x) {
309309
^^^^^
310310

311+
parser/error_recovery/keyword_named_class_methods:282:7: Expected ';' after this.
312+
int super(int x) {
313+
^^^^^
314+
315+
parser/error_recovery/keyword_named_class_methods:282:12: Expected an identifier, but got '('.
316+
int super(int x) {
317+
^
318+
311319
parser/error_recovery/keyword_named_class_methods:287:7: 'switch' can't be used as an identifier because it's a keyword.
312320
int switch(int x) {
313321
^^^^^^
@@ -3883,12 +3891,23 @@ beginCompilationUnit(class)
38833891
beginMetadataStar(int)
38843892
endMetadataStar(0)
38853893
beginMember()
3886-
beginMethod(DeclarationKind.Class, null, null, null, null, null, super)
3894+
beginFields(DeclarationKind.Class, null, null, null, null, null, null, })
38873895
handleIdentifier(int, typeReference)
38883896
handleNoTypeArguments(super)
38893897
handleType(int, null)
38903898
handleRecoverableError(Message[ExpectedIdentifierButGotKeyword, 'super' can't be used as an identifier because it's a keyword., Try renaming this to be an identifier that isn't a keyword., {lexeme: super}], super, super)
3891-
handleIdentifier(super, methodDeclaration)
3899+
handleIdentifier(super, fieldDeclaration)
3900+
handleNoFieldInitializer(()
3901+
handleRecoverableError(Message[ExpectedAfterButGot, Expected ';' after this., null, {string: ;}], super, super)
3902+
endClassFields(null, null, null, null, null, null, 1, int, ;)
3903+
endMember()
3904+
beginMetadataStar(()
3905+
endMetadataStar(0)
3906+
beginMember()
3907+
beginMethod(DeclarationKind.Class, null, null, null, null, null, ()
3908+
handleNoType(;)
3909+
handleRecoverableError(Message[ExpectedIdentifier, Expected an identifier, but got '('., Try inserting an identifier before '('., {lexeme: (}], (, ()
3910+
handleIdentifier(, methodDeclaration)
38923911
handleNoTypeVariables(()
38933912
beginFormalParameters((, MemberKind.NonStaticMethod)
38943913
beginMetadataStar(int)
@@ -3937,7 +3956,7 @@ beginCompilationUnit(class)
39373956
endBinaryExpression(+)
39383957
endReturnStatement(true, return, ;)
39393958
endBlockFunctionBody(2, {, })
3940-
endClassMethod(null, int, (, null, })
3959+
endClassMethod(null, , (, null, })
39413960
endMember()
39423961
beginMetadataStar(int)
39433962
endMetadataStar(0)
@@ -4743,7 +4762,7 @@ beginCompilationUnit(class)
47434762
endBlockFunctionBody(2, {, })
47444763
endClassMethod(null, int, (, null, })
47454764
endMember()
4746-
endClassOrMixinOrExtensionBody(DeclarationKind.Class, 70, {, })
4765+
endClassOrMixinOrExtensionBody(DeclarationKind.Class, 71, {, })
47474766
endClassDeclaration(class, })
47484767
endTopLevelDeclaration()
47494768
endCompilationUnit(1, )

0 commit comments

Comments
 (0)