mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java][instanceof] IDEA-280626 Patterns in instanceof: red code false-negative
Move the test data to LightPatternsHighlightingTest Signed-off-by: Nikita Eshkeev <nikita.eshkeev@jetbrains.com> GitOrigin-RevId: f62fc31839e92b03161837d92b2518c4b13ab5c8
This commit is contained in:
committed by
intellij-monorepo-bot
parent
2e1608914a
commit
cbb421ecb6
+24
@@ -0,0 +1,24 @@
|
||||
|
||||
class Main {
|
||||
|
||||
private static final boolean TRUE = 1 == 1;
|
||||
|
||||
void testGuardedPatternWithCompileTimeCondition1(String s) {
|
||||
if (s instanceof (<error descr="Pattern type 'String' is the same as expression type">String</error> s1 && true)) {
|
||||
System.out.println(s1);
|
||||
}
|
||||
}
|
||||
|
||||
void testGuardedPatternWithAlwaysTrueCondition2(String s) {
|
||||
if (s instanceof (<error descr="Pattern type 'String' is the same as expression type">String</error> s1 && TRUE)) {
|
||||
System.out.println(s1);
|
||||
}
|
||||
}
|
||||
|
||||
void testGuardedPatternWithAlwaysTrueCondition3(String s) {
|
||||
if (s instanceof ((<error descr="Pattern type 'String' is the same as expression type">String</error> s1 && true) && true)) {
|
||||
System.out.println(s1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,4 @@
|
||||
class Test {
|
||||
|
||||
private static final boolean TRUE = <warning descr="Condition '1 == 1' is always 'true'">1 == 1</warning>;
|
||||
|
||||
void testTypePattern1(Object o) {
|
||||
o = "fsd";
|
||||
if (<warning descr="Condition 'o instanceof String s' is always 'true'">o instanceof String s</warning>) {
|
||||
@@ -56,24 +53,6 @@ class Test {
|
||||
}
|
||||
}
|
||||
|
||||
void testGuardedPatternWithCompileTimeCondition1(String s) {
|
||||
if (<warning descr="Condition 's instanceof (String s1 && true)' is always 'true'">s instanceof (<error descr="Pattern type 'String' is the same as expression type">String</error> s1 && true)</warning>) {
|
||||
System.out.println(s1);
|
||||
}
|
||||
}
|
||||
|
||||
void testGuardedPatternWithAlwaysTrueCondition2(String s) {
|
||||
if (s instanceof (<error descr="Pattern type 'String' is the same as expression type">String</error> s1 && TRUE)) {
|
||||
System.out.println(s1);
|
||||
}
|
||||
}
|
||||
|
||||
void testGuardedPatternWithAlwaysTrueCondition3(String s) {
|
||||
if (<warning descr="Condition 's instanceof ((String s1 && true) && true)' is always 'true'">s instanceof ((<error descr="Pattern type 'String' is the same as expression type">String</error> s1 && true) && true)</warning>) {
|
||||
System.out.println(s1);
|
||||
}
|
||||
}
|
||||
|
||||
private String getString() {
|
||||
return "str";
|
||||
}
|
||||
|
||||
+4
-1
@@ -18,7 +18,7 @@ public class LightPatternsHighlightingTest extends LightJavaCodeInsightFixtureTe
|
||||
@NotNull
|
||||
@Override
|
||||
protected LightProjectDescriptor getProjectDescriptor() {
|
||||
return JAVA_16;
|
||||
return JAVA_17;
|
||||
}
|
||||
|
||||
public void testInstanceOfBasics() {
|
||||
@@ -49,6 +49,9 @@ public class LightPatternsHighlightingTest extends LightJavaCodeInsightFixtureTe
|
||||
public void testInstanceOfSubtype() {
|
||||
doTest();
|
||||
}
|
||||
public void testInstanceOfPatternMatching() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
myFixture.configureByFile(getTestName(false) + ".java");
|
||||
|
||||
Reference in New Issue
Block a user