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,
|
public JsNode visitSafeQualifiedExpression(@NotNull JetSafeQualifiedExpression expression,
|
||||||
@NotNull TranslationContext context) {
|
@NotNull TranslationContext context) {
|
||||||
JsExpression receiver = translateReceiver(expression, context);
|
JsExpression receiver = translateReceiver(expression, context);
|
||||||
|
JsNullLiteral nullLiteral = context.program().getNullLiteral();
|
||||||
JsBinaryOperation nullCheck = new JsBinaryOperation
|
JsBinaryOperation nullCheck = new JsBinaryOperation
|
||||||
(JsBinaryOperator.NEQ, receiver, context.program().getNullLiteral());
|
(JsBinaryOperator.NEQ, receiver, nullLiteral);
|
||||||
JsStatement thenStatement = AstUtil.convertToStatement(translateQualifiedExpression(expression, context));
|
JsExpression thenExpression = AstUtil.convertToExpression(translateQualifiedExpression(expression, context));
|
||||||
return new JsIf(nullCheck, thenStatement, null);
|
return new JsConditional(nullCheck, thenExpression, nullLiteral);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -44,6 +44,11 @@ public final class PropertyAccessorTest extends AbstractClassTest {
|
|||||||
testFooBoxIsTrue("safeCall.kt");
|
testFooBoxIsTrue("safeCall.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void safeCallReturnsNullIfFails() throws Exception {
|
||||||
|
testFooBoxIsTrue("safeCallReturnsNullIfFails.kt");
|
||||||
|
}
|
||||||
|
|
||||||
//TODO test
|
//TODO test
|
||||||
// @Test
|
// @Test
|
||||||
// public void namespaceCustomAccessors() throws Exception {
|
// 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