Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 691aa62

Browse files
author
Dart CI
committed
Version 2.19.0-134.0.dev
Merge commit 'bba453b798728548807d822c6af7de02e81f8daf' into 'dev'
2 parents 859e9bb + bba453b commit 691aa62

33 files changed

Lines changed: 6023 additions & 36 deletions

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ bool isModifier(Token token) {
2626
Token next = token.next!;
2727
Keyword? keyword = next.keyword;
2828
if (keyword == null && !next.isIdentifier || keyword == Keyword.IN) {
29+
// Record type is a possibility.
30+
if (optional("(", next) && next.endGroup!.next!.isIdentifier) {
31+
// We've seen [modifier] [record type] [identifier].
32+
return true;
33+
}
2934
return false;
3035
}
3136
}

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,19 @@ TypeParamOrArgInfo computeTypeParamOrArg(Token token,
373373
return simpleTypeArgument1GtEq;
374374
}
375375
} else if (optional('(', next)) {
376-
return noTypeParamOrArg;
376+
bool recordType = false;
377+
if (isPossibleRecordType(next)) {
378+
TypeInfo type = computeType(beginGroup, false);
379+
if (type is ComplexTypeInfo &&
380+
(type.recordType || type.gftReturnTypeHasRecordType) &&
381+
!type.recovered) {
382+
// Looks like a record type.
383+
recordType = true;
384+
}
385+
}
386+
if (!recordType) {
387+
return noTypeParamOrArg;
388+
}
377389
}
378390

379391
// TODO(danrubel): Consider adding additional const for common situations.

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

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -705,16 +705,36 @@ class ComplexTypeInfo implements TypeInfo {
705705
if (optional('?', next)) {
706706
next = next.next!;
707707
}
708-
if (!(next.isIdentifier)) {
709-
// This could for instance be `(int x, int y) {`.
710-
return noType;
708+
bool getOrSet = false;
709+
if (next.isKeyword &&
710+
(optional("get", next) || optional("set", next)) &&
711+
next.next!.isIdentifier) {
712+
getOrSet = true;
713+
next = next.next!;
711714
}
712-
Token afterIdentifier = next.next!;
713-
// TODO(jensj): Are there any other instances where it's a valid
714-
// (optional) record type?
715-
if (!isOneOfOrEof(afterIdentifier, const [";", "=", "(", ",", ")"])) {
716-
// This could for instance be `(int x, int y) async {`.
717-
return noType;
715+
if (next.isIdentifier) {
716+
Token afterIdentifier = next.next!;
717+
// TODO(jensj): Are there any other instances where it's a valid
718+
// (optional) record type?
719+
if (!isOneOfOrEof(afterIdentifier, const [";", "=", "(", ",", ")"])) {
720+
if (getOrSet && isOneOfOrEof(afterIdentifier, const ["=>", "{"])) {
721+
// With a getter/setter in the mix we can accept more stuff, e.g.
722+
// these would be fine:
723+
// - `(` unchecked content `)` `get` identifier `=>`.
724+
// - `(` unchecked content `)` `get` identifier `{`.
725+
// TODO(jensj): A setter would need parenthesis so technically
726+
// couldn't look like this, but I don't think any other valid thing
727+
// could either. Should we handle that specifically?
728+
} else {
729+
// This could for instance be `(int x, int y) async {`.
730+
return noType;
731+
}
732+
}
733+
} else {
734+
// Is it e.g. List<(int, int)> or Map<(int, int), (String, String)>?
735+
if (!isOneOfOrEof(next, const [",", ">"])) {
736+
return noType;
737+
}
718738
}
719739
}
720740
assert(optional(')', token));

pkg/analyzer/test/src/dart/resolution/record_type_annotation_test.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,6 @@ RecordTypeAnnotation
341341
''');
342342
}
343343

344-
@FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/49769')
345344
test_typeArgument() async {
346345
await assertNoErrorsInCode(r'''
347346
void f() {

pkg/front_end/parser_testcases/record/record_type_01.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,18 @@ void foo() {
1919
(int x, int y) async (int x, int y) {
2020
print("sync named async with record type return type taking 2 parameters");
2121
}
22+
23+
(int x, int y) async (int x, int y) => print("sync named async with record type return type taking 2 parameters");
2224

2325
(int x, int y) {
2426
print("sync unnamed taking 2 parameters");
2527
}();
2628

29+
(int x, int y) => print("sync unnamed taking 2 parameters");
30+
2731
(int x, int y) async {
2832
print("async unnamed taking 2 parameters");
2933
}();
34+
35+
(int x, int y) async => print("async unnamed taking 2 parameters");
3036
}

pkg/front_end/parser_testcases/record/record_type_01.dart.expect

Lines changed: 123 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,62 @@ beginCompilationUnit(void)
536536
handleExpressionStatement(;)
537537
endBlockFunctionBody(1, {, })
538538
endLocalFunctionDeclaration(})
539+
beginMetadataStar(()
540+
endMetadataStar(0)
541+
handleNoTypeVariables(()
542+
beginLocalFunctionDeclaration(()
543+
beginRecordType(()
544+
beginRecordTypeEntry()
545+
beginMetadataStar(int)
546+
endMetadataStar(0)
547+
handleIdentifier(int, typeReference)
548+
handleNoTypeArguments(x)
549+
handleType(int, null)
550+
handleIdentifier(x, recordFieldDeclaration)
551+
endRecordTypeEntry()
552+
beginRecordTypeEntry()
553+
beginMetadataStar(int)
554+
endMetadataStar(0)
555+
handleIdentifier(int, typeReference)
556+
handleNoTypeArguments(y)
557+
handleType(int, null)
558+
handleIdentifier(y, recordFieldDeclaration)
559+
endRecordTypeEntry()
560+
endRecordType((, null, 2, false)
561+
beginFunctionName(async)
562+
handleIdentifier(async, localFunctionDeclaration)
563+
endFunctionName((, ()
564+
beginFormalParameters((, MemberKind.Local)
565+
beginMetadataStar(int)
566+
endMetadataStar(0)
567+
beginFormalParameter(int, MemberKind.Local, null, null, null)
568+
handleIdentifier(int, typeReference)
569+
handleNoTypeArguments(x)
570+
handleType(int, null)
571+
handleIdentifier(x, formalParameterDeclaration)
572+
handleFormalParameterWithoutValue(,)
573+
endFormalParameter(null, null, null, x, null, null, FormalParameterKind.requiredPositional, MemberKind.Local)
574+
beginMetadataStar(int)
575+
endMetadataStar(0)
576+
beginFormalParameter(int, MemberKind.Local, null, null, null)
577+
handleIdentifier(int, typeReference)
578+
handleNoTypeArguments(y)
579+
handleType(int, null)
580+
handleIdentifier(y, formalParameterDeclaration)
581+
handleFormalParameterWithoutValue())
582+
endFormalParameter(null, null, null, y, null, null, FormalParameterKind.requiredPositional, MemberKind.Local)
583+
endFormalParameters(2, (, ), MemberKind.Local)
584+
handleNoInitializers()
585+
handleAsyncModifier(null, null)
586+
handleIdentifier(print, expression)
587+
handleNoTypeArguments(()
588+
beginArguments(()
589+
beginLiteralString("sync named async with record type return type taking 2 parameters")
590+
endLiteralString(0, ))
591+
endArguments(1, (, ))
592+
handleSend(print, ;)
593+
handleExpressionFunctionBody(=>, ;)
594+
endLocalFunctionDeclaration(;)
539595
handleNoTypeVariables(()
540596
beginFunctionExpression(()
541597
beginFormalParameters((, MemberKind.Local)
@@ -576,6 +632,39 @@ beginCompilationUnit(void)
576632
handleSend((, ))
577633
handleExpressionStatement(;)
578634
handleNoTypeVariables(()
635+
beginFunctionExpression(()
636+
beginFormalParameters((, MemberKind.Local)
637+
beginMetadataStar(int)
638+
endMetadataStar(0)
639+
beginFormalParameter(int, MemberKind.Local, null, null, null)
640+
handleIdentifier(int, typeReference)
641+
handleNoTypeArguments(x)
642+
handleType(int, null)
643+
handleIdentifier(x, formalParameterDeclaration)
644+
handleFormalParameterWithoutValue(,)
645+
endFormalParameter(null, null, null, x, null, null, FormalParameterKind.requiredPositional, MemberKind.Local)
646+
beginMetadataStar(int)
647+
endMetadataStar(0)
648+
beginFormalParameter(int, MemberKind.Local, null, null, null)
649+
handleIdentifier(int, typeReference)
650+
handleNoTypeArguments(y)
651+
handleType(int, null)
652+
handleIdentifier(y, formalParameterDeclaration)
653+
handleFormalParameterWithoutValue())
654+
endFormalParameter(null, null, null, y, null, null, FormalParameterKind.requiredPositional, MemberKind.Local)
655+
endFormalParameters(2, (, ), MemberKind.Local)
656+
handleAsyncModifier(null, null)
657+
handleIdentifier(print, expression)
658+
handleNoTypeArguments(()
659+
beginArguments(()
660+
beginLiteralString("sync unnamed taking 2 parameters")
661+
endLiteralString(0, ))
662+
endArguments(1, (, ))
663+
handleSend(print, ;)
664+
handleExpressionFunctionBody(=>, null)
665+
endFunctionExpression((, ;)
666+
handleExpressionStatement(;)
667+
handleNoTypeVariables(()
579668
beginFunctionExpression(()
580669
beginFormalParameters((, MemberKind.Local)
581670
beginMetadataStar(int)
@@ -614,7 +703,40 @@ beginCompilationUnit(void)
614703
endArguments(0, (, ))
615704
handleSend((, ))
616705
handleExpressionStatement(;)
617-
endBlockFunctionBody(14, {, })
706+
handleNoTypeVariables(()
707+
beginFunctionExpression(()
708+
beginFormalParameters((, MemberKind.Local)
709+
beginMetadataStar(int)
710+
endMetadataStar(0)
711+
beginFormalParameter(int, MemberKind.Local, null, null, null)
712+
handleIdentifier(int, typeReference)
713+
handleNoTypeArguments(x)
714+
handleType(int, null)
715+
handleIdentifier(x, formalParameterDeclaration)
716+
handleFormalParameterWithoutValue(,)
717+
endFormalParameter(null, null, null, x, null, null, FormalParameterKind.requiredPositional, MemberKind.Local)
718+
beginMetadataStar(int)
719+
endMetadataStar(0)
720+
beginFormalParameter(int, MemberKind.Local, null, null, null)
721+
handleIdentifier(int, typeReference)
722+
handleNoTypeArguments(y)
723+
handleType(int, null)
724+
handleIdentifier(y, formalParameterDeclaration)
725+
handleFormalParameterWithoutValue())
726+
endFormalParameter(null, null, null, y, null, null, FormalParameterKind.requiredPositional, MemberKind.Local)
727+
endFormalParameters(2, (, ), MemberKind.Local)
728+
handleAsyncModifier(async, null)
729+
handleIdentifier(print, expression)
730+
handleNoTypeArguments(()
731+
beginArguments(()
732+
beginLiteralString("async unnamed taking 2 parameters")
733+
endLiteralString(0, ))
734+
endArguments(1, (, ))
735+
handleSend(print, ;)
736+
handleExpressionFunctionBody(=>, null)
737+
endFunctionExpression((, ;)
738+
handleExpressionStatement(;)
739+
endBlockFunctionBody(17, {, })
618740
endTopLevelMethod(void, null, })
619741
endTopLevelDeclaration()
620742
endCompilationUnit(1, )

0 commit comments

Comments
 (0)