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:
anna
2013-05-07 13:43:25 +02:00
parent 8538b0d82b
commit 3f6f5b5a9e
3 changed files with 40 additions and 6 deletions
@@ -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();
}
}
@@ -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();
}
}