From 89d2ebc500448c5b5c73292e8c85e133f794b2a6 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Fri, 31 Jan 2014 22:16:02 +0400 Subject: [PATCH] invocation type inference: when unchecked conversion was performed - treat its results in return value checks as they were in bounds --- .../resolve/graphInference/InferenceSession.java | 2 +- .../constraints/UncheckedBoundsWithErasure.java | 14 ++++++++++++++ .../lambda/ConstraintsInferenceMiscTest.java | 4 ++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/constraints/UncheckedBoundsWithErasure.java diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java index 7adc38075705..d9623a31876d 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java @@ -333,7 +333,7 @@ public class InferenceSession { final InferenceVariable inferenceVariable = getInferenceVariable(returnType); if (inferenceVariable != null) { if (targetType instanceof PsiPrimitiveType && hasPrimitiveWrapperBound(inferenceVariable) || - targetType instanceof PsiClassType && hasUncheckedBounds(inferenceVariable, (PsiClassType)targetType)) { + targetType instanceof PsiClassType && (hasUncheckedBounds(inferenceVariable, (PsiClassType)targetType) || myErased)) { return inferenceVariable; } } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/constraints/UncheckedBoundsWithErasure.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/constraints/UncheckedBoundsWithErasure.java new file mode 100644 index 000000000000..49753a7bcdac --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/constraints/UncheckedBoundsWithErasure.java @@ -0,0 +1,14 @@ +public class Sample { + interface G {} + interface G1 extends G {} + void foo(G1 g1) { + bar(g1); + } + B bar(G gb) {return null;} + + void f(G1 g1) { + G l11 = bar(g1); + String l1 = bar(g1); + Object o = bar(g1); + } +} diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/ConstraintsInferenceMiscTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/ConstraintsInferenceMiscTest.java index 035ea16b8c4d..de39d99efffd 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/ConstraintsInferenceMiscTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/ConstraintsInferenceMiscTest.java @@ -46,6 +46,10 @@ public class ConstraintsInferenceMiscTest extends LightDaemonAnalyzerTestCase { doTest(false); } + public void testUncheckedBoundsWithErasure() throws Exception { + doTest(false); + } + private void doTest(final boolean checkWarnings) { doTestNewInference(BASE_PATH + "/" + getTestName(false) + ".java", checkWarnings, false); }