new inference: distinguish return type type parameters and current session inference variables (IDEA-135001)

This commit is contained in:
Anna Kozlova
2015-01-07 15:34:27 +01:00
parent 5674b493e0
commit c11d64ac60
3 changed files with 28 additions and 1 deletions
@@ -488,7 +488,7 @@ public class InferenceSession {
if (psiClass != null) {
LOG.assertTrue(returnType instanceof PsiClassType);
final PsiTypeParameter[] typeParameters = psiClass.getTypeParameters();
InferenceVariable[] copy = initBounds(myContext, typeParameters);
InferenceVariable[] copy = initBounds(null, typeParameters);
final PsiType substitutedCapture = PsiUtil.captureToplevelWildcards(returnType, myContext);
myIncorporationPhase.addCapture(copy, (PsiClassType)substituteWithInferenceVariables(returnType));
addConstraint(new TypeCompatibilityConstraint(targetType, substitutedCapture));
@@ -0,0 +1,23 @@
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Stream;
class Test {
private void foo(Function<? super Integer, Stream<Integer>> first) {
Function<? super Integer, Object> second = first.andThen(s -> s.map(null));
}
private final Function<? super Integer, ? extends Stream<? extends Integer>> first =
response -> Arrays.asList(response).stream().map(i -> i++);
private final Function<? super Integer, ? extends Stream<Map<String, Integer>>> second = first.andThen(
mid -> mid.map(i -> {
Map<String, Integer> map = new HashMap<>();
map.put("key", i);
return map;
}));
}
@@ -58,6 +58,10 @@ public class ConstraintsInferenceMiscTest extends LightDaemonAnalyzerTestCase {
doTest(false);
}
public void testWildcardParameterizedReturnTypeConflictWithParameterTypes() throws Exception {
doTest(false);
}
private void doTest(final boolean checkWarnings) {
doTest(BASE_PATH + "/" + getTestName(false) + ".java", checkWarnings, false);
}