File tree Expand file tree Collapse file tree 3 files changed +46
-1
lines changed Expand file tree Collapse file tree 3 files changed +46
-1
lines changed Original file line number Diff line number Diff line change @@ -31,7 +31,10 @@ extension Parser {
31
31
self . missingToken ( . identifier, text: nil )
32
32
)
33
33
} else {
34
- return ( nil , self . consumeAnyToken ( ) )
34
+ if let wildcardToken = self . consume ( if: . wildcardKeyword) {
35
+ return ( nil , wildcardToken)
36
+ }
37
+ return ( nil , self . consumeAnyToken ( remapping: . identifier) )
35
38
}
36
39
}
37
40
}
Original file line number Diff line number Diff line change @@ -73,6 +73,22 @@ final class DeclarationTests: XCTestCase {
73
73
)
74
74
75
75
AssertParse ( " func /^ (lhs: Int, rhs: Int) -> Int { 1 / 2 } " )
76
+
77
+ AssertParse (
78
+ """
79
+ func name(_ default: Int) {}
80
+ """ ,
81
+ substructure: Syntax ( FunctionParameterSyntax (
82
+ attributes: nil ,
83
+ modifiers: nil ,
84
+ firstName: . wildcardKeyword( ) ,
85
+ secondName: . identifier( " default " ) ,
86
+ colon: TokenSyntax . colonToken ( ) ,
87
+ type: TypeSyntax ( SimpleTypeIdentifierSyntax ( name: TokenSyntax . identifier ( " Int " ) , genericArgumentClause: nil ) ) ,
88
+ ellipsis: nil ,
89
+ defaultArgument: nil ,
90
+ trailingComma: nil ) )
91
+ )
76
92
}
77
93
78
94
func testFuncAfterUnbalancedClosingBrace( ) {
Original file line number Diff line number Diff line change @@ -520,4 +520,30 @@ final class StatementTests: XCTestCase {
520
520
func testDefaultIdentIdentifierInReturnStmt( ) {
521
521
AssertParse ( " return FileManager.default " )
522
522
}
523
+
524
+ func testDefaultAsIdentifierInSubscript( ) {
525
+ AssertParse (
526
+ """
527
+ data[position, default: 0]
528
+ """ ,
529
+ substructure: Syntax ( ExprSyntax ( SubscriptExprSyntax (
530
+ calledExpression: ExprSyntax ( IdentifierExprSyntax ( identifier: . identifier( " data " ) , declNameArguments: nil ) ) ,
531
+ leftBracket: . leftSquareBracketToken( ) ,
532
+ argumentList: TupleExprElementListSyntax ( [
533
+ TupleExprElementSyntax (
534
+ label: nil ,
535
+ colon: nil ,
536
+ expression: ExprSyntax ( IdentifierExprSyntax ( identifier: . identifier( " position " ) , declNameArguments: nil ) ) ,
537
+ trailingComma: . commaToken( ) ) ,
538
+ TupleExprElementSyntax (
539
+ label: . identifier( " default " ) ,
540
+ colon: . colonToken( ) ,
541
+ expression: ExprSyntax ( IntegerLiteralExprSyntax ( 0 ) ) ,
542
+ trailingComma: nil ) ,
543
+ ] ) ,
544
+ rightBracket: . rightSquareBracketToken( ) ,
545
+ trailingClosure: nil ,
546
+ additionalTrailingClosures: nil ) ) )
547
+ )
548
+ }
523
549
}
You can’t perform that action at this time.
0 commit comments