@@ -786,7 +786,10 @@ extension Parser {
786786 if self . at ( . rightSquare) {
787787 args = [ ]
788788 } else {
789- args = self . parseArgumentListElements ( pattern: pattern, allowTrailingComma: false )
789+ args = self . parseArgumentListElements (
790+ pattern: pattern,
791+ allowTrailingComma: self . experimentalFeatures. contains ( . trailingComma)
792+ )
790793 }
791794 let ( unexpectedBeforeRSquare, rsquare) = self . expect ( . rightSquare)
792795
@@ -1019,7 +1022,10 @@ extension Parser {
10191022 if self . at ( . rightSquare) {
10201023 args = [ ]
10211024 } else {
1022- args = self . parseArgumentListElements ( pattern: pattern, allowTrailingComma: false )
1025+ args = self . parseArgumentListElements (
1026+ pattern: pattern,
1027+ allowTrailingComma: self . experimentalFeatures. contains ( . trailingComma)
1028+ )
10231029 }
10241030 let ( unexpectedBeforeRSquare, rsquare) = self . expect ( . rightSquare)
10251031
@@ -1314,7 +1320,10 @@ extension Parser {
13141320 let unexpectedBeforeRightParen : RawUnexpectedNodesSyntax ?
13151321 let rightParen : RawTokenSyntax ?
13161322 if leftParen != nil {
1317- args = parseArgumentListElements ( pattern: pattern, allowTrailingComma: false )
1323+ args = parseArgumentListElements (
1324+ pattern: pattern,
1325+ allowTrailingComma: self . experimentalFeatures. contains ( . trailingComma)
1326+ )
13181327 ( unexpectedBeforeRightParen, rightParen) = self . expect ( . rightParen)
13191328 } else {
13201329 args = [ ]
@@ -1740,7 +1749,7 @@ extension Parser {
17401749 arena: self . arena
17411750 )
17421751 )
1743- } while keepGoing != nil && self . hasProgressed ( & loopProgress)
1752+ } while keepGoing != nil && ! self . atCaptureListTerminator ( ) && self . hasProgressed ( & loopProgress)
17441753 }
17451754 // We were promised a right square bracket, so we're going to get it.
17461755 var unexpectedNodes = [ RawSyntax] ( )
@@ -1827,6 +1836,10 @@ extension Parser {
18271836 )
18281837 }
18291838
1839+ mutating func atCaptureListTerminator( ) -> Bool {
1840+ return self . at ( . rightSquare)
1841+ }
1842+
18301843 mutating func parseClosureCaptureSpecifiers( ) -> RawClosureCaptureSpecifierSyntax ? {
18311844 // Check for the strength specifier: "weak", "unowned", or
18321845 // "unowned(safe/unsafe)".
@@ -1938,7 +1951,7 @@ extension Parser {
19381951 }
19391952
19401953 mutating func atArgumentListTerminator( _ allowTrailingComma: Bool ) -> Bool {
1941- return allowTrailingComma && self . at ( . rightParen)
1954+ return allowTrailingComma && ( self . at ( . rightParen) || self . at ( . rightSquare ) )
19421955 }
19431956}
19441957
@@ -2383,7 +2396,7 @@ extension Parser {
23832396 } else {
23842397 unexpectedPrePatternCase = nil
23852398 }
2386- } while keepGoing != nil && self . hasProgressed ( & loopProgress)
2399+ } while keepGoing != nil && ! self . atSwitchCaseListTerminator ( ) && self . hasProgressed ( & loopProgress)
23872400 }
23882401 let ( unexpectedBeforeColon, colon) = self . expect ( . colon)
23892402 return RawSwitchCaseLabelSyntax (
@@ -2396,6 +2409,10 @@ extension Parser {
23962409 )
23972410 }
23982411
2412+ mutating func atSwitchCaseListTerminator( ) -> Bool {
2413+ return self . experimentalFeatures. contains ( . trailingComma) && self . at ( . colon)
2414+ }
2415+
23992416 /// Parse a switch case with a 'default' label.
24002417 mutating func parseSwitchDefaultLabel(
24012418 _ handle: RecoveryConsumptionHandle
0 commit comments