treat conditional expressions with new expressions with diamonds inside as poly

EA-76546 - assert: InferenceSessionContainer.treeWalkUp
This commit is contained in:
Anna.Kozlova
2016-04-19 14:57:26 +02:00
parent abf32b50d5
commit c09caae28e
3 changed files with 25 additions and 2 deletions

View File

@@ -169,9 +169,13 @@ public class PsiPolyExpressionUtil {
}
if (expr == null) return null;
PsiType type = null;
if (expr instanceof PsiNewExpression || hasStandaloneForm(expr)) {
//A class instance creation expression (§15.9) for a class that is convertible to a numeric type.
//As numeric classes do not have type parameters, at this point expressions with diamonds could be ignored
if (expr instanceof PsiNewExpression && !PsiDiamondType.hasDiamond((PsiNewExpression)expr) ||
hasStandaloneForm(expr)) {
type = expr.getType();
} else if (expr instanceof PsiMethodCallExpression) {
}
else if (expr instanceof PsiMethodCallExpression) {
final PsiMethod method = ((PsiMethodCallExpression)expr).resolveMethod();
if (method != null) {
type = method.getReturnType();

View File

@@ -0,0 +1,15 @@
class FImpl<K> {
public FImpl(K k) {
}
public void myMethod() {
foo (false ? new FImpl<>(null) : null);
}
private <T> T foo(final T bar) {
return null;
}
private <T> T foo(final String bar) {
return null;
}
}

View File

@@ -437,6 +437,10 @@ public class GraphInferenceHighlightingTest extends LightDaemonAnalyzerTestCase
doTest();
}
public void testTreatConditionalExpressionAsPolyIfNewExpressionWithDiamondsIsUsed() throws Exception {
doTest();
}
public void testVariableNamesOfNestedCalls() throws Exception {
IdeaTestUtil.setTestVersion(JavaSdkVersion.JDK_1_8, getModule(), getTestRootDisposable());
String filePath = BASE_PATH + "/" + getTestName(false) + ".java";