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-4079] Availability of enum case does not propagate to its switch case scope. #46662

Open
swift-ci opened this issue Feb 26, 2017 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-4079
Radar rdar://problem/20937722
Original Reporter andersha (JIRA User)
Type Bug
Environment

Xcode 8.2.1 (8C1002)

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

md5: de37f303f2707187e9cee8954de0adbf

relates to:

  • SR-4196 Allow #if (conditional compilation) to guard switch cases

Issue Description:

When matching against a case with minimum API requirement, the scope logically inherits the requirement from the case. But the compiler currently does not propagate the requirement, and requires a fallback to dynamic `#available` checks.

import MachO

enum Lock {
    @available(macOS 10.12, *)
    case unfairLock(os_unfair_lock_t)

    func lock() {
        switch self {
        case let .unfairLock(lock):
            // Unreachable in macOS version <10.12, but
            // `#available` is still required here for a green light
            // from the compiler.
            os_unfair_lock_lock(lock)
        }
    }
}
@belkadan
Copy link
Contributor

This isn't quite a Starter Bug, but if anyone wants to pick it up, the relevant code is the TypeRefinementContextBuilder in TypeCheckAvailability.cpp.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

2 participants