Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unnamed patterns inside of multi case patterns fail to parse #2956

Open
DarinM223 opened this issue Sep 14, 2024 · 2 comments
Open

Unnamed patterns inside of multi case patterns fail to parse #2956

DarinM223 opened this issue Sep 14, 2024 · 2 comments
Assignees

Comments

@DarinM223
Copy link

DarinM223 commented Sep 14, 2024

This code:

public class Main {
    public sealed interface MyType {
        record A() implements MyType {
        }

        record B(int value) implements MyType {
        }

        record C() implements MyType {
        }
    }

    public static void main(String[] args) {
        MyType myType = new MyType.A();
        switch (myType) {
            case MyType.A(), MyType.B(_) -> {}
            case MyType.C() -> {}
        }
    }
}

works in IntelliJ with OpenJDK 22 but in Eclipse 4.33 using the Eclipse compiler it gives the error messages:

Syntax error on token ")", delete this token
Syntax error on token(s), misplaced construct(s)

It seems that this may be because a wildcard pattern is used inside of an or pattern. Expanding the or pattern like:

        switch (myType) {
            case MyType.A() -> {}
            case MyType.B(_) -> {}
            case MyType.C() -> {}
        }

results in no compile errors.

@srikanth-sankaran srikanth-sankaran self-assigned this Sep 16, 2024
@srikanth-sankaran
Copy link
Contributor

Also reversing the order of the multi case arm as in case MyType.B(_), MyType.A() -> {} is accepted. This can be the workaround for the time being.

@srikanth-sankaran
Copy link
Contributor

Problem is observable on 4.32 as well as 4.31 (with preview enabled)

@srikanth-sankaran srikanth-sankaran changed the title Wildcard patterns inside of or patterns fail to parse Unnamed patterns inside of multi case patterns fail to parse Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants