inference: don't remember captured wildcard with non-proper bound (IDEA-180042)

later check could fail e.g. if bound was created inside one of nested session
This commit is contained in:
Anna.Kozlova
2017-10-17 17:58:55 +02:00
parent df2907a68e
commit 2658d37da0
2 changed files with 13 additions and 3 deletions
@@ -770,7 +770,7 @@ public class InferenceSession {
InferenceVariable[] variables = initBounds(null, restParamSubstitution, capturedParams.toArray(PsiTypeParameter.EMPTY_ARRAY));
int idx = 0;
for (PsiType parameter : parameters) {
if (parameter instanceof PsiCapturedWildcardType) {
if (parameter instanceof PsiCapturedWildcardType && isProperType(((PsiCapturedWildcardType)parameter).getWildcard())) {
variables[idx++].putUserData(ORIGINAL_CAPTURE, (PsiCapturedWildcardType)parameter);
}
}
@@ -1234,8 +1234,7 @@ public class InferenceSession {
//restore captured wildcard from method return type when no additional constraints were inferred
//to preserve equality of type arguments
if (capturedWildcard != null &&
capturedWildcard.getUpperBound().equals(getUpperBound(aClass)) &&
isProperType(capturedWildcard.getWildcard())) {
capturedWildcard.getUpperBound().equals(getUpperBound(aClass))) {
eqBound = capturedWildcard;
}
}
@@ -1,3 +1,4 @@
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Supplier;
@@ -54,3 +55,13 @@ class TestWithNonProperTypeBeforeCapture {
return null;
}
}
class TestWithNonPropertTypeBeforeCaptureInMethodCall {
private <K, V> void test(Stream<Map.Entry<K, V>> stream, BiFunction<K, V, ?> entryMapper) {
stream.map(createToStringMapper(entryMapper));
}
private <K, V> Function<? super Map.Entry<K, V>, String> createToStringMapper(BiFunction<K, V, ?> mapper) {
return k -> toString();
}
}