Skip to content
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

[SR-14878] Enum cases with associated values cannot be marked potentially unavailable with '@available' #57225

Closed
swift-ci opened this issue Jul 6, 2021 · 8 comments

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Jul 6, 2021

Previous ID SR-14878
Radar rdar://problem/80238318
Original Reporter Gereon (JIRA User)
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

Xcode 13 beta 2 on macOS 11.4 (Intel)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 7d073033bcd79fe82b5f2ab19dd0d073

Issue Description:

Code that uses `@available` for enum cases that have associated values no longer compiles:

enum Foo {
@available(iOS 13.0, *)
case bar(Int)
case baz
}

This code compiled fine in Xcode12, but doesn't in Xcode 13 (both beta 1 and 2)

@typesanitizer
Copy link

typesanitizer commented Jul 7, 2021

Not able to reproduce with Xcode 13 beta 2 or main. Is that the only code, or is there more to it? Are you seeing a compiler error (if so, what is the error)? Is the problem that the availability annotations are not being honored correctly?

@swift-ci create

@swift-ci
Copy link
Collaborator Author

swift-ci commented Jul 7, 2021

Comment by Gereon Steffens (JIRA)

The attached project shows the issue, it builds in Xcode 12.5.1 and fails to build in Xcode 13 beta 2.

The error message is

Enum cases with associated values cannot be marked potentially unavailable with '@available'

on line 11 of ViewController.swift.

A couple of other reports of this issue can be found at https://developer.apple.com/forums/thread/682351

@swift-ci
Copy link
Collaborator Author

swift-ci commented Jul 7, 2021

Comment by Gereon Steffens (JIRA)

I first came across this issue when trying to build a project targeting iOS 12, which includes the SwiftMessages library, and building that failed on https://github.com/SwiftKickMobile/SwiftMessages/blob/master/SwiftMessages/SwiftMessages.swift#L82

@typesanitizer
Copy link

typesanitizer commented Jul 7, 2021

Huh, that's weird. I don't see the error when the availability annotation uses 13.0 but I do see the error when it is 14.0. The app's own deployment target is 13.0, which seems related.

@CodaFi
Copy link
Member

CodaFi commented Jul 7, 2021

This is intentional. The ABI of enum cases with payloads that are potentially unavailable is not well-defined. That this worked in the past was by coincidence of your application not requiring the (potentially unavailable) type metadata for the payload. Please either increase your deployment target or mark Foo itself as available as the least-available case.

#36327

@swift-ci
Copy link
Collaborator Author

swift-ci commented Aug 31, 2021

Comment by Spandana Batchu (JIRA)

Gereon (JIRA User) Im using SwiftMessages library and I see the same issue with Xcode 13 Beta. How did you resolve the issue?

@CodaFi
Copy link
Member

CodaFi commented Aug 31, 2021

spandanabatchu (JIRA User) You (or SwiftMessages) must resolve this issue by either

1) Increasing your deployment target
2) Lowering the availability restriction
3) Removing the annotation altogether

The compiler is warning you that the availability bounds there are not meaningful and may lead to poor behavior if relied upon for their intended purpose.

@swift-ci
Copy link
Collaborator Author

swift-ci commented Aug 31, 2021

Comment by Gereon Steffens (JIRA)

spandanabatchu (JIRA User) there is a workaround described here: SwiftKickMobile/SwiftMessages#471 (comment)

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants