Skip to content

Commit 2fc256f

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 299ed59 commit 2fc256f

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
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/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/FunctionTests.swift

Lines changed: 6 additions & 6 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
}
@@ -74,7 +74,7 @@ final class FunctionTests: XCTestCase {
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)