Question regarding exhaustiveness check of record patterns

Tesla Zhang ice1000kotlin at foxmail.com
Wed Nov 2 18:59:52 UTC 2022


Hi,

I am confused by a compile error generated by the following code:


sealed interface I<T> {}
record A<T>(T t) implements I<T> {}
public static void main(I<String> args) {
  switch (args) {
    case A<String>(var x) -> System.out.println(x);
  }
}



Compiling the code with the following JDK:


openjdk 19 2022-09-20
OpenJDK Runtime Environment (build 19+37)
OpenJDK 64-Bit Server VM (build 19+37, mixed mode, sharing)



I get:


.\JavaBug.java:5: error: the switch statement does not cover all possible input values
    switch (args) {
    ^
Note: .\JavaBug.java uses preview features of Java SE 19.
Note: Recompile with -Xlint:preview for details.
1 error



What cases could be not covered? It looks like a bug to me.


Also, I believe that showing the particular uncovered cases in the error messages would make very good developer experiences.


Best regards,
Tesla
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20221102/63379b62/attachment.htm>


More information about the amber-dev mailing list