Skip to content

Java 21 pattern matching on records seems not working, gives false error "incorrect number of nested patterns" #338

Description

@liufuyang
Image
public class Hello {
    public static void main(String[] args) {
        System.out.println("Hello from Java!");
        printAngleFromXAxis(new Point(1, 1));
    }

    static void printAngleFromXAxis(Object obj) {
        if (obj instanceof Point(double x1, double y1)) {
            System.out.println(Math.toDegrees(Math.atan2(y1, x1)));
        }
    }
}

record Point(double x, double y) {}

This piece of Java code compiles in Java 21.

But with the language server, I got a weird error saying:

incorrect number of nested patterns
required: double,double,double,double
found: double,double(compiler.err.incorrect.number.of.nested.patterns)


By the way, @georgewfraser, thanks for making this nice tool. Just wondering, will you still have time to improve it? There seem to be many good PRs are also hanging there for some time :)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions