[External] : Re: Make all switches exhaustive?
Brian Goetz
brian.goetz at oracle.com
Tue Apr 27 17:55:47 UTC 2021
>
> This will not solve the problem of Maurizio for sub-patterns but i
> like it.
I agree it doesn't *solve* the problem, but it helps somewhat.
> We don't have to later transform the warning to an error, keeping it
> as a warning can be annoying enough to force people to change their
> code (or ALT-ENTER + CTRL+1 ont it).
Yes, we can make this decision later.
>
>
> Legacy switches are those whose operand type is one of the
> "classic" types and all labels are constant labels or "default".
>
> For a switch that is deliberately non-exhaustive, all the user has
> to do to capture this (and shut up the compiler) is:
>
> default: break;
>
>
> "default:" should be enough no ?
Yes, probably.
>
>
> which is not very intrusive, and arguably makes the code more
> readable anyway. Users will see a speed bump when upgrading to
> pattern switches (clippy will tell them "I see you're writing a
> pattern switch, don't forget to end it with default:break") which
> presumably they will quickly internalize.
>
> (How's that for teaching an old dog new tricks?)
>
>
>
> I think we should tackle "default" not being at the end the same way.
>
I'd like that; pushing total patterns to the end is pretty helpful. We
tried that once, and ran into trouble, though; there were cases we
couldn't completely express with that IIRC. With the latest formulation
of `case null, default`, I think the trouble we ran into before goes
away, but we might have new trouble doing so.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/amber-spec-experts/attachments/20210427/fc239cff/attachment.htm>
More information about the amber-spec-experts
mailing list