eclipse.jdt.ls icon indicating copy to clipboard operation
eclipse.jdt.ls copied to clipboard

False positive when using switch expressions on sealed interfaces.

Open computerscience-person opened this issue 1 year ago • 1 comments

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:

  • Cannot switch on a value of type of this.
  • SchoolDay cannot be resolved to a variable.
  • Syntax error on token "day", delete this token.

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.

computerscience-person avatar Nov 16 '23 18:11 computerscience-person

@computerscience-person Could you attach a project example?

snjeza avatar Nov 16 '23 19:11 snjeza