Java: accept more patterns (IJ-CR-144289)

GitOrigin-RevId: c0692f8c924b32988ec98aae86c1ad9b466cb45a
This commit is contained in:
Bas Leijdekkers
2024-09-24 10:04:30 +00:00
committed by intellij-monorepo-bot
parent b847b27f2c
commit c3189981f6
2 changed files with 13 additions and 2 deletions
@@ -231,7 +231,7 @@ public class EqualsWhichDoesntCheckParameterClassInspection extends BaseInspecti
.map(PsiSwitchLabelStatementBase::getCaseLabelElementList)
.filter(Objects::nonNull)
.flatMap(list -> Arrays.stream(list.getElements()))
.anyMatch(element -> element instanceof PsiTypeTestPattern);
.anyMatch(element -> element instanceof PsiPrimaryPattern);
if (checksType) makeChecked();
}
@@ -158,4 +158,15 @@ final class MyClass implements MyInterface {
};
}
}
}
record MyRecord(String str) {
@Override
public boolean equals(Object o) { // "'equals()' should check the class of its parameter" is falsely reported
if (this == o) return true;
return switch (o) {
case MyRecord(String s) when s != null -> Objects.equals(str, s);
case null, default -> false;
};
}
}