-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Add Check Support for Java 21 Pattern Matching for Switch Syntax: InnerAssignment #15037
Comments
Let's add a test input for this one (I don't see any record patterns or |
Nope PS D:\CS\test> cat src/Test.java
record ColoredPoint(boolean p, int x, int c) { }
record Rectangle(ColoredPoint upperLeft, ColoredPoint lowerRight) { }
public class Test {
void test(Object obj) {
boolean n = false;
switch (obj) {
case ColoredPoint(boolean x, int y, int c) when (n = true) -> {
if (n = true) { }
}
case ColoredPoint(boolean x, int y, int c) when (x = true) -> {
if (x = true) { }
}
default -> { }
}
}
}
PS D:\CS\test> javac src/Test.java
src\Test.java:8: error: cannot assign to n, as it was not declared inside the guard
case ColoredPoint(boolean x, int y, int c) when (n = true) -> {
^
src\Test.java:11: error: cannot assign to x, as it was not declared inside the guard
case ColoredPoint(boolean x, int y, int c) when (x = true) -> {
^
2 errors
PS D:\CS\test> |
Can you actually declare a variable inside the guard? |
@mahfouz72 Edit: nevermind, this is probably the same as |
Updated the example now that we have added the |
child of #14961
I have read check documentation:https://checkstyle.org/checks/coding/innerassignment.html#InnerAssignment
I have downloaded the latest checkstyle from: https://checkstyle.org/cmdline.html#Download_and_Run
I have executed the cli and showed it below, as cli describes the problem better than 1,000 words
Describe what you want in detail
we are ok here. This was an issue that I fixed recently with this PR. So this can be closed
The text was updated successfully, but these errors were encountered: