Skip to content

[java] Problems with pattern variables in switch branches #5050

@oowekyala

Description

@oowekyala

It seems there is an issue with the scope of pattern variables in switch branches. In the following, the variable array is undefined in the RHS of the branch:

return switch (foo) {
	case char[] array -> new String(array);
	case String string -> string;
	default -> throw new Exception();
};

Originally posted by @boris-petrov in #4874 (comment)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions