Skip to content

Sema: Ban unavailable deinits #64843

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 3, 2023

Conversation

tshortli
Copy link
Contributor

@tshortli tshortli commented Apr 1, 2023

Destructors are always called if declared, so allowing deinit to be declared as unavailable (or potentially unavailable) creates a type checking loophole that allows unavailable code to execute at runtime:

class C {
  @available(*, unavailable)
  deinit {
    print("Oops")
  }
}

_ = C() // prints "Oops"

Resolves rdar://106409012, resolves #63854.

Destructors are always called if declared, so allowing deinit to be declared as
unavailable (or potentially unavailable) creates a type checking loophole that
allows unavailable code to execute at runtime:

```
class C {
  @available(*, unavailable)
  deinit {
    print("Oops")
  }
}

_ = C() // prints "Oops"
```

Resolves rdar://106409012 and swiftlang#63854.
@tshortli
Copy link
Contributor Author

tshortli commented Apr 1, 2023

@swift-ci please test

@tshortli tshortli merged commit 9886ff6 into swiftlang:main Apr 3, 2023
@tshortli tshortli deleted the ban-unavailable-deinit branch April 3, 2023 05:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Swift allows & calls @available(*, unavailable) deinit
1 participant