Is it feasible for Exhaustiveness Checks to tell us what we are missing? At least in some cases?

David Alayachew davidalayachew at gmail.com
Wed Jan 31 03:55:11 UTC 2024


Hello Tagir,

Thank you for your response!

Fair point about NP-Complete. Maybe scaling back the idea would make more
sense.

But I am confused about this comment.

> From what I remember, it could be very non-trivial to determine a minimal
set of missing branches

I'm very surprised to hear this, but if that is true, then let's scale this
down to the absolute minimum.

In order to know that we are missing a case, we must first find a gap in
the exhaustiveness, with respect to the remainder.

So let's move the goal posts and say that if we can report that single type
that is the gap, I would be happy enough with that.

Would that be more realistic?

Thank you for reaching out!
David Alayachew

On Tue, Jan 30, 2024 at 3:21 AM Tagir Valeev <amaembo at gmail.com> wrote:

> IntelliJ IDEA can do this in simple cases (use 'Create missing branches'
> action in Alt+Enter menu on "statement does not cover all possible input
> values" error message). From what I remember, it could be very non-trivial
> to determine a minimal set of missing branches in a general case,
> especially if you have generic parameters and nested deconstruction
> patterns. I'm not sure but probably it's an NP-complete problem.
>
> With best regards,
> Tagir Valeev.
>
> On Tue, Jan 30, 2024 at 6:40 AM David Alayachew <davidalayachew at gmail.com>
> wrote:
>
>> Hello Amber Dev Team,
>>
>> The previous discussions on Checked Exceptions reminded me about this.
>>
>> Is there any possible future where sealed types will be able to tell you
>> which permitted subtypes are missing?
>>
>> This is actually one of the sleeper features of Checked Exceptions --
>> they don't just give you exhaustiveness, they are even nice enough to tell
>> you exactly which Exception type you left out.
>>
>> This is a godsend for maintenance, fearless refactoring, and general
>> correctness.
>>
>> Any chance we could get this for sealed types in the future?
>>
>> Thank you for your time and help!
>> David Alayachew
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20240130/5783fb31/attachment-0001.htm>


More information about the amber-dev mailing list