diff --git a/java/java-psi-api/src/com/intellij/psi/util/RedundantCastUtil.java b/java/java-psi-api/src/com/intellij/psi/util/RedundantCastUtil.java index 65c3ce81812d..d4382b40db7a 100644 --- a/java/java-psi-api/src/com/intellij/psi/util/RedundantCastUtil.java +++ b/java/java-psi-api/src/com/intellij/psi/util/RedundantCastUtil.java @@ -518,7 +518,9 @@ public class RedundantCastUtil { return; } } - } + } + } else { + return; } } if (parent instanceof PsiThrowStatement) { diff --git a/java/java-tests/testData/inspection/redundantCast/lambda/ForeachValue/expected.xml b/java/java-tests/testData/inspection/redundantCast/lambda/ForeachValue/expected.xml new file mode 100644 index 000000000000..4704d91e891d --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/lambda/ForeachValue/expected.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/java/java-tests/testData/inspection/redundantCast/lambda/ForeachValue/src/Test.java b/java/java-tests/testData/inspection/redundantCast/lambda/ForeachValue/src/Test.java new file mode 100644 index 000000000000..bd2236cfe9f1 --- /dev/null +++ b/java/java-tests/testData/inspection/redundantCast/lambda/ForeachValue/src/Test.java @@ -0,0 +1,10 @@ +import java.util.Arrays; +import java.util.Iterator; + +class IterableMain { + public static void main(final String... args) { + for (final String s : (Iterable) XIterator::new) {} + } + + public static interface XIterator extends Iterator {} +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/RedundantCast18Test.java b/java/java-tests/testSrc/com/intellij/codeInspection/RedundantCast18Test.java index 0a0c5396c6c9..6cb52914fe84 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/RedundantCast18Test.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/RedundantCast18Test.java @@ -18,7 +18,6 @@ package com.intellij.codeInspection; import com.intellij.codeInspection.ex.LocalInspectionToolWrapper; import com.intellij.codeInspection.redundantCast.RedundantCastInspection; import com.intellij.openapi.projectRoots.Sdk; -import com.intellij.openapi.projectRoots.impl.JavaSdkImpl; import com.intellij.openapi.roots.LanguageLevelProjectExtension; import com.intellij.pom.java.LanguageLevel; import com.intellij.testFramework.IdeaTestUtil; @@ -33,6 +32,7 @@ public class RedundantCast18Test extends InspectionTestCase { public void testLambdaContext() throws Exception { doTest(); } public void testMethodRefContext() throws Exception { doTest(); } public void testExpectedSupertype() throws Exception { doTest(); } + public void testForeachValue() throws Exception { doTest(); } @Override protected Sdk getTestProjectSdk() {