Avatar
swiftbot BOT 1/11/2019 3:20 AM
Author icon
rintaro
struct HaveResult { var resultCode = 0 mutating func returnResultCode(_ value: Int) -> Int { return resultCode } } public func testA() { var r = HaveResult() print(r.returnResultCode(changeResult(r: &r))) } func testA_variant() { var r = HaveResult() var r2 = r print(r2.returnResultCode(changeResult(r: &r))) } func testB() { var r = HaveResult() var x = changeResult(r: &r) print(r.returnResultCode(x)) } func changeResult(r: inout HaveResult) -> Int { r.resultCode = 1 return 0 } testA() testA_variant() testB()
Version:
swift-4.2.1-RELEASE
Output:
1 0 1
Error:
/usercode/main.swift:22:9: warning: variable 'x' was never mutated; consider changing to 'let' constant var x = changeResult(r: &r) ~~~ ^ let