Skip to content

Commit a9c91a1

Browse files
johnniwintherCommit Queue
authored andcommitted
[parser] Support declaring function typed parameters
This adds parser support for using `final` and `var` in function type parameters of primary constructors. Part of #61699 Change-Id: I32c0b9ac9700fc6a4ccfdd6c732c3ae3179ad5fb Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/457023 Reviewed-by: Konstantin Shcheglov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Johnni Winther <[email protected]>
1 parent f6b74c3 commit a9c91a1

16 files changed

+7264
-183
lines changed

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

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2209,10 +2209,20 @@ class Parser {
22092209
Token closer = typeParam.skip(token);
22102210
if (closer.next!.isA(TokenType.OPEN_PAREN)) {
22112211
if (varFinalOrConst != null) {
2212-
reportRecoverableError(
2213-
varFinalOrConst,
2214-
codes.codeFunctionTypedParameterVar,
2215-
);
2212+
if (memberKind != MemberKind.PrimaryConstructor) {
2213+
reportRecoverableError(
2214+
varFinalOrConst,
2215+
codes.codeFunctionTypedParameterVar,
2216+
);
2217+
} else {
2218+
if (!_isDeclaringConstructorsFeatureEnabled) {
2219+
reportExperimentNotEnabled(
2220+
ExperimentalFlag.declaringConstructors,
2221+
varFinalOrConst,
2222+
varFinalOrConst,
2223+
);
2224+
}
2225+
}
22162226
}
22172227
beforeInlineFunctionType = token;
22182228
token = closer.next!.endGroup!;
@@ -2221,10 +2231,20 @@ class Parser {
22212231
}
22222232
} else if (next.isA(TokenType.OPEN_PAREN)) {
22232233
if (varFinalOrConst != null) {
2224-
reportRecoverableError(
2225-
varFinalOrConst,
2226-
codes.codeFunctionTypedParameterVar,
2227-
);
2234+
if (memberKind != MemberKind.PrimaryConstructor) {
2235+
reportRecoverableError(
2236+
varFinalOrConst,
2237+
codes.codeFunctionTypedParameterVar,
2238+
);
2239+
} else {
2240+
if (!_isDeclaringConstructorsFeatureEnabled) {
2241+
reportExperimentNotEnabled(
2242+
ExperimentalFlag.declaringConstructors,
2243+
varFinalOrConst,
2244+
varFinalOrConst,
2245+
);
2246+
}
2247+
}
22282248
}
22292249
beforeInlineFunctionType = token;
22302250
token = next.endGroup!;

pkg/front_end/parser_testcases/declaring_constructors/declaring_parameter.dart

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ class C(var a) {}
55
class C(final a) {}
66
class C(var a b) {}
77
class C(final a b) {}
8+
class C(var f()) {}
9+
class C(final f()) {}
10+
class C(var void f()) {}
11+
class C(final void f()) {}
12+
class C(var f<T>()) {}
13+
class C(final f<T>()) {}
14+
class C(var void f<T>()) {}
15+
class C(final void f<T>()) {}
816

917
enum E() {}
1018
enum E(a) {}
@@ -13,6 +21,14 @@ enum E(var a) {}
1321
enum E(final a) {}
1422
enum E(var a b) {}
1523
enum E(final a b) {}
24+
enum E(var f()) {}
25+
enum E(final f()) {}
26+
enum E(var void f()) {}
27+
enum E(final void f()) {}
28+
enum E(var f<T>()) {}
29+
enum E(final f<T>()) {}
30+
enum E(var void f<T>()) {}
31+
enum E(final void f<T>()) {}
1632

1733
extension type ET() {}
1834
extension type ET(a) {}
@@ -21,3 +37,11 @@ extension type ET(var a) {}
2137
extension type ET(final a) {}
2238
extension type ET(var a b) {}
2339
extension type ET(final a b) {}
40+
extension type ET(var f()) {}
41+
extension type ET(final f()) {}
42+
extension type ET(var void f()) {}
43+
extension type ET(final void f()) {}
44+
extension type ET(var f<T>()) {}
45+
extension type ET(final f<T>()) {}
46+
extension type ET(var void f<T>()) {}
47+
extension type ET(final void f<T>()) {}

0 commit comments

Comments
 (0)