IDEA-193097 Redundant cast is reported for cast on functional expression inside synchronized()

This commit is contained in:
Tagir Valeev
2018-06-01 13:14:14 +07:00
parent 23c71174a1
commit 1f3cd67c4b
2 changed files with 10 additions and 1 deletions
@@ -541,7 +541,10 @@ public class RedundantCastUtil {
if (opposite == null || conditionalType instanceof PsiPrimitiveType &&
!Comparing.equal(conditionalType, opposite.getType())) return;
}
} else if (parent instanceof PsiSynchronizedStatement && expr != null && expr.getType() instanceof PsiPrimitiveType) {
}
else if (parent instanceof PsiSynchronizedStatement &&
expr != null &&
(expr.getType() instanceof PsiPrimitiveType || expr instanceof PsiFunctionalExpression)) {
return;
} else if (expr instanceof PsiLambdaExpression || expr instanceof PsiMethodReferenceExpression) {
if (parent instanceof PsiParenthesizedExpression && parent.getParent() instanceof PsiReferenceExpression) {
@@ -7,6 +7,12 @@ class Test {
return s.length();
}
void test() {
synchronized ((Bar)Test::length) {
System.out.println("Synchronizing on a method reference is a nice thing to try!");
}
}
interface Bar {
Integer m(String s);
}