Skip to content

Ignore patterns in switches silently prevents formatter from running #1378

@dtwelch

Description

@dtwelch

Using deconstruction (ignore patterns via _) prevents the palantir formatter from running -- silently fails/ignores the whole file (seems like a resiliency issue).

For example, this file will format just fine:

public final class SyntaxTree {

    public record Point(int x, int y) {}

    public String dumbYStr(Point p) {
        return switch (p) {
            case Point(var _, var y) -> "y is: " + y;
        };
    } // this example formats fine..
}

even though we did: var _ in the pattern match..

but making this tweak causes the palantir formatter to not run:

public final class SyntaxTree {

    public record Point(int x, int y) {}

    public String dumbYStr(Point p) {
        return switch (p) {
            // ignore pattern on first component
            case Point(_, var y) -> "y is: " + y; 
        };
    }
}

Could be these _ patterns are still preview..

Figured I'd make the issue in case anyone else notices or stumbles across this behavior when using jdk24 style switch stmts and exprs and wonders why it's not formatting anything in the document.

EDIT: should clarify, using version 2.72.0 in IntelliJ community edition. IntelliJ: Build #IC-252.23892.248

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions