-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Sema] Perform availability checks in literals initializers #61805
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
[Sema] Perform availability checks in literals initializers #61805
Conversation
@swift-ci Please test |
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.
Thanks! I think we probably ought to apply this logic to the result type of the literal too, but I'm happy for that to be done in a follow up if you want. cc @tshortli in case he has any other comments.
// Regex literals require both the Regex<Output> type to be available, | ||
// as well as the initializer that is implicitly called. | ||
diagnoseDeclRefAvailability(Context.getRegexDecl(), Range); |
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 wonder if this is something that ought to be applied to the result type of a literal in general. e.g for:
@available(*, unavailable)
struct S: ExpressibleByIntegerLiteral {
init(integerLiteral value: Int) {}
}
@available(*, unavailable)
typealias IntegerLiteralType = S
let i = 0
We're implicitly forming a call to S(integerLiteral: 0)
, but aren't erroring that it's 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.
A long term goal of mine is to run availability checks on the transformed AST so that we can catch these issues in a more generalized way. Not sure if that applies directly here but it seems like it might.
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.
Yeah these literal cases are tricky because we don't actually form the call in the AST, we emit them directly in SILGen
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 wonder if this is something that ought to be applied to the result type of a literal in general.
I'll create an issue to track that case and look at it separately =]
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.
@hamishknight @tshortli Issue created #61890
@@ -0,0 +1,169 @@ | |||
// RUN: %target-typecheck-verify-swift -swift-version 5 |
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 love the thoroughness of this test, thanks!
Some literal initializers were not being handled in
ExprAvailabilityWalker
which make then being left undiagnosed in cases like:So this adds check for all literals that have an associated implicit initializer and collection literal as well.
Fixes #61564