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-14188] Extend "Literal value is already handled by previous pattern" to nil literals #56566

Open
swift-ci opened this issue Feb 11, 2021 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-14188
Radar None
Original Reporter jumhyn (JIRA User)
Type Bug
Additional Detail from JIRA
Votes 0
Component/s
Labels Bug
Assignee None
Priority Medium

md5: e4c7d0cd85360f93068188fda33a0878

Issue Description:

The following example prints `false`, because the `case nil, nil` is not matched by the passed value. This is because `case nil, nil` is treated as two separate patterns, equivalent to:

case nil:
    fallthrough
case nil:
    ...
func check(_ arg1: Int?, _ arg2: Int?) -> Bool {
    switch (arg1, arg2) {
    case (.some(let val1), .some(let val2)):
        return val1 > val2
    case nil, nil:
        return true
    default:
        return false
    }
}

print(check(nil, nil))

We have a check that diagnoses and warns about other duplicate literals, so we should probably extend that to `nil` literals as well!

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

No branches or pull requests

1 participant