Skip to content

Use generic parameter for TupleExprElement convenience initializer #1162

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/SwiftSyntaxBuilder/ConvenienceInitializers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ extension TernaryExpr {
extension TupleExprElement {
/// A convenience initializer that allows passing in label as an optional string.
/// The presence of the colon will be inferred based on the presence of the label.
public init(label: String? = nil, expression: ExprSyntax) {
public init<E: ExprSyntaxProtocol>(label: String? = nil, expression: E) {
self.init(
label: label.map { .identifier($0) },
colon: label == nil ? nil : .colonToken(),
Expand Down
4 changes: 2 additions & 2 deletions Tests/SwiftSyntaxBuilderTest/CustomAttributeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ final class CustomAttributeTests: XCTestCase {
#line: (CustomAttribute("WithParens") {}, "@WithParens()"),
#line: (
CustomAttribute("WithArgs") {
TupleExprElement(expression: "value1")
TupleExprElement(label: "labelled", expression: "value2")
TupleExprElement(expression: Expr("value1"))
TupleExprElement(label: "labelled", expression: Expr("value2"))
}, "@WithArgs(value1, labelled: value2)"
),
]
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftSyntaxBuilderTest/DoStmtTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ final class DoStmtTests: XCTestCase {
},
CatchClause {
FunctionCallExpr(callee: ExprSyntax("print")) {
TupleExprElement(expression: "error")
TupleExprElement(expression: Expr("error"))
}
},
]
Expand Down
6 changes: 3 additions & 3 deletions Tests/SwiftSyntaxBuilderTest/FunctionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ final class FunctionTests: XCTestCase {
func testArguments() {
let buildable = FunctionCallExpr(callee: ExprSyntax("test")) {
for param in (1...5) {
TupleExprElement(label: param.isMultiple(of: 2) ? "p\(param)" : nil, expression: "value\(raw: param)")
TupleExprElement(label: param.isMultiple(of: 2) ? "p\(param)" : nil, expression: Expr("value\(raw: param)"))
}
}
AssertBuildResult(buildable, "test(value1, p2: value2, value3, p4: value4, value5)")
Expand Down Expand Up @@ -130,15 +130,15 @@ final class FunctionTests: XCTestCase {

func testParensEmittedForArgumentAndTrailingClosure() {
let buildable = FunctionCallExpr(callee: ExprSyntax("test"), trailingClosure: ClosureExpr()) {
TupleExprElement(expression: "42")
TupleExprElement(expression: Expr("42"))
}
AssertBuildResult(buildable, "test(42) {\n}")
}

func testParensOmittedForNoArgumentsAndTrailingClosure() {
let closure = ClosureExpr(statementsBuilder: {
FunctionCallExpr(callee: ExprSyntax("f")) {
TupleExprElement(expression: "a")
TupleExprElement(expression: Expr("a"))
}
})
let buildable = FunctionCallExpr(callee: ExprSyntax("test"), trailingClosure: closure)
Expand Down
6 changes: 3 additions & 3 deletions Tests/SwiftSyntaxBuilderTest/VariableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ final class VariableTests: XCTestCase {
VariableDecl(
attributes: AttributeList {
CustomAttribute("WithArgs") {
TupleExprElement(expression: "value1")
TupleExprElement(label: "label", expression: "value2")
TupleExprElement(expression: Expr("value1"))
TupleExprElement(label: "label", expression: Expr("value2"))
}
},
name: "z",
Expand All @@ -195,7 +195,7 @@ final class VariableTests: XCTestCase {
VariableDecl(
attributes: AttributeList {
CustomAttribute("WithArgs") {
TupleExprElement(expression: "value")
TupleExprElement(expression: Expr("value"))
}
},
modifiers: [DeclModifier(name: .public)],
Expand Down