-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
Fix availability checking for stored properties and enum cases with associated values #36327
Fix availability checking for stored properties and enum cases with associated values #36327
Conversation
@xymus I suspect there are some similar edge cases with SPI that need to be straightened out. |
…the deployment target
This cannot be supported for the same reasons struct and class stored properties with potential unavailability cannot be supported. It is possible that some users relied on this, because it worked in some cases where the type metadata for the potentially unavailable type was not actually needed for anything (eg, if the type was @Frozen and trivial, or a simple class reference). If this becomes an issue we can downgrade this to a warning. Note that just like the previous fix for stored properties, we do still allow writing an '@available' attribute on the enum element if the OS version is not any newer than the deployment target. This allows annotating APIs with the OS version where they were introduced.
e5a676f
to
511ada4
Compare
@swift-ci Please test |
@swift-ci Please test source compatibility |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good!
Build failed |
@swift-ci Please test Linux |
I believe the second commit message should say "as new as the enclosing availability context"? |
In swiftlang#36327, trying to compile library code where a struct has an unavailable stored property or an enum with an unavailable case with associated values was made into a hard error. Update the docs to reflect this limitation for library authors shipping new versions of dylibs to older OSes.
@slavapestov Why It Not work in Xcode14-beta now? |
The old behavior:
@available
at all.@available
without restriction.When computing the in-memory layout of a type we require that all stored types are available at runtime, that is, not any newer than the intersection of the current deployment target and the availability context of their type.
This means that stored properties and enum elements with associated values must have the same availability checking behavior as each other, and also that both existing behaviors were wrong.
The new rule is that
@available
is only allowed on either kind of declaration if the OS version is not any newer than the enclosing availability context.