[java-highlighting] Check if variable within pattern guard is effectively final

IDEA-301356

GitOrigin-RevId: 0b8146783be915b5a05a48801151bf64176e39d8
This commit is contained in:
Andrey.Cherkasov
2022-09-08 13:47:10 +04:00
committed by intellij-monorepo-bot
parent bfc6ad1073
commit 1c11e442b0
8 changed files with 173 additions and 6 deletions

View File

@@ -0,0 +1,15 @@
// "Move 'x' into anonymous object" "true-preview"
class Test {
void test(Object o) {
var ref = new Object() {
int x = 42;
};
switch (o) {
case null -> System.out.println(0);
case Integer i -> System.out.println(1);
case String s when s.length() == ref.x++ -> System.out.println(2);
default -> System.out.println(123);
}
}
}

View File

@@ -0,0 +1,13 @@
// "Move 'x' into anonymous object" "true-preview"
class Test {
void test(Object o) {
int x = 42;
switch (o) {
case null -> System.out.println(0);
case Integer i -> System.out.println(1);
case String s when s.length() == x<caret>++ -> System.out.println(2);
default -> System.out.println(123);
}
}
}