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

- 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 committed Feb 29, 2024
1 parent 2e4e2ae commit aab4541
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 else {
return
}

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

Expand Down

0 comments on commit aab4541

Please sign in to comment.