@@ -144,6 +144,130 @@ ConstructorDeclaration
144144''' );
145145 }
146146
147+ test_constructor_formalParameter_functionTyped_const () {
148+ var parseResult = parseStringWithErrors (r'''
149+ class A {
150+ A(const int a(String x));
151+ }
152+ ''' );
153+ parseResult.assertErrors ([
154+ error (ParserErrorCode .extraneousModifier, 14 , 5 ),
155+ error (ParserErrorCode .functionTypedParameterVar, 14 , 5 ),
156+ ]);
157+
158+ var node = parseResult.findNode.singleConstructorDeclaration;
159+ assertParsedNodeText (node, r'''
160+ ConstructorDeclaration
161+ returnType: SimpleIdentifier
162+ token: A
163+ parameters: FormalParameterList
164+ leftParenthesis: (
165+ parameter: FunctionTypedFormalParameter
166+ returnType: NamedType
167+ name: int
168+ name: a
169+ parameters: FormalParameterList
170+ leftParenthesis: (
171+ parameter: SimpleFormalParameter
172+ type: NamedType
173+ name: String
174+ name: x
175+ rightParenthesis: )
176+ rightParenthesis: )
177+ body: EmptyFunctionBody
178+ semicolon: ;
179+ ''' );
180+ }
181+
182+ test_constructor_formalParameter_functionTyped_final () {
183+ var parseResult = parseStringWithErrors (r'''
184+ class A {
185+ A(final int a(String x));
186+ }
187+ ''' );
188+ parseResult.assertErrors ([
189+ error (ParserErrorCode .functionTypedParameterVar, 14 , 5 ),
190+ ]);
191+
192+ var node = parseResult.findNode.singleConstructorDeclaration;
193+ assertParsedNodeText (node, r'''
194+ ConstructorDeclaration
195+ returnType: SimpleIdentifier
196+ token: A
197+ parameters: FormalParameterList
198+ leftParenthesis: (
199+ parameter: FunctionTypedFormalParameter
200+ keyword: final
201+ returnType: NamedType
202+ name: int
203+ name: a
204+ parameters: FormalParameterList
205+ leftParenthesis: (
206+ parameter: SimpleFormalParameter
207+ type: NamedType
208+ name: String
209+ name: x
210+ rightParenthesis: )
211+ rightParenthesis: )
212+ body: EmptyFunctionBody
213+ semicolon: ;
214+ ''' );
215+ }
216+
217+ test_constructor_formalParameter_simple_const () {
218+ var parseResult = parseStringWithErrors (r'''
219+ class A {
220+ A(const int a);
221+ }
222+ ''' );
223+ parseResult.assertErrors ([
224+ error (ParserErrorCode .extraneousModifier, 14 , 5 ),
225+ ]);
226+
227+ var node = parseResult.findNode.singleConstructorDeclaration;
228+ assertParsedNodeText (node, r'''
229+ ConstructorDeclaration
230+ returnType: SimpleIdentifier
231+ token: A
232+ parameters: FormalParameterList
233+ leftParenthesis: (
234+ parameter: SimpleFormalParameter
235+ keyword: const
236+ type: NamedType
237+ name: int
238+ name: a
239+ rightParenthesis: )
240+ body: EmptyFunctionBody
241+ semicolon: ;
242+ ''' );
243+ }
244+
245+ test_constructor_formalParameter_simple_final () {
246+ var parseResult = parseStringWithErrors (r'''
247+ class A {
248+ A(final int a);
249+ }
250+ ''' );
251+ parseResult.assertNoErrors ();
252+
253+ var node = parseResult.findNode.singleConstructorDeclaration;
254+ assertParsedNodeText (node, r'''
255+ ConstructorDeclaration
256+ returnType: SimpleIdentifier
257+ token: A
258+ parameters: FormalParameterList
259+ leftParenthesis: (
260+ parameter: SimpleFormalParameter
261+ keyword: final
262+ type: NamedType
263+ name: int
264+ name: a
265+ rightParenthesis: )
266+ body: EmptyFunctionBody
267+ semicolon: ;
268+ ''' );
269+ }
270+
147271 test_nameWithTypeParameters_hasTypeParameters () {
148272 useDeclaringConstructorsAst = true ;
149273 var parseResult = parseStringWithErrors (r'''
@@ -605,6 +729,39 @@ ClassDeclaration
605729''' );
606730 }
607731
732+ test_primaryConstructor_declaringFormalParameter_functionTyped_const () {
733+ useDeclaringConstructorsAst = true ;
734+ var parseResult = parseStringWithErrors (r'''
735+ class A(const int a(String x)) {}
736+ ''' );
737+ parseResult.assertErrors ([error (ParserErrorCode .extraneousModifier, 8 , 5 )]);
738+
739+ var node = parseResult.findNode.singleClassDeclaration;
740+ assertParsedNodeText (node, r'''
741+ ClassDeclaration
742+ classKeyword: class
743+ namePart: PrimaryConstructorDeclaration
744+ typeName: A
745+ formalParameters: FormalParameterList
746+ leftParenthesis: (
747+ parameter: FunctionTypedFormalParameter
748+ returnType: NamedType
749+ name: int
750+ name: a
751+ parameters: FormalParameterList
752+ leftParenthesis: (
753+ parameter: SimpleFormalParameter
754+ type: NamedType
755+ name: String
756+ name: x
757+ rightParenthesis: )
758+ rightParenthesis: )
759+ body: BlockClassBody
760+ leftBracket: {
761+ rightBracket: }
762+ ''' );
763+ }
764+
608765 test_primaryConstructor_declaringFormalParameter_functionTyped_final () {
609766 useDeclaringConstructorsAst = true ;
610767 var parseResult = parseStringWithErrors (r'''
@@ -621,6 +778,7 @@ ClassDeclaration
621778 formalParameters: FormalParameterList
622779 leftParenthesis: (
623780 parameter: FunctionTypedFormalParameter
781+ keyword: final
624782 returnType: NamedType
625783 name: int
626784 name: a
@@ -654,6 +812,7 @@ ClassDeclaration
654812 formalParameters: FormalParameterList
655813 leftParenthesis: (
656814 parameter: FunctionTypedFormalParameter
815+ keyword: var
657816 returnType: NamedType
658817 name: int
659818 name: a
@@ -671,6 +830,33 @@ ClassDeclaration
671830''' );
672831 }
673832
833+ test_primaryConstructor_declaringFormalParameter_simple_const () {
834+ useDeclaringConstructorsAst = true ;
835+ var parseResult = parseStringWithErrors (r'''
836+ class A(const int a) {}
837+ ''' );
838+ parseResult.assertErrors ([error (ParserErrorCode .extraneousModifier, 8 , 5 )]);
839+
840+ var node = parseResult.findNode.singleClassDeclaration;
841+ assertParsedNodeText (node, r'''
842+ ClassDeclaration
843+ classKeyword: class
844+ namePart: PrimaryConstructorDeclaration
845+ typeName: A
846+ formalParameters: FormalParameterList
847+ leftParenthesis: (
848+ parameter: SimpleFormalParameter
849+ keyword: const
850+ type: NamedType
851+ name: int
852+ name: a
853+ rightParenthesis: )
854+ body: BlockClassBody
855+ leftBracket: {
856+ rightBracket: }
857+ ''' );
858+ }
859+
674860 test_primaryConstructor_declaringFormalParameter_simple_final () {
675861 useDeclaringConstructorsAst = true ;
676862 var parseResult = parseStringWithErrors (r'''
0 commit comments