Skip to content

Commit 5ad7814

Browse files
committed
Add convenience initializer for ReturnClause
1 parent 6859f75 commit 5ad7814

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import SwiftSyntax
14+
15+
extension ReturnClause: ExpressibleByStringLiteral {
16+
public init(stringLiteral value: String) {
17+
self.init(returnType: value)
18+
}
19+
}

Sources/SwiftSyntaxBuilder/StringConvenienceInitializers.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ extension String: ExpressibleAsStringLiteralExpr {
3434
}
3535
}
3636

37+
extension String: ExpressibleAsReturnClause {
38+
public func createReturnClause() -> ReturnClause {
39+
ReturnClause(stringLiteral: self)
40+
}
41+
}
42+
3743
/// Default conformance to `ExpressibleByTypeBuildable`
3844
extension String {
3945
public func createTypeBuildable() -> TypeBuildable {

Tests/SwiftSyntaxBuilderTest/FunctionTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ final class FunctionTests: XCTestCase {
1414
ReturnStmt(expression: IntegerLiteralExpr(digits: "n"))
1515
})
1616

17-
let signature = FunctionSignature(input: input, output: ReturnClause(returnType: "Int"))
17+
let signature = FunctionSignature(input: input, output: "Int")
1818

1919

2020
let codeBlock = CodeBlock(statementsBuilder: {

0 commit comments

Comments
 (0)