Skip to content

Sema: Ban unavailable stored properties #64885

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 2 commits into from
Apr 5, 2023

Conversation

tshortli
Copy link
Contributor

@tshortli tshortli commented Apr 4, 2023

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 added 2 commits April 4, 2023 08:52
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 branch from d6bd513 to 9812c90 Compare April 4, 2023 15:53
@tshortli
Copy link
Contributor Author

tshortli commented Apr 4, 2023

@swift-ci please test

@tshortli
Copy link
Contributor Author

tshortli commented Apr 4, 2023

@swift-ci please clean test macOS

@tshortli tshortli merged commit 24a3317 into swiftlang:main Apr 5, 2023
@tshortli tshortli deleted the ban-unavailable-stored-properties branch April 5, 2023 05:27
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.

1 participant