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

[SILGen] Silence redundant unreachable enum case warning #33336

Merged
merged 1 commit into from Aug 22, 2020
Merged

[SILGen] Silence redundant unreachable enum case warning #33336

merged 1 commit into from Aug 22, 2020

Conversation

theblixguy
Copy link
Collaborator

@theblixguy theblixguy commented Aug 6, 2020

When an enum case is already handled, for example:

enum Foo { case a, b }
func takesFoo(arg: Foo) {
  switch arg {
    case _: break
    case .b: break
  }
}

We would get two warnings on case .b: case is already handled by previous patterns; consider removing it & case will never be executed. The first warning comes from Space Engine and the second warning comes from SILGenPattern.

So, silence the (redundant) warning emitted by SILGenPattern for switch statements (except default case).

Resolves #54657
Resolves rdar://problem/59655513

@jckarter
Copy link
Member

jckarter commented Aug 6, 2020

IIRC there isn't perfect overlap between the two diagnostics, so disabling either one will cause us to miss cases the other doesn't catch either. @CodaFi how does this sound to you now?

@CodaFi
Copy link
Member

CodaFi commented Aug 6, 2020

The space engine only has incomplete redundancy checking for expression patterns - there we do something awful that approximates redundancy checking for (non-range) literals. Proper patterns always emit overlap diagnostics, so we could at least ditch SIL's diagnostics for those cases.

@theblixguy
Copy link
Collaborator Author

theblixguy commented Aug 6, 2020

I have updated the implementation to check for ExprPatterns and continue to emit the diagnostic in that case.

Is there a test case that triggers redundant warning for ExprPattern today? I tried a few test cases but it doesn’t seem to trigger redundant diagnostics.

@theblixguy
Copy link
Collaborator Author

Ping. Does the change look good now @CodaFi?

@theblixguy
Copy link
Collaborator Author

Ping.

Copy link
Member

@CodaFi CodaFi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Joe can sign off on SIL.

Copy link
Member

@jckarter jckarter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me too.

@theblixguy
Copy link
Collaborator Author

@swift-ci please smoke test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants