In some particular situation, Xcode debugger or lldb cli cannot correctly extract some value that returned by a async throw function and handled by guard let try?
.
Here is the minimum example:
import Dispatch
func test() async throws -> [Int] {
return [369]
}
let group = DispatchGroup()
group.enter()
let task = Task {
guard let res = try? await test() else { return }
print(res)
group.leave()
}
group.wait()
If added a break point at print(res)
, the debugger cannot show the value of res
.
Due to forum limitation, I cannot paste a screenshot here...
if use p res
or po res
at lldb cli, it shows:
(lldb) p res
error: expression failed to parse:
error: <EXPR>:3:1: error: cannot find 'res' in scope
res
^~~
(lldb) po res
error: expression failed to parse:
error: <EXPR>:3:1: error: cannot find 'res' in scope
res
^~~
If test()
returns a dict, or a costom struct, the issue retains. But if returned a trivial value like Int
, it acts normally.
Also, if remove the guard statement, make res a optional value(use let res = try? await test()
), debugger can extract the value.
Above results are compiled and run in this environment:
- Swift 5.6.1
- Xcode 13.4.1 (13F100)
- lldb-1316.0.9.46
- macOS 12.4
- x86_64 arch