clear diamond inference errors when overload resolution fails

This commit is contained in:
Anna.Kozlova
2016-04-28 11:39:38 +02:00
parent bebf4975e6
commit f36501444c
5 changed files with 104 additions and 56 deletions
@@ -0,0 +1,14 @@
import java.util.Collection;
class Test {
void m(StringBuilder builder){
builder.append(new Foo<>((Collection)null));
}
static class Foo<T> {
public Foo(Collection<? extends T> c) {}
public Foo(Foo<T> t) {}
}
}
@@ -79,6 +79,10 @@ public class Java8ExpressionsCheckTest extends LightDaemonAnalyzerTestCase {
doTestAllMethodCallExpressions();
}
public void testObjectOverloadsWithDiamondsOverMultipleConstructors() throws Exception {
doTestAllMethodCallExpressions();
}
public void testNonCachingFolding() throws Exception {
final String filePath = BASE_PATH + "/" + getTestName(false) + ".java";
configureByFile(filePath);
@@ -149,11 +153,19 @@ public class Java8ExpressionsCheckTest extends LightDaemonAnalyzerTestCase {
assertNotNull("Failed inference for: " + expression.getText(), expression.getType());
}
final Collection<PsiReferenceParameterList> parameterLists = PsiTreeUtil.findChildrenOfType(getFile(), PsiReferenceParameterList.class);
for (PsiReferenceParameterList list : parameterLists) {
final Collection<PsiNewExpression> parameterLists = PsiTreeUtil.findChildrenOfType(getFile(), PsiNewExpression.class);
for (PsiNewExpression newExpression : parameterLists) {
getPsiManager().dropResolveCaches();
final PsiType[] arguments = list.getTypeArguments();
assertNotNull("Failed inference for: " + list.getParent().getText(), arguments);
final PsiType[] arguments = newExpression.getTypeArguments();
String failMessage = "Failed inference for: " + newExpression.getParent().getText();
assertNotNull(failMessage, arguments);
PsiDiamondType diamondType = PsiDiamondType.getDiamondType(newExpression);
if (diamondType != null) {
JavaResolveResult staticFactory = diamondType.getStaticFactory();
assertNotNull(staticFactory);
assertTrue(staticFactory instanceof MethodCandidateInfo);
assertNull(failMessage, ((MethodCandidateInfo)staticFactory).getInferenceErrorMessage());
}
}
}