File tree 3 files changed +39
-10
lines changed
3 files changed +39
-10
lines changed Original file line number Diff line number Diff line change @@ -263,17 +263,13 @@ extension Parser {
263
263
mutating func parseParameterModifiers( isClosure: Bool ) -> RawDeclModifierListSyntax {
264
264
var elements = [ RawDeclModifierSyntax] ( )
265
265
var loopProgress = LoopProgressCondition ( )
266
- MODIFIER_LOOP: while self . hasProgressed ( & loopProgress) {
267
- switch self . at ( anyIn: ParameterModifier . self) {
268
- case ( . _const, let handle) ? :
269
- elements. append ( RawDeclModifierSyntax ( name: self . eat ( handle) , detail: nil , arena: self . arena) )
270
- case ( . isolated, let handle) ?
271
- where self . withLookahead ( { !$0. startsParameterName ( isClosure: isClosure, allowMisplacedSpecifierRecovery: false ) }
272
- ) :
273
- elements. append ( RawDeclModifierSyntax ( name: self . eat ( handle) , detail: nil , arena: self . arena) )
274
- default :
275
- break MODIFIER_LOOP
266
+ while self . hasProgressed ( & loopProgress) {
267
+ guard let match = self . at ( anyIn: ParameterModifier . self) ,
268
+ !withLookahead( { $0. startsParameterName ( isClosure: isClosure, allowMisplacedSpecifierRecovery: false ) } )
269
+ else {
270
+ break
276
271
}
272
+ elements. append ( RawDeclModifierSyntax ( name: self . eat ( match. handle) , detail: nil , arena: self . arena) )
277
273
}
278
274
if elements. isEmpty {
279
275
return self . emptyCollection ( RawDeclModifierListSyntax . self)
Original file line number Diff line number Diff line change @@ -375,6 +375,7 @@ extension Parser.Lookahead {
375
375
&& !self . at ( . keyword( . repeat ) )
376
376
&& !self . at ( . keyword( . __shared) )
377
377
&& !self . at ( . keyword( . __owned) )
378
+ && !self . at ( . keyword( . _const) )
378
379
&& !self . at ( . keyword( . borrowing) )
379
380
&& !self . at ( . keyword( . consuming) )
380
381
&& !( experimentalFeatures. contains ( . sendingArgsAndResults) && self . at ( . keyword( . sending) ) )
Original file line number Diff line number Diff line change @@ -3288,4 +3288,36 @@ final class DeclarationTests: ParserTestCase {
3288
3288
"""
3289
3289
)
3290
3290
}
3291
+
3292
+ func testConstAsArgumentLabel( ) {
3293
+ assertParse (
3294
+ " func const(_const: String) {} " ,
3295
+ substructure: FunctionParameterSyntax (
3296
+ firstName: . identifier( " _const " ) ,
3297
+ colon: . colonToken( ) ,
3298
+ type: TypeSyntax ( IdentifierTypeSyntax ( name: . identifier( " String " ) ) )
3299
+ )
3300
+ )
3301
+
3302
+ assertParse (
3303
+ " func const(_const map: String) {} " ,
3304
+ substructure: FunctionParameterSyntax (
3305
+ firstName: . identifier( " _const " ) ,
3306
+ secondName: . identifier( " map " ) ,
3307
+ colon: . colonToken( ) ,
3308
+ type: TypeSyntax ( IdentifierTypeSyntax ( name: . identifier( " String " ) ) )
3309
+ )
3310
+ )
3311
+
3312
+ assertParse (
3313
+ " func const(_const x y: String) {} " ,
3314
+ substructure: FunctionParameterSyntax (
3315
+ modifiers: [ DeclModifierSyntax ( name: . keyword( . _const) ) ] ,
3316
+ firstName: . identifier( " x " ) ,
3317
+ secondName: . identifier( " y " ) ,
3318
+ colon: . colonToken( ) ,
3319
+ type: TypeSyntax ( IdentifierTypeSyntax ( name: . identifier( " String " ) ) )
3320
+ )
3321
+ )
3322
+ }
3291
3323
}
You can’t perform that action at this time.
0 commit comments