-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[sema] Fix availability narrowing fixits for macOS >= 11 #76018
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
benlangmuir
merged 1 commit into
swiftlang:main
from
benlangmuir:fix-availability-narrowing-fixit
Aug 22, 2024
Merged
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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -1,69 +1,101 @@ | ||
// RUN: %target-typecheck-verify-swift | ||
// RUN: %target-typecheck-verify-swift -target %target-cpu-apple-macos10.15 | ||
// REQUIRES: OS=macosx | ||
// <rdar://problem/17669805> Suggest narrowing the range of bad availabile checks | ||
|
||
import Foundation | ||
|
||
@available(macOS 10.50.2, *) | ||
@available(macOS 50.2, *) | ||
func foo() { } | ||
|
||
func useFoo() { | ||
if #available(macOS 10.50.1, *) { | ||
foo() // expected-error {{'foo()' is only available in macOS 10.50.2 or newer}} {{-1:23-30=10.50.2}} | ||
if #available(macOS 50.1, *) { | ||
foo() // expected-error {{'foo()' is only available in macOS 50.2 or newer}} {{-1:23-27=50.2}} | ||
} | ||
} | ||
|
||
func useFooDifferentSpelling() { | ||
if #available(OSX 10.50.1, *) { | ||
foo() // expected-error {{'foo()' is only available in macOS 10.50.2 or newer}} {{-1:21-28=10.50.2}} | ||
if #available(OSX 50.1, *) { | ||
foo() // expected-error {{'foo()' is only available in macOS 50.2 or newer}} {{-1:21-25=50.2}} | ||
} | ||
} | ||
|
||
func useFooAlreadyOkRange() { | ||
if #available(OSX 10.51, *) { | ||
if #available(OSX 51, *) { | ||
foo() | ||
} | ||
} | ||
|
||
func useFooUnaffectedSimilarText() { | ||
if #available(iOS 10.50.10, OSX 10.50.1, *) { | ||
foo() // expected-error {{'foo()' is only available in macOS 10.50.2 or newer}} {{-1:35-42=10.50.2}} | ||
if #available(iOS 50.10, OSX 50.1, *) { | ||
foo() // expected-error {{'foo()' is only available in macOS 50.2 or newer}} {{-1:32-36=50.2}} | ||
} | ||
} | ||
|
||
func useFooWayOff() { | ||
// expected-note@-1{{add @available attribute to enclosing global function}} | ||
// expected-note@-1 2 {{add @available attribute to enclosing global function}} | ||
if #available(OSX 10.10, *) { | ||
foo() // expected-error {{'foo()' is only available in macOS 10.50.2 or newer}} | ||
foo() // expected-error {{'foo()' is only available in macOS 50.2 or newer}} | ||
// expected-note@-1{{add 'if #available' version check}} | ||
} | ||
|
||
if #available(OSX 49.0, *) { | ||
foo() // expected-error {{'foo()' is only available in macOS 50.2 or newer}} | ||
// expected-note@-1{{add 'if #available' version check}} | ||
} | ||
} | ||
|
||
@available(OSX 10.50, *) | ||
@available(OSX 50, *) | ||
class FooUser { | ||
func useFoo() { | ||
foo() // expected-error {{'foo()' is only available in macOS 10.50.2 or newer}} {{-3:16-21=10.50.2}} | ||
foo() // expected-error {{'foo()' is only available in macOS 50.2 or newer}} {{-3:16-18=50.2}} | ||
} | ||
} | ||
|
||
@available(OSX, introduced: 10.50, obsoleted: 10.50.4) | ||
@available(OSX, introduced: 50, obsoleted: 50.4) | ||
class FooUser2 { | ||
func useFoo() { | ||
foo() // expected-error {{'foo()' is only available in macOS 10.50.2 or newer}} {{-3:29-34=10.50.2}} | ||
foo() // expected-error {{'foo()' is only available in macOS 50.2 or newer}} {{-3:29-31=50.2}} | ||
} | ||
} | ||
|
||
@available(OSX, introduced: 10.50, obsoleted: 10.50.4) | ||
@available(OSX, introduced: 50, obsoleted: 50.4) | ||
@objc | ||
class FooUser3 : NSObject { | ||
func useFoo() { | ||
foo() // expected-error {{'foo()' is only available in macOS 10.50.2 or newer}} {{-4:29-34=10.50.2}} | ||
foo() // expected-error {{'foo()' is only available in macOS 50.2 or newer}} {{-4:29-31=50.2}} | ||
} | ||
} | ||
|
||
@available(OSX, introduced: 10.50.4) | ||
@available(OSX, introduced: 50.4) | ||
class FooUserOkRange { | ||
func useFoo() { | ||
foo() | ||
} | ||
} | ||
|
||
@available(macOS 10.50.2, *) | ||
func foo10() { } | ||
|
||
func useFoo10() { | ||
if #available(macOS 10.50.1, *) { | ||
foo10() // expected-error {{'foo10()' is only available in macOS 10.50.2 or newer}} {{-1:23-30=10.50.2}} | ||
} | ||
} | ||
|
||
func useFoo10WayOff() { | ||
// expected-note@-1 3 {{add @available attribute to enclosing global function}} | ||
if #available(OSX 10.10, *) { | ||
foo10() // expected-error {{'foo10()' is only available in macOS 10.50.2 or newer}} | ||
// expected-note@-1{{add 'if #available' version check}} | ||
} | ||
|
||
if #available(OSX 10.49.0, *) { | ||
foo10() // expected-error {{'foo10()' is only available in macOS 10.50.2 or newer}} | ||
// expected-note@-1{{add 'if #available' version check}} | ||
} | ||
|
||
if #available(OSX 9, *) { | ||
foo10() // expected-error {{'foo10()' is only available in macOS 10.50.2 or newer}} | ||
// expected-note@-1{{add 'if #available' version check}} | ||
} | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.