continue inference after raw type detected; report raw after all args were processed with raw result only (IDEA-92273)

This commit is contained in:
Anna Kozlova
2012-10-13 15:29:28 +02:00
parent c50b22e99d
commit 23120f5c8a
3 changed files with 30 additions and 1 deletions

View File

@@ -187,6 +187,7 @@ public class PsiResolveHelperImpl implements PsiResolveHelper {
@Nullable PsiElement parent,
final ParameterTypeInferencePolicy policy) {
PsiWildcardType wildcardToCapture = null;
Pair<PsiType, ConstraintType> rawInference = null;
PsiType lowerBound = PsiType.NULL;
PsiType upperBound = PsiType.NULL;
if (paramTypes.length > 0) {
@@ -231,7 +232,10 @@ public class PsiResolveHelperImpl implements PsiResolveHelper {
final ConstraintType constraintType = currentSubstitution.getSecond();
final PsiType type = currentSubstitution.getFirst();
if (type == null) return RAW_INFERENCE;
if (type == null) {
rawInference = RAW_INFERENCE;
continue;
}
switch(constraintType) {
case EQUALS:
if (!(type instanceof PsiWildcardType)) return currentSubstitution;
@@ -270,6 +274,7 @@ public class PsiResolveHelperImpl implements PsiResolveHelper {
}
if (lowerBound != PsiType.NULL) return new Pair<PsiType, ConstraintType>(lowerBound, ConstraintType.EQUALS);
if (rawInference != null) return rawInference;
if (parent != null) {
final Pair<PsiType, ConstraintType> constraint =

View File

@@ -0,0 +1,23 @@
import java.util.*;
class Test {
List<String> getList(Function<Object, String> function) {
/*
* When the first argument below is a raw type it turns red because IDEA thinks the return
* type is Collection<>. javac and Eclipse don't care
*/
return transform(new ArrayList(), new ArrayList<String>(), function);
}
<R, S, T extends Collection<S>> T transform(Iterable<? extends R> oldCollection, T newCollection, Function<R, S> function) {
for (R r : oldCollection) {
newCollection.add(function.apply(r));
}
return newCollection;
}
interface Function<X, Y> {
Y apply(X input);
}
}

View File

@@ -149,6 +149,7 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase {
public void testIDEA89801() throws Exception { doTest(false); }
public void testInconvertibleTypes() throws Exception { doTest(false); }
public void testIncompatibleReturnType() throws Exception { doTest(false); }
public void testContinueInferenceAfterFirstRawResult() throws Exception { doTest(false); }
public void testJavaUtilCollections_NoVerify() throws Exception {
PsiClass collectionsClass = getJavaFacade().findClass("java.util.Collections", GlobalSearchScope.moduleWithLibrariesScope(getModule()));