method refs: ensure inference from captured return type (IDEA-145152)

This commit is contained in:
Anna Kozlova
2015-09-16 18:53:31 +03:00
parent c26cc82486
commit f61de7a241
3 changed files with 19 additions and 2 deletions
@@ -197,8 +197,9 @@ public class PsiMethodReferenceCompatibilityConstraint implements ConstraintForm
}
}
constraints.add(new TypeCompatibilityConstraint(returnType,
session.substituteWithInferenceVariables(psiSubstitutor.substitute(referencedMethodReturnType))));
final PsiType capturedReturnType = PsiImplUtil.normalizeWildcardTypeByPosition(psiSubstitutor.substitute(referencedMethodReturnType),
myExpression);
constraints.add(new TypeCompatibilityConstraint(returnType, session.substituteWithInferenceVariables(capturedReturnType)));
}
return true;
@@ -0,0 +1,12 @@
import java.util.stream.Stream;
class Test {
void foo(final Stream<StubElement<?>> inStream){
inStream.map(StubElement::getPsi)
.map(s -> s.length());
}
class StubElement<T extends String> {
T getPsi() {return null;}
}
}
@@ -426,6 +426,10 @@ public class NewMethodRefHighlightingTest extends LightDaemonAnalyzerTestCase {
doTest();
}
public void testCapturedReturnTypeOfMethodReference() throws Exception {
doTest();
}
private void doTest() {
doTest(false);
}