Skip to content

Commit 3bce6f1

Browse files
committed
Use generic parameter for TupleExprElement convenience initializer
1 parent cc9b4b6 commit 3bce6f1

File tree

5 files changed

+10
-10
lines changed

5 files changed

+10
-10
lines changed

Sources/SwiftSyntaxBuilder/ConvenienceInitializers.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ extension TernaryExpr {
376376
extension TupleExprElement {
377377
/// A convenience initializer that allows passing in label as an optional string.
378378
/// The presence of the colon will be inferred based on the presence of the label.
379-
public init(label: String? = nil, expression: ExprSyntax) {
379+
public init<E: ExprSyntaxProtocol>(label: String? = nil, expression: E) {
380380
self.init(
381381
label: label.map { .identifier($0) },
382382
colon: label == nil ? nil : .colonToken(),

Tests/SwiftSyntaxBuilderTest/CustomAttributeTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ final class CustomAttributeTests: XCTestCase {
2121
#line: (CustomAttribute("WithParens") {}, "@WithParens()"),
2222
#line: (
2323
CustomAttribute("WithArgs") {
24-
TupleExprElement(expression: "value1")
25-
TupleExprElement(label: "labelled", expression: "value2")
24+
TupleExprElement(expression: Expr("value1"))
25+
TupleExprElement(label: "labelled", expression: Expr("value2"))
2626
}, "@WithArgs(value1, labelled: value2)"
2727
),
2828
]

Tests/SwiftSyntaxBuilderTest/DoStmtTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ final class DoStmtTests: XCTestCase {
4343
},
4444
CatchClause {
4545
FunctionCallExpr(callee: ExprSyntax("print")) {
46-
TupleExprElement(expression: "error")
46+
TupleExprElement(expression: Expr("error"))
4747
}
4848
},
4949
]

Tests/SwiftSyntaxBuilderTest/FunctionTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ final class FunctionTests: XCTestCase {
4040
func testArguments() {
4141
let buildable = FunctionCallExpr(callee: ExprSyntax("test")) {
4242
for param in (1...5) {
43-
TupleExprElement(label: param.isMultiple(of: 2) ? "p\(param)" : nil, expression: "value\(raw: param)")
43+
TupleExprElement(label: param.isMultiple(of: 2) ? "p\(param)" : nil, expression: Expr("value\(raw: param)"))
4444
}
4545
}
4646
AssertBuildResult(buildable, "test(value1, p2: value2, value3, p4: value4, value5)")
@@ -130,15 +130,15 @@ final class FunctionTests: XCTestCase {
130130

131131
func testParensEmittedForArgumentAndTrailingClosure() {
132132
let buildable = FunctionCallExpr(callee: ExprSyntax("test"), trailingClosure: ClosureExpr()) {
133-
TupleExprElement(expression: "42")
133+
TupleExprElement(expression: Expr("42"))
134134
}
135135
AssertBuildResult(buildable, "test(42) {\n}")
136136
}
137137

138138
func testParensOmittedForNoArgumentsAndTrailingClosure() {
139139
let closure = ClosureExpr(statementsBuilder: {
140140
FunctionCallExpr(callee: ExprSyntax("f")) {
141-
TupleExprElement(expression: "a")
141+
TupleExprElement(expression: Expr("a"))
142142
}
143143
})
144144
let buildable = FunctionCallExpr(callee: ExprSyntax("test"), trailingClosure: closure)

Tests/SwiftSyntaxBuilderTest/VariableTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ final class VariableTests: XCTestCase {
176176
VariableDecl(
177177
attributes: AttributeList {
178178
CustomAttribute("WithArgs") {
179-
TupleExprElement(expression: "value1")
180-
TupleExprElement(label: "label", expression: "value2")
179+
TupleExprElement(expression: Expr("value1"))
180+
TupleExprElement(label: "label", expression: Expr("value2"))
181181
}
182182
},
183183
name: "z",
@@ -195,7 +195,7 @@ final class VariableTests: XCTestCase {
195195
VariableDecl(
196196
attributes: AttributeList {
197197
CustomAttribute("WithArgs") {
198-
TupleExprElement(expression: "value")
198+
TupleExprElement(expression: Expr("value"))
199199
}
200200
},
201201
modifiers: [DeclModifier(name: .public)],

0 commit comments

Comments
 (0)