eclipse-jdtls / eclipse.jdt.ls

Java language server
1.81k stars 402 forks source link

False positive when using switch expressions on sealed interfaces. #2959

Open computerscience-person opened 1 year ago

computerscience-person commented 1 year ago

Hello, I was looking at some of my code and found that jdt-ls gives a false positive error when using switch expressions on sealed interfaces.

Example code snippet:

  public sealed interface Day permits SchoolDay, Weekend, Holiday {
  // SNIP
    default void summary() {
      switch (this) {
        case SchoolDay day -> {
          out.println("Finished school day.");
        }
        case Weekend day -> {
          out.println("Finished weekend.");
        }
        case Holiday day -> {
          out.println("Finished holiday.");
        }
      }
    }

Here, jdt-ls gives 7 errors:

And similar errors on the other two classes that implement the interface Day.

Apart from that, using sealed interfaces themselves are clunky, and needs better suggestions/code completions.

snjeza commented 1 year ago

@computerscience-person Could you attach a project example?