conditional: ensure to convert type from parent to ll >= 1.8 so assignments would be correct, etc (IDEA-161854)

This commit is contained in:
Anna.Kozlova
2016-09-29 19:02:22 +02:00
parent 46605f3b1a
commit e052fabb42
4 changed files with 23 additions and 1 deletions

View File

@@ -71,7 +71,11 @@ public class PsiConditionalExpressionImpl extends ExpressionPsiElement implement
!MethodCandidateInfo.ourOverloadGuard.currentStack().contains(PsiUtil.skipParenthesizedExprUp(this.getParent()))) {
//15.25.3 Reference Conditional Expressions
// The type of a poly reference conditional expression is the same as its target type.
return InferenceSession.getTargetType(this);
final PsiType targetType = InferenceSession.getTargetType(this);
if (targetType instanceof PsiClassType) {
return ((PsiClassType)targetType).setLanguageLevel(PsiUtil.getLanguageLevel(this));
}
return targetType;
}
final int typeRank1 = TypeConversionUtil.getTypeRank(type1);

View File

@@ -0,0 +1,4 @@
package p;
class A {
public void foo(Object o) {}
}

View File

@@ -0,0 +1,6 @@
package p;
class B {
void bar(A a) {
a.foo(true ? "1" : 1);
}
}

View File

@@ -253,6 +253,14 @@ public class MultipleJdksHighlightingTest extends UsefulTestCase {
assertContainsElements(MethodReferencesSearch.search(method).findAll(), ref);
}
public void testConditionalAssignedToJava3Object() throws Exception {
ModuleRootModificationUtil.addDependency(myJava8Module, myJava3Module);
final String name = getTestName(false);
myFixture.copyFileToProject("java3/p/" + name + ".java");
myFixture.configureByFiles("java8/p/" + name + ".java");
myFixture.checkHighlighting();
}
private void doTestWithoutLibrary() {
final String name = getTestName(false);
myFixture.configureByFiles("java7/p/" + name + ".java", "java8/p/" + name + ".java");