Skip to content

Commit f296439

Browse files
committed
Fix the problematic builders
1 parent 09361c2 commit f296439

File tree

4 files changed

+26
-28
lines changed

4 files changed

+26
-28
lines changed

Sources/SwiftSyntaxBuilder/ResultBuilderExtensions.swift

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,14 @@ extension MemberBlockItemListBuilder {
5050
}
5151
}
5252

53-
// MARK: Initializing collections from protocols
54-
// These initializers allow the creation of syntax collections that have a base
55-
// node as their element from the corresponding protocol type.
56-
// These are used by the result builders.
57-
// Since we only have two of these, it doesn’t make sense to generate them.
58-
59-
extension ExprListSyntax {
60-
init(_ elements: [ExprSyntaxProtocol]) {
61-
self = ExprListSyntax(elements.map { ExprSyntax(fromProtocol: $0) } as [ExprSyntax])
53+
extension ExprListBuilder {
54+
public static func buildExpression(_ expression: some ExprSyntaxProtocol) -> Component {
55+
return buildExpression(ExprSyntax(fromProtocol: expression))
6256
}
6357
}
6458

65-
extension UnexpectedNodesSyntax {
66-
public init(_ elements: [SyntaxProtocol]) {
67-
self = UnexpectedNodesSyntax(elements.map { Syntax(fromProtocol: $0) } as [Syntax])
59+
extension UnexpectedNodesBuilder {
60+
public static func buildExpression(_ expression: some SyntaxProtocol) -> Component {
61+
return buildExpression(Syntax(fromProtocol: expression))
6862
}
6963
}

Tests/SwiftParserTest/DeclarationTests.swift

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,8 +1246,9 @@ final class DeclarationTests: ParserTestCase {
12461246
])
12471247
),
12481248
UnexpectedNodesSyntax([
1249-
TokenSyntax.identifier("bogus"), TokenSyntax.keyword(.rethrows),
1250-
TokenSyntax.identifier("set"),
1249+
Syntax(fromProtocol: TokenSyntax.identifier("bogus")),
1250+
Syntax(fromProtocol: TokenSyntax.keyword(.rethrows)),
1251+
Syntax(fromProtocol: TokenSyntax.identifier("set")),
12511252
])
12521253
),
12531254
diagnostics: [
@@ -1336,7 +1337,7 @@ final class DeclarationTests: ParserTestCase {
13361337
substructure: FunctionParameterSyntax(
13371338
firstName: .identifier("first"),
13381339
secondName: .identifier("second"),
1339-
UnexpectedNodesSyntax([TokenSyntax.identifier("third")]),
1340+
UnexpectedNodesSyntax([Syntax(fromProtocol: TokenSyntax.identifier("third"))]),
13401341
colon: .colonToken(),
13411342
type: IdentifierTypeSyntax(name: .identifier("Int"))
13421343
),
@@ -1352,7 +1353,10 @@ final class DeclarationTests: ParserTestCase {
13521353
substructure: FunctionParameterSyntax(
13531354
firstName: .identifier("first"),
13541355
secondName: .identifier("second"),
1355-
UnexpectedNodesSyntax([TokenSyntax.identifier("third"), TokenSyntax.identifier("fourth")]),
1356+
UnexpectedNodesSyntax([
1357+
Syntax(fromProtocol: TokenSyntax.identifier("third")),
1358+
Syntax(fromProtocol: TokenSyntax.identifier("fourth")),
1359+
]),
13561360
colon: .colonToken(),
13571361
type: IdentifierTypeSyntax(name: .identifier("Int"))
13581362
),
@@ -1406,10 +1410,10 @@ final class DeclarationTests: ParserTestCase {
14061410
firstName: .identifier("first"),
14071411
secondName: .identifier("second"),
14081412
UnexpectedNodesSyntax([
1409-
TokenSyntax.leftSquareToken(),
1410-
TokenSyntax.identifier("third"),
1411-
TokenSyntax.identifier("fourth"),
1412-
TokenSyntax.rightSquareToken(),
1413+
Syntax(fromProtocol: TokenSyntax.leftSquareToken()),
1414+
Syntax(fromProtocol: TokenSyntax.identifier("third")),
1415+
Syntax(fromProtocol: TokenSyntax.identifier("fourth")),
1416+
Syntax(fromProtocol: TokenSyntax.rightSquareToken()),
14131417
]),
14141418
colon: .colonToken(),
14151419
type: IdentifierTypeSyntax(name: .identifier("Int"))
@@ -2203,7 +2207,7 @@ final class DeclarationTests: ParserTestCase {
22032207
memberBlock: MemberBlockSyntax(
22042208
leftBrace: .leftBraceToken(),
22052209
members: MemberBlockItemListSyntax(),
2206-
UnexpectedNodesSyntax([TokenSyntax.binaryOperator("^")]),
2210+
UnexpectedNodesSyntax([Syntax(fromProtocol: TokenSyntax.binaryOperator("^"))]),
22072211
rightBrace: .rightBraceToken()
22082212
)
22092213
)
@@ -2880,7 +2884,7 @@ final class DeclarationTests: ParserTestCase {
28802884
funcKeyword: .keyword(.func),
28812885
name: .identifier("test"),
28822886
UnexpectedNodesSyntax([
2883-
TokenSyntax.identifier("<#name#>")
2887+
Syntax(fromProtocol: TokenSyntax.identifier("<#name#>"))
28842888
]),
28852889
signature: FunctionSignatureSyntax(
28862890
parameterClause: FunctionParameterClauseSyntax(

Tests/SwiftParserTest/Parser+EntryTests.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ public class EntryTests: ParserTestCase {
5050
"1️⃣operator 2️⃣test 3️⃣{} other tokens",
5151
{ DeclSyntax.parse(from: &$0) },
5252
substructure: UnexpectedNodesSyntax([
53-
TokenSyntax.leftBraceToken(),
54-
PrecedenceGroupAttributeListSyntax([]),
55-
TokenSyntax.rightBraceToken(),
56-
TokenSyntax.identifier("other"),
57-
TokenSyntax.identifier("tokens"),
53+
Syntax(fromProtocol: TokenSyntax.leftBraceToken()),
54+
Syntax(fromProtocol: PrecedenceGroupAttributeListSyntax([])),
55+
Syntax(fromProtocol: TokenSyntax.rightBraceToken()),
56+
Syntax(fromProtocol: TokenSyntax.identifier("other")),
57+
Syntax(fromProtocol: TokenSyntax.identifier("tokens")),
5858
]),
5959
substructureAfterMarker: "3️⃣",
6060
diagnostics: [

Tests/SwiftParserTest/translated/ErrorsTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ final class ErrorsTests: ParserTestCase {
300300
)
301301
)
302302
]),
303-
UnexpectedNodesSyntax([TokenSyntax.keyword(.throws)])
303+
UnexpectedNodesSyntax([Syntax(fromProtocol: TokenSyntax.keyword(.throws))])
304304
),
305305
diagnostics: [
306306
DiagnosticSpec(message: "unexpected 'throws' keyword in function")

0 commit comments

Comments
 (0)