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-11014] Using a void return immediately before an @unknown default results in a compilation error #53404

Closed
gfontenot opened this issue Jun 25, 2019 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.

Comments

@gfontenot
Copy link

Previous ID SR-11014
Radar None
Original Reporter @gfontenot
Type Bug
Status Resolved
Resolution Duplicate
Environment

Swift 5.0, Xcode 10.2

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

md5: 7e8bfa15a3c43f075b068cb3bc6bda4e

duplicates:

  • SR-9920 Compiler error when an empty "return" precedes an "@unknown default" case.

Issue Description:

If the final case in a switch statement has a void return statement and you add an @unknown default statement after it, the compiler seems to interpret the default statement as being a continuation of the return. To fix the compiler, you need to explicitly return ().

Sample code exhibiting the issue:

enum Foo {
    case one
    case two
    case three
}

func something(foo: Foo) {
    switch foo {
    case .one:
        break
    case .two:
        break
    case .three:
        return

    @unknown default:
        return
    }
}
@belkadan
Copy link
Contributor

Fixed in Swift 5.1!

@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.
Projects
None yet
Development

No branches or pull requests

2 participants