mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
erasure of method call expression type if method is not generics but unchecked conversion was needed to check the applicability (IDEA-157223)
This commit is contained in:
+11
-6
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.psi.impl.source.tree.java;
|
||||
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.JavaGenericsUtil;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.projectRoots.JavaSdkVersion;
|
||||
@@ -254,14 +255,18 @@ 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 (!languageLevel.isAtLeast(LanguageLevel.JDK_1_8) &&
|
||||
(method.hasTypeParameters() || JavaVersionService.getInstance().isAtLeast(call, JavaSdkVersion.JDK_1_8)) &&
|
||||
if ((!languageLevel.isAtLeast(LanguageLevel.JDK_1_8) && method.hasTypeParameters() ||
|
||||
!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);
|
||||
if (applicabilityLevel == MethodCandidateInfo.ApplicabilityLevel.NOT_APPLICABLE) {
|
||||
return TypeConversionUtil.erasure(substitutedReturnType);
|
||||
final PsiParameter[] parameters = method.getParameterList().getParameters();
|
||||
final boolean varargs = ((MethodCandidateInfo)result).getApplicabilityLevel() == MethodCandidateInfo.ApplicabilityLevel.VARARGS;
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
final PsiType parameterType = substitutor.substitute(PsiTypesUtil.getParameterType(parameters, i, varargs));
|
||||
final PsiType expressionType = args[i];
|
||||
if (expressionType != null && parameterType != null && JavaGenericsUtil.isRawToGeneric(parameterType, expressionType)) {
|
||||
return TypeConversionUtil.erasure(substitutedReturnType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
class Test {
|
||||
public static <Om> List<Om> sort(Comparator comp, Stream<Om> stream) {
|
||||
<error descr="Incompatible types. Found: 'java.lang.Object', required: 'java.util.List<Om>'">return stream.sorted(comp).collect(Collectors.toList());</error>
|
||||
}
|
||||
|
||||
//accept unbounded wildcards
|
||||
List<String> get(List<?> lists) {
|
||||
return null;
|
||||
}
|
||||
|
||||
void foo(List l) {
|
||||
String p = get(l).get(0);
|
||||
}
|
||||
}
|
||||
+4
@@ -994,4 +994,8 @@ public class GenericsHighlighting8Test extends LightDaemonAnalyzerTestCase {
|
||||
public void testNestedCaptures() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testErasureOfReturnTypeOfNonGenericMethod() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user