[java-highlighting] add a few more positive tests for record patterns in 'for-each' loops

GitOrigin-RevId: 288695978fe572073256e34ff116381f65f597d7
This commit is contained in:
Andrey Cherkasov
2023-01-21 19:48:14 +04:00
committed by intellij-monorepo-bot
parent a71748ad14
commit 9a9a0e26bf

View File

@@ -24,44 +24,50 @@ class Main {
}
}
void test1(Point[] points) {
for (Point(int x, int y) : points) {
System.out.println(x + y);
void ok3(List<Point> points) {
for (Point(final int a, final int b) : points) {
System.out.println(a + b);
}
}
void test2() {
void ok4(Iterable<Rect> rectangles) {
for (Rect(Point(final int x1, final int y1), final Point point2) : rectangles) {
System.out.println(x1 + y1);
}
}
void test1() {
System.out.println(<error descr="Cannot resolve symbol 'x'">x</error>);
for (Point(int x, int y) : getPoints(<error descr="Cannot resolve symbol 'x'">x</error>)) {
}
System.out.println(<error descr="Cannot resolve symbol 'y'">y</error>);
}
void test3(List<Integer> nums) {
void test2(List<Integer> nums) {
for (<error descr="Deconstruction pattern can only be applied to a record, 'java.lang.Integer' is not a record">Integer</error>(int num) : nums) {
System.out.println();
}
}
void test4(Point[] points) {
void test3(Point[] points) {
for (Point(int x, <error descr="Incompatible types. Found: 'java.lang.Integer', required: 'int'">Integer y</error>) : points) {
System.out.println(x + y);
}
}
void test5(Rect[] rectangles) {
void test4(Rect[] rectangles) {
for (Rect(Point<error descr="Incorrect number of nested patterns: expected 2 but found 1">(int x1)</error>, Point point2): rectangles) {
System.out.println(x1 + <error descr="Cannot resolve symbol 'y1'">y1</error>);
}
}
void test6(Point[] points) {
void test5(Point[] points) {
for (Point(int x, int y, <error descr="Incorrect number of nested patterns: expected 2 but found 3">int z)</error> : points) {
System.out.println(x + y + z);
}
}
<T> void test7(Set<Pair<String, String>> pairs) {
<T> void test6(Set<Pair<String, String>> pairs) {
for (<error descr="'Main.Pair<java.lang.String,java.lang.String>' cannot be safely cast to 'Main.Pair<T,java.lang.String>'">Pair<T, String>(var t, var u)</error> : pairs) {}
}