-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Extend transitive availability checking to initial value expressions #22438
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
Conversation
Because initial value expressions aren't actually considered /within/ the VarDecl or PatternBindingDecl they're initializing, the existing logic to search for availability attributes wasn't kicking in, leading to errors when a conditionally-unavailable value was used in an initial value expression for a conditionally-unavailable binding. https://bugs.swift.org/browse/SR-9867
@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.
If the comment below doesn't prompt any changes, this looks good to me.
var osx_init_osx = osx() // OK | ||
|
||
@available(OSXApplicationExtension, unavailable) | ||
var osx_extension_init_osx = osx() // expected-error {{'osx()' is unavailable}} |
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.
Would this test pass?
@available(OSX, unavailable)
var osx_inner_init_osx = { let inner_var = osx() }
If so, is it worth adding to the test suite? If not, do we want to merge this change anyway?
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.
Definitely seems worth adding! I think it'll work with this change, but it's always worth checking.
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.
Aha, it does not work. Important info!
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.
I'm going to look at this this afternoon, and if there's not an easy fix maybe we'll just take this part.
Found a better approach, will open a new PR for that. |
Because initial value expressions aren't actually considered within the VarDecl or PatternBindingDecl they're initializing, the existing logic to search for availability attributes wasn't kicking in, leading to errors when a conditionally-unavailable value was used in an initial value expression for a conditionally-unavailable binding.
SR-9867 / rdar://problem/47852718