Skip to content

Commit f784853

Browse files
committed
Support trailing commas in types within expressions
1 parent 793ccbd commit f784853

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

Sources/SwiftParser/Types.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1057,7 +1057,8 @@ extension Parser.Lookahead {
10571057
return false
10581058
}
10591059
// Parse the comma, if the list continues.
1060-
} while self.consume(if: .comma) != nil && self.hasProgressed(&loopProgress)
1060+
// This could be the trailing comma.
1061+
} while self.consume(if: .comma) != nil && !self.at(prefix: ">") && self.hasProgressed(&loopProgress)
10611062
}
10621063

10631064
guard self.consume(ifPrefix: ">", as: .rightAngle) != nil else {

Tests/SwiftParserTest/ExpressionTests.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2125,6 +2125,26 @@ final class ExpressionTests: ParserTestCase {
21252125
"""
21262126
)
21272127
}
2128+
2129+
func testTrailingCommasInTypeExpressions() {
2130+
assertParse(
2131+
"""
2132+
let _ = Foo2<Int, Bool, String,>.self
2133+
"""
2134+
)
2135+
2136+
assertParse(
2137+
"""
2138+
let _ = Foo2<Int, Bool, String,>()
2139+
"""
2140+
)
2141+
2142+
assertParse(
2143+
"""
2144+
let _ = ((Int, Bool, String,) -> Void).self
2145+
"""
2146+
)
2147+
}
21282148
}
21292149

21302150
final class MemberExprTests: ParserTestCase {

0 commit comments

Comments
 (0)