Skip to content

Instantly share code, notes, and snippets.

@mayoff
Created February 23, 2019 03:00
Show Gist options
  • Save mayoff/2c788003c1b5161da36bec807cc2a8e5 to your computer and use it in GitHub Desktop.
Save mayoff/2c788003c1b5161da36bec807cc2a8e5 to your computer and use it in GitHub Desktop.
test Swift unowned safety
class MyObject { }
var o = MyObject()
print("strong o = \(o)")
unowned let u = o
print("unowned u = \(u)")
o = MyObject()
print("new strong o = \(o)")
print("old unowned u = \(u)")
@robertmryan
Copy link

robertmryan commented Feb 25, 2019

@hamishknight - that was in Swift 4.2.1.

Apple Swift version 4.2.1 (swiftlang-1000.11.42 clang-1000.11.45.1)

@hamishknight
Copy link

@robertmryan Ah interesting! Sorry, I missed that part in your original post. Upon re-inspection, you get the same behaviour in 4.2 and 5.0 – it just appears to be sometimes hitting the runtime error and sometimes crashing with EXC_BAD_ACCESS. Digging a bit further, when running with an assert Swift runtime it trips an assertion.

Filed a bug: SR-9999.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment