-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Sema: Narrow fix to allow @_spi_available
in extensions
#84238
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// RUN: %empty-directory(%t) | ||
// RUN: %target-typecheck-verify-swift \ | ||
// RUN: -enable-library-evolution -swift-version 5 \ | ||
// RUN: -library-level=api -require-explicit-availability=ignore | ||
|
||
// REQUIRES: OS=macosx | ||
|
||
@_spi_available(macOS, introduced: 12.0) @available(iOS 12.0, *) | ||
public struct SPIAvailableType { // expected-note {{struct declared here}} | ||
public init() {} | ||
} | ||
|
||
@_spi(S) | ||
public struct NormalSPIType { | ||
public init() {} | ||
} | ||
|
||
// SPI available in SPI available should be accepted. | ||
|
||
@_spi_available(macOS, introduced: 12.0) @available(iOS 12.0, *) | ||
public struct OtherSPIAvailableType { | ||
public func foo(s: SPIAvailableType) {} | ||
} | ||
|
||
extension OtherSPIAvailableType { | ||
public func bar(s: SPIAvailableType) {} // expected-error {{cannot use struct 'SPIAvailableType' here; it is SPI}} // FIXME We should allow this. | ||
} | ||
|
||
// Normal SPI in normal SPI should be accepted. | ||
|
||
@_spi(S) | ||
public struct OtherNormalSPIType { | ||
public func foo(s: SPIAvailableType) {} | ||
} | ||
|
||
extension OtherNormalSPIType { | ||
public func bar2(s: SPIAvailableType) {} | ||
} | ||
|
||
// Normal SPI in SPI available should be rejected. | ||
|
||
@_spi_available(macOS, introduced: 12.0) @available(iOS 12.0, *) | ||
public func SPIAvailableToSPI(s: NormalSPIType) {} // FIXME This should be an error | ||
|
||
@inlinable | ||
@_spi_available(macOS, introduced: 12.0) @available(iOS 12.0, *) | ||
public func inlinableSPIAvailable() { | ||
let _: NormalSPIType = NormalSPIType() // FIXME There should be many errors here | ||
} | ||
|
||
// SPI available in normal SPI is currently accepted. | ||
|
||
@_spi(S) | ||
public func SPIToSPIAvailable(s: NormalSPIType) {} | ||
|
||
@inlinable | ||
@_spi(S) | ||
public func inlinableSPI() { | ||
let _: SPIAvailableType = SPIAvailableType() | ||
} |
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 won't handle a case like this:
It's probably not worth addressing now, though. We should aim to support that with a more holistic fix though.
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.
Right, we'd need to properly propagate the
@_spi_available
-ness across contexts. That will need a wider fix as the current mechanism for it is mixed in with the normal SPI and probably shouldn't be.