[java] SwitchStmtsShouldHaveDefault - also ignore record pattern

This commit is contained in:
Andreas Dangel 2024-10-05 10:39:55 +02:00
parent e5ff5532d4
commit 59403fc9e1
No known key found for this signature in database
GPG Key ID: 93450DF2DF9A3FA3
2 changed files with 18 additions and 2 deletions

View File

@ -1178,8 +1178,8 @@ class SomeTestClass {
<property name="xpath">
<value><![CDATA[
//SwitchStatement[@DefaultCase = false() and @ExhaustiveEnumSwitch = false()]
(: exclude type pattern tests - for these, the compiler will ensure exhaustiveness :)
[not(*/SwitchLabel/TypePattern)]
(: exclude pattern tests - for these, the compiler will ensure exhaustiveness :)
[not(*/SwitchLabel/(TypePattern|RecordPattern))]
]]></value>
</property>
</properties>

View File

@ -313,6 +313,22 @@ public class Example2 {
}
}
}
]]></code>
</test-code>
<test-code>
<description>With Record Patterns #4813</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
record R(int i) {}
public class SwitchWithRecordPattern {
public void check(R r) {
switch(r) {
case R(int a) -> System.out.println(a);
}
}
}
]]></code>
</test-code>
</test-data>