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-14993] Missed warning for redundant .some(_) case in the presence of implicit wrapping #57335

Open
typesanitizer opened this issue Jul 31, 2021 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@typesanitizer
Copy link

Previous ID SR-14993
Radar rdar://problem/81357517
Original Reporter @typesanitizer
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: f95d824e2da4264fbbf4de7621741d1e

Issue Description:

Originally noticed here: https://forums.swift.org/t/odd-inconsistent-compile-warning-for-optional-of-enum/50780/8

enum E {
    case e1
}
func f(_ e: E?) {
    switch e {
    case .e1: ()
    case .none: ()
    default: () // warning: default will never be executed
    }
    switch e {
    case .e1: ()
    case .none: ()
    case .some(_): () // no warning :O
    }
}
 

The .some(_) example should also emit a warning.

If you look at -dump-ast the two patterns are different, the .e1 will be a pattern_optional_some implicit whereas the .some(_) will be a pattern_enum_element type='E?' E?.some .

I don't know for sure, but I have a gut feeling that the problem is due to this dual representation. If that's actually the case, trivially canonicalizing the pattern may not be enough (e.g. we could potentially map one kind of pattern to the other to avoid two representations for the same logical thing) because that could end up regressing diagnostics. Introducing a distinction Pattern vs CanPattern (akin to Type vs CanType) distinction seems a bit overkill for this one thing but it may be the best long-term solution...

Tested with Xcode 13 beta 3.

@typesanitizer
Copy link
Author

@swift-ci create

@CodaFi
Copy link
Member

CodaFi commented Aug 18, 2021

We could start warning when the unknown default isn't required. Should be an easy fix.

@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