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-13521] Improve diagnostic when exhaustiveness checking fails due to custom match functions #55957
Comments
@swift-ci create |
I want to try to work on this, if no one has claimed it yet. I will need some help pointing me to the right direction first, though. I searched for the string "switch must be exhaustive" in Swift's repository, and it didn't give me much helpful information. It will be great if someone could show me where the diagnostics messages are produced, and which files are responsible for checking switch cases' exhaustiveness. |
Generally what I end up doing is something like git grep 'switch must be exhaustive' -- 'include/**' 'lib/**' In this case, it gives 4 hits; the error message is present in — That said, before hacking at the code, it may be helpful to first discuss what cases should/shouldn't emit the new diagnostic, to gain some clarity (you may still want to read through Now consider the following example: switch (x as Optional<Int>) {
case .some(0): break;
} We probably want to continue having "switch must be exhaustive" here, having the "is not known to be exhaustive" warning would make it seem like the compiler doesn't even understand that there's a missing switch (x as Optional<Int>) {
case .some(let tmp): tmp ~= 0;
} If you use This means that the most straightforward solution of checking if any of the patterns contains an I'm still trying to precisely formulate the condition that we should be checking here... I need to think some more. I don't think this bug really qualifies as a StarterBug, it's more complicated than that. That said, if you are still interested, we can try working through this together. cc @hborla |
Yep, I'm still interested. Even if I can't do much, I would still like to follow along and learn. — In addition to the — Newbie question: I tried to access |
The compiler does exhaustiveness checking for enum cases, not for arbitrary types. Since
That's strange, those files should open fine in Xcode. Are you working with a fresh build/did Xcode finish indexing? You may want to run a build of |
I re-cloned and re-built the project for a few times, and the problem persists. I'm going to ask about it on the forums, instead of polluting this thread. |
Additional Detail from JIRA
md5: d6cd00bf3c67667514e251b4587cc376
Issue Description:
For example:
https://bugs.swift.org/browse/SR-13516
The wording "switch must be exhaustive" makes it sound like the switch is not exhaustive. However, that's not the case. The problem is that the compiler is not able to reason about exhaustiveness here. We should clarify the diagnostic to have wording like (say) "is not known to be exhaustive" when we see custom match functions (i.e.
~=
overloads) being used. Similarly, if there arewhere
clauses, we should emit the new wording, only using the current wording we were able to compute the pattern subspace that is not covered by the existing patterns.The text was updated successfully, but these errors were encountered: