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-10995] Compiler emits "empty enum" warning for Optional<Never> #53385

Closed
swift-ci opened this issue Jun 21, 2019 · 3 comments
Closed

[SR-10995] Compiler emits "empty enum" warning for Optional<Never> #53385

swift-ci opened this issue Jun 21, 2019 · 3 comments
Assignees
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-10995
Radar None
Original Reporter erikstrottmann (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Apple Swift version 5.0.1 (swiftlang-1001.0.82.4 clang-1001.0.46.5)
Target: x86_64-apple-darwin18.6.0

macOS 10.14.5 Mojave
Swift 5.0.1 bundled with Xcode 10.2.1 (10E1001)

Issue is reproducible both in Xcode and with the swift CLI.

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

md5: cdc218f85104802ae78791de0fee0ad7

Issue Description:

The Swift compiler emits a warning when a variable is inferred to have a type that is an empty enum like Never. An easy way to trigger this is by assigning the result of a function that returns Never to a variable:

let never = fatalError() // warning: constant 'never' inferred to have type 'Never', which is an enum with no cases

However, the compiler also emits this warning for variables inferred to be Never?, but warning is not accurate in that case, because Never? is an enum with two cases, `some` and `none` (though of course, a valid of Never?.some is as impossible as a value of Never).

func makeOptionalNever() -> Never? {
    return nil
}

let optionalNever = makeOptionalNever() // warning: constant 'optionalNever' inferred to have type 'Never?', which is an enum with no cases

The compiler does not emit the warning for variables inferred to be Never??:

func makeDoubleOptionalNever() -> Never?? {
    return nil
}

let doubleOptionalNever = makeDoubleOptionalNever() // no warning
@belkadan
Copy link
Contributor

cc @xedin, @Azoy

@theblixguy
Copy link
Collaborator

PR: #25719

@theblixguy
Copy link
Collaborator

Fixed on master.

@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
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

3 participants