@@ -751,7 +751,7 @@ extension Parser {
751751 let args = self . parseArgumentListElements (
752752 pattern: pattern,
753753 flavor: flavor. callArgumentFlavor,
754- allowTrailingComma: experimentalFeatures . contains ( . trailingComma )
754+ allowTrailingComma: true
755755 )
756756 let ( unexpectedBeforeRParen, rparen) = self . expect ( . rightParen)
757757
@@ -788,7 +788,10 @@ extension Parser {
788788 if self . at ( . rightSquare) {
789789 args = [ ]
790790 } else {
791- args = self . parseArgumentListElements ( pattern: pattern, allowTrailingComma: false )
791+ args = self . parseArgumentListElements (
792+ pattern: pattern,
793+ allowTrailingComma: true
794+ )
792795 }
793796 let ( unexpectedBeforeRSquare, rsquare) = self . expect ( . rightSquare)
794797
@@ -1021,7 +1024,10 @@ extension Parser {
10211024 if self . at ( . rightSquare) {
10221025 args = [ ]
10231026 } else {
1024- args = self . parseArgumentListElements ( pattern: pattern, allowTrailingComma: false )
1027+ args = self . parseArgumentListElements (
1028+ pattern: pattern,
1029+ allowTrailingComma: true
1030+ )
10251031 }
10261032 let ( unexpectedBeforeRSquare, rsquare) = self . expect ( . rightSquare)
10271033
@@ -1313,7 +1319,10 @@ extension Parser {
13131319 let unexpectedBeforeRightParen : RawUnexpectedNodesSyntax ?
13141320 let rightParen : RawTokenSyntax ?
13151321 if leftParen != nil {
1316- args = parseArgumentListElements ( pattern: pattern, allowTrailingComma: false )
1322+ args = parseArgumentListElements (
1323+ pattern: pattern,
1324+ allowTrailingComma: true
1325+ )
13171326 ( unexpectedBeforeRightParen, rightParen) = self . expect ( . rightParen)
13181327 } else {
13191328 args = [ ]
@@ -1429,7 +1438,7 @@ extension Parser {
14291438 let ( unexpectedBeforeLParen, lparen) = self . expect ( . leftParen)
14301439 let elements = self . parseArgumentListElements (
14311440 pattern: pattern,
1432- allowTrailingComma: experimentalFeatures . contains ( . trailingComma )
1441+ allowTrailingComma: true
14331442 )
14341443 let ( unexpectedBeforeRParen, rparen) = self . expect ( . rightParen)
14351444 return RawTupleExprSyntax (
@@ -1730,7 +1739,7 @@ extension Parser {
17301739 arena: arena
17311740 )
17321741 )
1733- } while keepGoing != nil && self . hasProgressed ( & loopProgress)
1742+ } while keepGoing != nil && ! self . atCaptureListTerminator ( ) && self . hasProgressed ( & loopProgress)
17341743 }
17351744 // We were promised a right square bracket, so we're going to get it.
17361745 var unexpectedNodes = [ RawSyntax] ( )
@@ -1817,6 +1826,10 @@ extension Parser {
18171826 )
18181827 }
18191828
1829+ mutating func atCaptureListTerminator( ) -> Bool {
1830+ return self . at ( . rightSquare)
1831+ }
1832+
18201833 mutating func parseClosureCaptureSpecifiers( ) -> RawClosureCaptureSpecifierSyntax ? {
18211834 // Check for the strength specifier: "weak", "unowned", or
18221835 // "unowned(safe/unsafe)".
@@ -1928,7 +1941,7 @@ extension Parser {
19281941 }
19291942
19301943 mutating func atArgumentListTerminator( _ allowTrailingComma: Bool ) -> Bool {
1931- return allowTrailingComma && self . at ( . rightParen)
1944+ return allowTrailingComma && ( self . at ( . rightParen) || self . at ( . rightSquare ) )
19321945 }
19331946}
19341947
@@ -2367,7 +2380,7 @@ extension Parser {
23672380 } else {
23682381 unexpectedPrePatternCase = nil
23692382 }
2370- } while keepGoing != nil && self . hasProgressed ( & loopProgress)
2383+ } while keepGoing != nil && ! self . atSwitchCaseListTerminator ( ) && self . hasProgressed ( & loopProgress)
23712384 }
23722385 let ( unexpectedBeforeColon, colon) = self . expect ( . colon)
23732386 return RawSwitchCaseLabelSyntax (
@@ -2380,6 +2393,10 @@ extension Parser {
23802393 )
23812394 }
23822395
2396+ mutating func atSwitchCaseListTerminator( ) -> Bool {
2397+ return self . experimentalFeatures. contains ( . trailingComma) && self . at ( . colon)
2398+ }
2399+
23832400 /// Parse a switch case with a 'default' label.
23842401 mutating func parseSwitchDefaultLabel(
23852402 _ handle: RecoveryConsumptionHandle
0 commit comments