mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
redundant type arguments: replay real inference to avoid inference from parent when inference would use the sibling's bound (IDEA-16723)
This commit is contained in:
+4
-5
@@ -106,12 +106,11 @@ public class RedundantTypeArgsInspection extends GenericsInspectionToolBase {
|
||||
if (typeParameters.length == typeArguments.length) {
|
||||
final PsiParameter[] parameters = method.getParameterList().getParameters();
|
||||
PsiResolveHelper resolveHelper = JavaPsiFacade.getInstance(expression.getProject()).getResolveHelper();
|
||||
for (int i = 0; i < typeParameters.length; i++) {
|
||||
final PsiSubstitutor psiSubstitutor = resolveHelper
|
||||
.inferTypeArguments(typeParameters, parameters, argumentList.getExpressions(), PsiSubstitutor.EMPTY, expression, DefaultParameterTypeInferencePolicy.INSTANCE);
|
||||
for (int i = 0, length = typeParameters.length; i < length; i++) {
|
||||
PsiTypeParameter typeParameter = typeParameters[i];
|
||||
final PsiType inferredType = resolveHelper.inferTypeForMethodTypeParameter(typeParameter, parameters,
|
||||
argumentList.getExpressions(),
|
||||
resolveResult.getSubstitutor(), expression,
|
||||
DefaultParameterTypeInferencePolicy.INSTANCE);
|
||||
final PsiType inferredType = psiSubstitutor.getSubstitutionMap().get(typeParameter);
|
||||
if (!typeArguments[i].equals(inferredType)) return;
|
||||
if (PsiUtil.resolveClassInType(method.getReturnType()) == typeParameter && PsiPrimitiveType.getUnboxedType(inferredType) != null) return;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import java.util.*;
|
||||
|
||||
class ArraysUtil {
|
||||
public static <S, T extends S> List<S> asList(T... a) {
|
||||
List<S> result = new ArrayList<S>();
|
||||
result.addAll(Arrays.asList(a));
|
||||
return result;
|
||||
}
|
||||
|
||||
public static <S, T extends S> List<S> asCollection(T... a) {
|
||||
return ArraysUtil.<S, T>asList(a);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
asCollection();
|
||||
}
|
||||
}
|
||||
|
||||
class ArraysUtil1 {
|
||||
public static <S, T> List<S> asList(T... a) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static List<String> asCollection(Integer... a) {
|
||||
return ArraysUtil1.<warning descr="Explicit type arguments can be inferred"><String, Integer></warning>asList(a);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
asCollection();
|
||||
}
|
||||
}
|
||||
+5
-1
@@ -30,7 +30,11 @@ public class RedundantTypeArgsInspectionTest extends JavaCodeInsightFixtureTestC
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testConditionalExpression() throws Throwable { // javac non-boxing: IDEA-53984
|
||||
public void testConditionalExpression() throws Throwable {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testBoundInference() throws Throwable {
|
||||
doTest();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user