Added support for returning value from safe qualified expression.
This commit is contained in:
@@ -379,10 +379,11 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
|
||||
public JsNode visitSafeQualifiedExpression(@NotNull JetSafeQualifiedExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
JsExpression receiver = translateReceiver(expression, context);
|
||||
JsNullLiteral nullLiteral = context.program().getNullLiteral();
|
||||
JsBinaryOperation nullCheck = new JsBinaryOperation
|
||||
(JsBinaryOperator.NEQ, receiver, context.program().getNullLiteral());
|
||||
JsStatement thenStatement = AstUtil.convertToStatement(translateQualifiedExpression(expression, context));
|
||||
return new JsIf(nullCheck, thenStatement, null);
|
||||
(JsBinaryOperator.NEQ, receiver, nullLiteral);
|
||||
JsExpression thenExpression = AstUtil.convertToExpression(translateQualifiedExpression(expression, context));
|
||||
return new JsConditional(nullCheck, thenExpression, nullLiteral);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -44,6 +44,11 @@ public final class PropertyAccessorTest extends AbstractClassTest {
|
||||
testFooBoxIsTrue("safeCall.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void safeCallReturnsNullIfFails() throws Exception {
|
||||
testFooBoxIsTrue("safeCallReturnsNullIfFails.kt");
|
||||
}
|
||||
|
||||
//TODO test
|
||||
// @Test
|
||||
// public void namespaceCustomAccessors() throws Exception {
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace foo
|
||||
|
||||
class A() {
|
||||
val x = 4
|
||||
}
|
||||
|
||||
fun box() : Boolean {
|
||||
var a : A? = null;
|
||||
return (a?.x == null);
|
||||
}
|
||||
Reference in New Issue
Block a user