java inference: ease assertion for lambdas in non-generic calls (EA-143883)

GitOrigin-RevId: 0e5ff0aa54375926c8ea5e2140458457250034dc
This commit is contained in:
Anna Kozlova
2019-11-08 21:03:13 +00:00
committed by intellij-monorepo-bot
parent 0000a12866
commit eb79bfc3d3
3 changed files with 30 additions and 1 deletions
@@ -398,8 +398,11 @@ public class LambdaUtil {
if (gParent instanceof PsiCall) {
final PsiCall contextCall = (PsiCall)gParent;
LOG.assertTrue(!MethodCandidateInfo.isOverloadCheck(contextCall.getArgumentList()));
JavaResolveResult resolveResult = PsiDiamondType.getDiamondsAwareResolveResult(contextCall);
PsiElement resultElement = resolveResult.getElement();
LOG.assertTrue(!(MethodCandidateInfo.isOverloadCheck(contextCall.getArgumentList()) &&
resultElement instanceof PsiMethod &&
((PsiMethod)resultElement).hasTypeParameters()));
return getSubstitutedType(expression, tryToSubstitute, lambdaIdx, resolveResult);
}
}
@@ -0,0 +1,18 @@
import java.util.function.Function;
class SomeClass implements IdeaBloopers11 {
void foo(Function<String, String> f) {}
void bar() {
fo<caret>o(s -> {
if (s.contains("a")) {
throw baz(s);
}
return s;
});
}
private NullPointerException baz(String s) {
return null;
}
}
@@ -57,6 +57,14 @@ public class Java8ExpressionsCheckTest extends LightDaemonAnalyzerTestCase {
assertEquals(CommonClassNames.JAVA_LANG_STRING, type.getCanonicalText());
}
public void testTypeOfThrowsExpression() {
configure();
PsiMethodCallExpression fooCall =
PsiTreeUtil.getParentOfType(getFile().findElementAt(getEditor().getCaretModel().getOffset()), PsiMethodCallExpression.class);
assertNotNull(fooCall.getType());
}
public void testRecursiveApplicabilityCheck() {
configure();
PsiMethodCallExpression getDataCall =