method call type: erasure should not be applied if method doesn't have type params; < 1.8 (IDEA-132810)

This commit is contained in:
Anna Kozlova
2014-11-25 17:13:03 +01:00
parent bb227e674f
commit 152df440c6
3 changed files with 22 additions and 1 deletions
@@ -17,6 +17,8 @@ package com.intellij.psi.impl.source.tree.java;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.projectRoots.JavaSdkVersion;
import com.intellij.openapi.projectRoots.JavaVersionService;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Condition;
import com.intellij.pom.java.LanguageLevel;
@@ -226,7 +228,9 @@ public class PsiMethodCallExpressionImpl extends ExpressionPsiElement implements
// If unchecked conversion was necessary for the method to be applicable,
// the parameter types of the invocation type are the parameter types of the method's type,
// and the return type and thrown types are given by the erasures of the return type and thrown types of the method's type.
if (result instanceof MethodCandidateInfo && ((MethodCandidateInfo)result).isApplicable()) {
if (!languageLevel.isAtLeast(LanguageLevel.JDK_1_8) &&
(method.hasTypeParameters() || JavaVersionService.getInstance().isAtLeast(call, JavaSdkVersion.JDK_1_8)) &&
result instanceof MethodCandidateInfo && ((MethodCandidateInfo)result).isApplicable()) {
final PsiType[] args = call.getArgumentList().getExpressionTypes();
final boolean allowUncheckedConversion = false;
final int applicabilityLevel = PsiUtil.getApplicabilityLevel(method, substitutor, args, languageLevel, allowUncheckedConversion, true);
@@ -0,0 +1,13 @@
import java.util.List;
import java.util.Set;
class Test {
void testCall(final Set set) {
for (String position : sortInvoice(set)) {}
}
private List<String> sortInvoice(Set<Integer> set) {
return null;
}
}
@@ -417,6 +417,10 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase {
public void testMethodCallTypeErasedWhenUncheckedConversionWasAppliedDuringApplicabilityCheck() {
doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false);
}
public void testMethodCallTypeNotErasedWhenUncheckedConversionWasAppliedButNoTypeParamsProvided() {
doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false);
}
public void testInferredParameterInBoundsInRecursiveGenerics() {
doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false);