-
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
[Diagnostics] Add support for updating the existing 'available' attribute. #72524
Open
CrazyFanFan
wants to merge
1
commit into
swiftlang:main
Choose a base branch
from
CrazyFanFan:feature/updating_existing_available_attribute
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// RUN: %swift -typecheck -verify -parse-stdlib -module-name Swift -target x86_64-apple-macosx10.10 %s | ||
|
||
@available(SwiftStdlib 5.1, *) | ||
func FooForDefineAvailability() {} | ||
|
||
@available(SwiftStdlib 5.0, *) | ||
func FooForDefineAvailabilityTest() { | ||
FooForDefineAvailability() | ||
// expected-error@-1 {{'FooForDefineAvailability()' is only available in macOS 10.15 or newer}} | ||
// expected-note@-2 {{add 'if #available' version check}} | ||
} | ||
|
||
@available(*, unavailable) | ||
func FooForUnavailable() {} // expected-note {{'FooForUnavailable()' has been explicitly marked unavailable here}} | ||
|
||
func FooForUnavailableTest() { | ||
FooForUnavailable() | ||
// expected-error@-1 {{'FooForUnavailable()' is unavailable}} | ||
} | ||
|
||
@available(macOS, introduced: 10.15) | ||
func FooForAvailability() {} | ||
|
||
@available(macOS, introduced: 10.10) | ||
func FooForAvailabilityTest() { | ||
// expected-note@-1 {{update @available attribute for macOS from '10.10' to '10.15' to meet the requirements of 'FooForAvailability'}} {{24:31-36=10.15}} | ||
FooForAvailability() | ||
// expected-error@-1 {{'FooForAvailability()' is only available in macOS 10.15 or newer}} | ||
// expected-note@-2 {{add 'if #available' version check}} | ||
} | ||
|
||
@available(macOS 10.15, iOS 13, *) | ||
func FooForAvailability2() { | ||
} | ||
|
||
@available(macOS 10.10, *) | ||
func FooForAvailability2Test() { | ||
// expected-note@-1 {{update @available attribute for macOS from '10.10' to '10.15' to meet the requirements of 'FooForAvailability2'}} {{36:18-23=10.15}} | ||
FooForAvailability2() | ||
// expected-error@-1 {{'FooForAvailability2()' is only available in macOS 10.15 or newer}} | ||
// expected-note@-2 {{add 'if #available' version check}} | ||
} | ||
|
||
@available(macOS 10.15, *) | ||
func FooForUnavailable2() {} | ||
|
||
@available(macOS, unavailable) | ||
func FooForUnavailable2Test() { | ||
FooForUnavailable2() | ||
// expected-error@-1 {{'FooForUnavailable2()' is only available in macOS 10.15 or newer}} | ||
// expected-note@-2 {{add 'if #available' version check}} | ||
} | ||
|
||
@available(macOS 10.15, *) | ||
func FooForDeprecated() {} | ||
|
||
@available(macOS, deprecated: 12) | ||
func FooForDeprecatedTest() { | ||
FooForDeprecated() | ||
// expected-error@-1 {{'FooForDeprecated()' is only available in macOS 10.15 or newer}} | ||
// expected-note@-2 {{add 'if #available' version check}} | ||
} | ||
|
||
@available(*, deprecated) | ||
func FooForDeprecatedTest2() { | ||
FooForDeprecated() | ||
// expected-error@-1 {{'FooForDeprecated()' is only available in macOS 10.15 or newer}} | ||
// expected-note@-2 {{add 'if #available' version check}} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 like it'll do the right thing for attributes like:
@available(*, unavailable)
(just skips it)@available(macOS, introduced: 10.15)
@available(macOS 10.15, iOS 13, *)
But what if you have something like these? Are there any tests cases like them?
@available(macOS, unavailable)
@available(macOS, deprecated: 12)
(You could just bail out for these like you do for unconditionally unavailable attributes, or you could make your fix-it insert
, introduced: 11
after the platform name in these cases.)Also:
@available(*, deprecated)
(For this, you probably either have to bail out or you have to act as though there is no active attribute and offer to insert a new one.)
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.
For the
deprecated
, I personally believe it is unnecessary to continue expanding to support new capabilities.The same for unavailable methods, unless a developer actively removes the
unavailable
attribute, we should not consider expanding to support new capabilities.Therefore, I think
return
is a good idea.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.
Okay. If you don't want to handle those cases (except by
return
ing), I would file a follow-up issue suggesting that they could be supported in the future.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 would also suggest add test cases for those kind of attributes in this PR as extra scenarios if we don't already.