Check type of elvis with expected type info

#KT-6713
This commit is contained in:
Denis Zharkov
2015-07-17 13:00:48 +03:00
parent 53edb83a56
commit 3ec00114c0
4 changed files with 33 additions and 1 deletions
@@ -1306,7 +1306,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
}
// If break or continue was possible, take condition check info as the jump info
return TypeInfoFactoryPackage.createTypeInfo(DataFlowUtils.checkType(type, expression, context),
return TypeInfoFactoryPackage.createTypeInfo(DataFlowUtils.checkType(type, expression, contextWithExpectedType),
dataFlowInfo,
loopBreakContinuePossible,
context.dataFlowInfo);
@@ -0,0 +1,5 @@
class RightElvisOperand {
static String foo() {
return null;
}
}
@@ -0,0 +1,21 @@
fun baz(): String? = null
fun bar(): String = baz() ?: RightElvisOperand.foo()
fun foo(x: String) {}
fun box(): String {
try {
foo(baz() ?: RightElvisOperand.foo())
return "Fail: should have been an exception in `foo(baz() ?: RightElvisOperand.foo())`"
}
catch(e: IllegalStateException) {}
try {
bar()
return "Fail: should have been an exception in `bar()`"
}
catch(e: IllegalStateException) {
return "OK"
}
}
@@ -423,6 +423,12 @@ public class BlackBoxAgainstJavaCodegenTestGenerated extends AbstractBlackBoxCod
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxAgainstJava/notNullAssertions/Delegation.kt");
doTestAgainstJava(fileName);
}
@TestMetadata("RightElvisOperand.kt")
public void testRightElvisOperand() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxAgainstJava/notNullAssertions/RightElvisOperand.kt");
doTestAgainstJava(fileName);
}
}
@TestMetadata("compiler/testData/codegen/boxAgainstJava/platformTypes")