inline: try to insert cast when conditional expr is inlined (IDEA-91288)

This commit is contained in:
Anna Kozlova
2012-09-13 22:11:29 +04:00
parent 1fd115a6b5
commit a9d8837b82
4 changed files with 19 additions and 1 deletions
@@ -55,7 +55,8 @@ public class InlineUtil {
PsiExpression expr = (PsiExpression)replaceDiamondWithInferredTypesIfNeeded(initializer, ref);
PsiType exprType = expr.getType();
if (exprType != null && (!varType.equals(exprType) && varType instanceof PsiPrimitiveType
|| !TypeConversionUtil.isAssignable(varType, exprType))) {
|| !TypeConversionUtil.isAssignable(varType, exprType)
|| expr instanceof PsiConditionalExpression)) {
boolean matchedTypes = false;
//try explicit type arguments
final PsiElementFactory elementFactory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
@@ -0,0 +1,7 @@
public class Test2 {
{
Integer iii = true ? 1 : 2;
<caret>iii.byteValue();
}
}
@@ -0,0 +1,6 @@
public class Test2 {
{
((Integer) (true ? 1 : 2)).byteValue();
}
}
@@ -148,6 +148,10 @@ public class InlineLocalTest extends LightCodeInsightTestCase {
"Variable 'x' is accessed for writing.");
}
public void testConditionExpr() throws Exception {
doTest(true);
}
public void testLambdaExpr() throws Exception {
doTest(true);
}