forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Sema] Check availability in inlinable code using the explicit version
Inlinable functions can be inlined in clients with a lower OS target version than the framework defining the function. For this reason, the availability in inlinable functions should always be checked using the explicit introduction OS version as lower bound and not the minimum deployment version. rdar://problem/67975153
- Loading branch information
Showing
4 changed files
with
103 additions
and
22 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/// Inlinable functions should check availability by ignoring the current | ||
/// deployment target as clients could inline the function in a lower target. | ||
|
||
// RUN: %target-typecheck-verify-swift -target %target-cpu-apple-macosx11.0 | ||
// RUN: %target-typecheck-verify-swift -target %target-cpu-apple-macosx10.10 | ||
|
||
// REQUIRES: OS=macosx | ||
|
||
@available(macOS 10.10, *) | ||
@inlinable | ||
public func availMacOS10() { | ||
availMacOS11() // expected-error {{'availMacOS11()' is only available in macOS 11.0 or newer}} | ||
// expected-note @-1 {{add 'if #available' version check}} | ||
|
||
if #available(macOS 11.0, *) { | ||
availMacOS11() | ||
} else { | ||
availMacOS11() // expected-error {{'availMacOS11()' is only available in macOS 11.0 or newer}} | ||
// expected-note @-1 {{add 'if #available' version check}} | ||
} | ||
|
||
if #available(macOS 10.15, *) { | ||
availMacOS11() // expected-error {{'availMacOS11()' is only available in macOS 11.0 or newer}} | ||
// expected-note @-1 {{add 'if #available' version check}} | ||
} | ||
|
||
func nestedFunc() { | ||
availMacOS11() // expected-error {{'availMacOS11()' is only available in macOS 11.0 or newer}} | ||
// expected-note @-1 {{add 'if #available' version check}} | ||
} | ||
} | ||
|
||
@available(macOS 11.0, *) | ||
public func availMacOS11() { } | ||
|
||
@available(macOS 10.10, *) | ||
public struct StructAvailMacOS10 { | ||
@inlinable | ||
public func availabilityFromTheContextInlinable() { | ||
// expected-note @-1 {{add @available attribute to enclosing instance method}} | ||
availMacOS11() // expected-error {{'availMacOS11()' is only available in macOS 11.0 or newer}} | ||
// expected-note @-1 {{add 'if #available' version check}} | ||
|
||
availabilityFromContext() | ||
} | ||
|
||
public func availabilityFromContext() {} | ||
} |