google / error-prone

Catch common Java mistakes as compile-time errors
https://errorprone.info
Apache License 2.0
6.83k stars 742 forks source link

Component out of order in a deconstruction pattern #4581

Open kevinb9n opened 1 week ago

kevinb9n commented 1 week ago

Just capturing an idea; not sure if it is high-value. In something like

case MyRecord(int foo, _, var bar)

A warning could be issued if the name of any pattern variable (here, "foo" or "bar") has a shorter edit distance to some other component of the record than the one it is matched up with.

Positional APIs can be hard to remember. This applies to instanceof as well. Currently this only applies to record patterns, but in the future there may be deconstructors for non-record classes too.