Skip to content

[5.9] Sema: Ban unavailable deinits #64844

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

Conversation

tshortli
Copy link
Contributor

@tshortli tshortli commented Apr 1, 2023

Cherry pick of #64843

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 #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 tshortli requested a review from a team as a code owner April 1, 2023 21:32
@tshortli
Copy link
Contributor Author

tshortli commented Apr 1, 2023

@swift-ci please test

@tshortli tshortli added 🍒 release cherry pick Flag: Release branch cherry picks swift 5.9 labels Apr 1, 2023
@tshortli
Copy link
Contributor Author

tshortli commented Apr 1, 2023

@swift-ci please test source compatibility

@tshortli tshortli merged commit 77d89e5 into swiftlang:release/5.9 Apr 3, 2023
@tshortli tshortli deleted the ban-unavailable-deinit-5.9 branch April 3, 2023 05:15
@tshortli tshortli linked an issue Apr 3, 2023 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍒 release cherry pick Flag: Release branch cherry picks swift 5.9
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Swift allows & calls @available(*, unavailable) deinit
2 participants