mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-20 13:31:28 +07:00
conditional expression: use target type for overload cases when assignable
GitOrigin-RevId: 2be5da156f1726f8536e6fc6447ae847629b0001
This commit is contained in:
committed by
intellij-monorepo-bot
parent
c8cf98f173
commit
0374b5f49c
@@ -67,11 +67,16 @@ public class PsiConditionalExpressionImpl extends ExpressionPsiElement implement
|
||||
if (type1.equals(type2)) return type1;
|
||||
|
||||
if (PsiUtil.isLanguageLevel8OrHigher(this) &&
|
||||
PsiPolyExpressionUtil.isPolyExpression(this) &&
|
||||
!MethodCandidateInfo.isOverloadCheck(PsiUtil.skipParenthesizedExprUp(this.getParent()))) {
|
||||
PsiPolyExpressionUtil.isPolyExpression(this)) {
|
||||
//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);
|
||||
PsiType targetType = InferenceSession.getTargetType(this);
|
||||
if (!MethodCandidateInfo.isOverloadCheck(PsiUtil.skipParenthesizedExprUp(this.getParent()))) {
|
||||
return targetType;
|
||||
}
|
||||
return targetType != null &&
|
||||
targetType.isAssignableFrom(type1) &&
|
||||
targetType.isAssignableFrom(type2) ? targetType : null;
|
||||
}
|
||||
|
||||
final int typeRank1 = TypeConversionUtil.getTypeRank(type1);
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
interface I {
|
||||
void f();
|
||||
}
|
||||
|
||||
class B implements I {
|
||||
@Override
|
||||
public void f() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class MyTest {
|
||||
void m(I i) {}
|
||||
|
||||
void n(int ik) {
|
||||
m(ik > 0 ? () -> {} : new B());
|
||||
}
|
||||
}
|
||||
@@ -202,6 +202,7 @@ public class GraphInferenceHighlightingTest extends LightDaemonAnalyzerTestCase
|
||||
}
|
||||
public void testNotInferredVarShouldNotBeUsedForInferenceJava10() { doTest(); }
|
||||
public void testJavac8UnCaptureBug() { doTest(); }
|
||||
public void testLambdaInConditional() { doTest(); }
|
||||
public void testTopLevelParentNoParameters() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user