Skip to content

Commit e8219b7

Browse files
committed
Add calledExpression label to FunctionCallExpr convenience initializer
Otherwise initializing a `FunctionCallExpr` from a string is ambiguous whether it should be parsed or call the string
1 parent e137e4d commit e8219b7

File tree

7 files changed

+21
-21
lines changed

7 files changed

+21
-21
lines changed

Sources/SwiftSyntaxBuilder/ConvenienceInitializers/FunctionCallExprConvenienceInitializers.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ extension FunctionCallExpr {
1818
/// instead of having to wrap them in a `TupleExprElementList`.
1919
/// The presence of the parenthesis will be inferred based on the presence of arguments and the trailing closure.
2020
public init(
21-
_ calledExpression: ExpressibleAsExprBuildable,
21+
calledExpression: ExpressibleAsExprBuildable,
2222
trailingClosure: ExpressibleAsClosureExpr? = nil,
2323
additionalTrailingClosures: MultipleTrailingClosureElementList? = nil,
2424
@TupleExprElementListBuilder argumentList: () -> ExpressibleAsTupleExprElementList = { [] }

Tests/SwiftSyntaxBuilderTest/CollectionNodeFlatteningTests.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ final class CollectionNodeFlatteningTests: XCTestCase {
99

1010
@CodeBlockItemListBuilder
1111
func buildInnerCodeBlockItemList() -> ExpressibleAsCodeBlockItemList {
12-
FunctionCallExpr("innerBuilder")
12+
FunctionCallExpr(calledExpression: "innerBuilder")
1313
}
1414

1515
@CodeBlockItemListBuilder
1616
func buildOuterCodeBlockItemList() -> ExpressibleAsCodeBlockItemList {
17-
FunctionCallExpr("outerBuilder")
17+
FunctionCallExpr(calledExpression: "outerBuilder")
1818

1919
buildInnerCodeBlockItemList()
2020
}
2121

2222
let codeBlock = CodeBlock(leadingTrivia: leadingTrivia) {
23-
FunctionCallExpr("outsideBuilder")
23+
FunctionCallExpr(calledExpression: "outsideBuilder")
2424
buildOuterCodeBlockItemList()
2525
}
2626

@@ -41,13 +41,13 @@ final class CollectionNodeFlatteningTests: XCTestCase {
4141
let leadingTrivia = Trivia.unexpectedText("")
4242

4343
func buildInnerCodeBlockItemList() -> ExpressibleAsCodeBlockItemList {
44-
CodeBlockItemList([FunctionCallExpr("innerBuilder")])
44+
CodeBlockItemList([FunctionCallExpr(calledExpression: "innerBuilder")])
4545
}
4646

4747
func buildOuterCodeBlockItemList() -> ExpressibleAsCodeBlockItemList {
4848
CodeBlockItemList(
4949
combining: [
50-
CodeBlockItemList([FunctionCallExpr("outerBuilder")]),
50+
CodeBlockItemList([FunctionCallExpr(calledExpression: "outerBuilder")]),
5151
buildInnerCodeBlockItemList()
5252
]
5353
)
@@ -57,7 +57,7 @@ final class CollectionNodeFlatteningTests: XCTestCase {
5757
leadingTrivia: leadingTrivia,
5858
statements: CodeBlockItemList(
5959
combining: [
60-
CodeBlockItemList([FunctionCallExpr("outsideBuilder")]),
60+
CodeBlockItemList([FunctionCallExpr(calledExpression: "outsideBuilder")]),
6161
buildOuterCodeBlockItemList()
6262
]
6363
)

Tests/SwiftSyntaxBuilderTest/DoStmtTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ final class DoStmtTests: XCTestCase {
55
func testDoStmt() {
66
let buildable = DoStmt(
77
body: CodeBlock(statementsBuilder: {
8-
CodeBlockItem(item: TryExpr(expression: FunctionCallExpr(MemberAccessExpr(base: "a", name: "b"))))
8+
CodeBlockItem(item: TryExpr(expression: FunctionCallExpr(calledExpression: MemberAccessExpr(base: "a", name: "b"))))
99
}),
1010
catchClauses: [
1111
CatchClause(CatchItemList {
1212
CatchItem(pattern: "Error1")
1313
CatchItem(pattern: "Error2")
1414
}) {
15-
FunctionCallExpr("print") {
15+
FunctionCallExpr(calledExpression: "print") {
1616
TupleExprElement(expression: StringLiteralExpr("Known error"))
1717
}
1818
},
@@ -23,7 +23,7 @@ final class DoStmtTests: XCTestCase {
2323
ThrowStmt(expression: MemberAccessExpr(base: "Error4", name: "error3"))
2424
},
2525
CatchClause {
26-
FunctionCallExpr("print") {
26+
FunctionCallExpr(calledExpression: "print") {
2727
TupleExprElement(expression: "error")
2828
}
2929
}

Tests/SwiftSyntaxBuilderTest/ExpressibleBuildablesTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ final class ExpressibleBuildablesTests: XCTestCase {
4545

4646
func testExprExpressibleAsCodeBlockItem() {
4747
let myCodeBlock = CodeBlock(leftBrace: .leftBrace.withLeadingTrivia([])) {
48-
FunctionCallExpr("print") { TupleExprElement(expression: StringLiteralExpr("Hello world")) }
48+
FunctionCallExpr(calledExpression: "print") { TupleExprElement(expression: StringLiteralExpr("Hello world")) }
4949
IntegerLiteralExpr(42)
5050
"someIdentifier"
5151
}

Tests/SwiftSyntaxBuilderTest/ExtensionDeclTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ final class ExtensionDeclTests: XCTestCase {
77
let keywords = ["associatedtype", "class"].map { keyword -> VariableDecl in
88
// We need to use `CodeBlock` here to ensure there is braces around.
99
let body = CodeBlock {
10-
FunctionCallExpr("TokenSyntax.\(keyword)Keyword")
10+
FunctionCallExpr(calledExpression: "TokenSyntax.\(keyword)Keyword")
1111
}
1212

1313
return VariableDecl(

Tests/SwiftSyntaxBuilderTest/FunctionTests.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ final class FunctionTests: XCTestCase {
2626
body: ifCodeBlock)
2727

2828
ReturnStmt(expression: SequenceExpr {
29-
FunctionCallExpr("fibonacci") {
29+
FunctionCallExpr(calledExpression: "fibonacci") {
3030
SequenceExpr {
3131
IntegerLiteralExpr(digits: "n")
3232
BinaryOperatorExpr("-")
@@ -36,7 +36,7 @@ final class FunctionTests: XCTestCase {
3636

3737
BinaryOperatorExpr("+")
3838

39-
FunctionCallExpr(MemberAccessExpr(base: "self", name: "fibonacci")) {
39+
FunctionCallExpr(calledExpression: MemberAccessExpr(base: "self", name: "fibonacci")) {
4040
SequenceExpr {
4141
IntegerLiteralExpr(digits: "n")
4242
BinaryOperatorExpr("-")
@@ -58,7 +58,7 @@ final class FunctionTests: XCTestCase {
5858
}
5959

6060
func testArguments() {
61-
let buildable = FunctionCallExpr("test") {
61+
let buildable = FunctionCallExpr(calledExpression: "test") {
6262
for param in (1...5) {
6363
TupleExprElement(label: param.isMultiple(of: 2) ? "p\(param)" : nil, expression: "value\(param)")
6464
}
@@ -68,13 +68,13 @@ final class FunctionTests: XCTestCase {
6868
}
6969

7070
func testParensEmittedForNoArgumentsAndNoTrailingClosure() {
71-
let buildable = FunctionCallExpr("test")
71+
let buildable = FunctionCallExpr(calledExpression: "test")
7272
let syntax = buildable.buildSyntax()
7373
XCTAssertEqual(syntax.description, "test()")
7474
}
7575

7676
func testParensEmittedForArgumentAndTrailingClosure() {
77-
let buildable = FunctionCallExpr("test", trailingClosure: ClosureExpr()) {
77+
let buildable = FunctionCallExpr(calledExpression: "test", trailingClosure: ClosureExpr()) {
7878
TupleExprElement(expression: "42")
7979
}
8080
let syntax = buildable.buildSyntax()
@@ -83,11 +83,11 @@ final class FunctionTests: XCTestCase {
8383

8484
func testParensOmittedForNoArgumentsAndTrailingClosure() {
8585
let closure = ClosureExpr(statementsBuilder: {
86-
FunctionCallExpr("f") {
86+
FunctionCallExpr(calledExpression: "f") {
8787
TupleExprElement(expression: "a")
8888
}
8989
})
90-
let buildable = FunctionCallExpr("test", trailingClosure: closure)
90+
let buildable = FunctionCallExpr(calledExpression: "test", trailingClosure: closure)
9191
let syntax = buildable.buildSyntax()
9292
XCTAssertEqual(
9393
syntax.description,

Tests/SwiftSyntaxBuilderTest/IfStmtTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ final class IfStmtTests: XCTestCase {
1919
// Use the convenience initializer from IfStmtConvenienceInitializers
2020
// with an else branch expressed by a second trailing closure.
2121
let buildable = IfStmt(conditions: ExprList([BooleanLiteralExpr(true)])) {
22-
FunctionCallExpr("print") {
22+
FunctionCallExpr(calledExpression: "print") {
2323
TupleExprElement(expression: StringLiteralExpr("Hello from the if-branch!"))
2424
}
2525
} elseBody: {
26-
FunctionCallExpr("print") {
26+
FunctionCallExpr(calledExpression: "print") {
2727
TupleExprElement(expression: StringLiteralExpr("Hello from the else-branch!"))
2828
}
2929
}

0 commit comments

Comments
 (0)