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-3768] The {{Never}} type has misleading compiler diagnostic messages #46353

Open
swift-ci opened this issue Jan 27, 2017 · 1 comment
Open
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-3768
Radar None
Original Reporter bnut (JIRA User)
Type Bug

Attachment: Download

Environment

$ xcodebuild -version
Xcode 8.2.1
Build version 8C1002

$ swift build --version
Apple Swift Package Manager - Swift 3.0.2 (swiftpm-11750)

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

md5: ecdf0cb654b8102fdf29aa61c8f56466

Issue Description:

Using the Never type in other types gives misleading compiler warning and errors, unless it's used correctly as a return type.

extension Never: Error {}
struct SomeError: Error {}

func throwButNoReturn() throws -> Never { throw SomeError() }

_ = try? throwButNoReturn()

// UNEXPECTED: warning: will never be executed
print("made it!")

do {
    try throwButNoReturn()
}
// EXPECTING: warning: will never be executed
catch is Never {
    fatalError("never")
}
enum Action {
// EXPECTING: error: Never cannot be used as an associated value in an enum
    case youDown(Never)
    case giveYouUp(Never)
}

func goingTo() -> Action { exit(EXIT_SUCCESS) }

switch goingTo() {
case let .youDown(x):
    break
// UNEXPECTED: error: Switch must be exhaustive, consider adding a default clause
// If Never is allowed in an enum then those cases cannot be reached
}

// EXPECTING: warning: will never be executed
exit(EXIT_SUCCESS)
// CORRECT: warning: will never be executed
exit(EXIT_FAILURE)

Steps to reproduce:

swiftc Example1.swift &> Example1.swift.log
swiftc Example2.swift &> Example2.swift.log
@CodaFi
Copy link
Member

CodaFi commented Apr 29, 2017

#8908 addresses the switching side of this one.

@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