Files
openide/java/java-tests/testData/inspection/dataFlow/fixture/ForEachPattern.java
Tagir Valeev 0484c455d1 [java-dfa] Support for-each patterns in Java DFA
Fixes IDEA-312232 Incorrect "Condition is always true" in presence of pattern foreach

GitOrigin-RevId: f25124ba8c0db15fc8c614aca7afec98cf78a29c
2023-02-03 11:41:51 +00:00

39 lines
879 B
Java

import java.util.*;
import org.jetbrains.annotations.Range;
public class ForEachPattern {
record IntBox(int i) {}
void bar1(Iterable<IntBox> i) {
int a = 1;
for (IntBox(int d) : i) {
a = 2;
}
System.out.println(a == 1);
}
record Point(int x, @Range(from = 1, to = 10) int y) {}
public static void main(String[] args) {
List<Point> points = new ArrayList<>();
use(points);
}
private static void use(List<Point> points) {
int a = 0, b = 0;
for (Point(int x, int y) : points) {
if (x == 1) {
a = 1;
}
if (x == 2) {
b = 1;
}
if (x == 2 && <warning descr="Condition 'b == 1' is always 'true' when reached">b == 1</warning>) {
b = y;
}
if (<warning descr="Condition 'y == 12' is always 'false'">y == 12</warning>) {}
}
if (a == 1 && b == 1) {
}
}
}