Skip to content

Commit dc82c99

Browse files
BridgeJS: Fix unused result warnings
1 parent b778856 commit dc82c99

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,19 @@ public struct ImportTS {
178178
rightParen: .rightParenToken()
179179
)
180180

181-
if returnType == .void {
182-
body.append(CodeBlockItemSyntax(item: .stmt(StmtSyntax(ExpressionStmtSyntax(expression: callExpr)))))
183-
} else if returnType.usesSideChannelForOptionalReturn() {
184-
// Side channel returns don't need "let ret ="
185-
body.append(CodeBlockItemSyntax(item: .stmt(StmtSyntax(ExpressionStmtSyntax(expression: callExpr)))))
181+
let needsRetBinding: Bool
182+
let liftingInfo = try returnType.liftingReturnInfo(context: context)
183+
if liftingInfo.valueToLift == nil || returnType.usesSideChannelForOptionalReturn() {
184+
// Void and side-channel returns don't need "let ret ="
185+
needsRetBinding = false
186186
} else {
187+
needsRetBinding = true
188+
}
189+
190+
if needsRetBinding {
187191
body.append("let ret = \(raw: callExpr)")
192+
} else {
193+
body.append(CodeBlockItemSyntax(item: .stmt(StmtSyntax(ExpressionStmtSyntax(expression: callExpr)))))
188194
}
189195

190196
// Add exception check for ImportTS context

Plugins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSCodegenTests/JSValue.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ fileprivate func bjs_jsEchoJSValue(_ valueKind: Int32, _ valuePayload1: Int32, _
141141

142142
func _$jsEchoJSValue(_ value: JSValue) throws(JSException) -> JSValue {
143143
let (valueKind, valuePayload1, valuePayload2) = value.bridgeJSLowerParameter()
144-
let ret = bjs_jsEchoJSValue(valueKind, valuePayload1, valuePayload2)
144+
bjs_jsEchoJSValue(valueKind, valuePayload1, valuePayload2)
145145
if let error = _swift_js_take_exception() {
146146
throw error
147147
}

Tests/BridgeJSRuntimeTests/Generated/BridgeJS.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7959,7 +7959,7 @@ fileprivate func bjs_globalObject1_get() -> Void {
79597959
#endif
79607960

79617961
func _$globalObject1_get() throws(JSException) -> JSValue {
7962-
let ret = bjs_globalObject1_get()
7962+
bjs_globalObject1_get()
79637963
if let error = _swift_js_take_exception() {
79647964
throw error
79657965
}
@@ -8083,7 +8083,7 @@ fileprivate func bjs_jsRoundTripJSValue(_ vKind: Int32, _ vPayload1: Int32, _ vP
80838083

80848084
func _$jsRoundTripJSValue(_ v: JSValue) throws(JSException) -> JSValue {
80858085
let (vKind, vPayload1, vPayload2) = v.bridgeJSLowerParameter()
8086-
let ret = bjs_jsRoundTripJSValue(vKind, vPayload1, vPayload2)
8086+
bjs_jsRoundTripJSValue(vKind, vPayload1, vPayload2)
80878087
if let error = _swift_js_take_exception() {
80888088
throw error
80898089
}

0 commit comments

Comments
 (0)