Skip to content

Commit

Permalink
Prevent Swift objects' deinit from trying to free a nil pointer whe…
Browse files Browse the repository at this point in the history
…n subclassed for mocking (#2001)

- doing so will result in a `Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value`
- deinit is not overridable in Swift and this cannot be handled in the subclass
  • Loading branch information
stefanceriu authored Feb 29, 2024
1 parent 2e4e2ae commit 77d3292
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ open class {{ impl_class_name }}:
{%- endmatch %}

deinit {
guard let pointer = pointer else {
return
}

try! rustCall { {{ obj.ffi_object_free().name() }}(pointer, $0) }
}

Expand Down

0 comments on commit 77d3292

Please sign in to comment.