It ought to be captured as unowned into the closure. It's fishy that it crashes with an assertion failure rather than a proper runtime trap, but it seems like this code ought to trap regardless, because the owning reference goes away before even the closure is formed.
Agreed. We should do a better job of diagnosing this at runtime, but essentially we're complaining when we copy the unowned reference into the closure that the reference is already dead, which seems like the right thing to do.
Indeed it should raise a runtime error – for context, the original issue was discovered when building without assertions where the code would sometimes trigger the correct runtime error and sometimes abort with EXC_BAD_ACCESS, which makes me feel like we have a race condition going on somewhere.
Environment
Swift version 5.0-dev (LLVM 6ddb64316c, Swift d17602a)
Target: x86_64-apple-darwin18.2.0
Additional Detail from JIRA
md5: 3dc353b8937cf7587df306c968f94c7f
Issue Description:
In a -O build, the following trips a runtime assertion:
Output:
The text was updated successfully, but these errors were encountered: