Skip to content

[5.9] Sema: Ban unavailable stored properties #64835

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 #64885.

Marking a stored property as unavailable with @available should be banned, just like it already is banned for potential unavailability. Unavailable code is not supposed be reachable at runtime, but unavailable properties with storage create a back door into executing arbitrary unavailable code at runtime:

@available(*, unavailable)
struct Unavailable {
  init() {
    print("Unavailable.init()")
  }
}

struct S {
  @available(*, unavailable)
  var x = Unavailable()
}

_ = S() // prints "Unavailable.init()"

Resolves rdar://107449845

@tshortli
Copy link
Contributor Author

tshortli commented Apr 1, 2023

@swift-ci please test Source Compatibility

@tshortli tshortli changed the title [5.9] Ban unavailable stored properties [5.9] Sema: Ban unavailable stored properties Apr 1, 2023
@tshortli tshortli force-pushed the ban-unavailable-stored-properties-5.9 branch 5 times, most recently from 833ba1d to a419f1c Compare April 3, 2023 05:19
@tshortli
Copy link
Contributor Author

tshortli commented Apr 3, 2023

@swift-ci please test source compatibility

@tshortli tshortli force-pushed the ban-unavailable-stored-properties-5.9 branch from a419f1c to 21abe32 Compare April 4, 2023 01:35
@tshortli tshortli added 🍒 release cherry pick Flag: Release branch cherry picks swift 5.9 labels Apr 4, 2023
@tshortli tshortli force-pushed the ban-unavailable-stored-properties-5.9 branch from 21abe32 to 48c2603 Compare April 4, 2023 03:35
tshortli added 2 commits April 4, 2023 08:33
Marking a stored property as unavailable with `@available` should be banned,
just like it already is banned for potential unavailability. Unavailable code
is not supposed be reachable at runtime, but unavailable properties with
storage create a back door into executing arbitrary unavailable code at
runtime:

```
@available(*, unavailable)
struct Unavailable {
  init() {
    print("Unavailable.init()")
  }
}

struct S {
  @available(*, unavailable)
  var x = Unavailable()
}

_ = S() // prints "Unavailable.init()"
```

Resolves rdar://107449845
@tshortli tshortli force-pushed the ban-unavailable-stored-properties-5.9 branch from 48c2603 to b81b05b Compare April 4, 2023 15:33
@tshortli
Copy link
Contributor Author

tshortli commented Apr 4, 2023

@swift-ci please test

@tshortli tshortli requested a review from nkcsgexi April 4, 2023 23:47
@tshortli tshortli marked this pull request as ready for review April 4, 2023 23:47
@tshortli tshortli requested a review from a team as a code owner April 4, 2023 23:47
@tshortli tshortli merged commit 7f22ad6 into swiftlang:release/5.9 Apr 5, 2023
@tshortli tshortli deleted the ban-unavailable-stored-properties-5.9 branch April 5, 2023 05:28
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.

2 participants