KT-2310: js: !! translated incorrectly (syntax ok, but logic not).
#KT-2310 Fixed
This commit is contained in:
@@ -148,6 +148,10 @@ public final class MiscTest extends AbstractExpressionTest {
|
||||
fooBoxTest();
|
||||
}
|
||||
|
||||
public void testExclExclResultIsComputedOnce() throws Exception {
|
||||
fooBoxTest();
|
||||
}
|
||||
|
||||
public void testLazyPropertyGetterNotCalledOnStart() throws Exception {
|
||||
checkOutput("lazyProperty.kt", "Hello, world! Gotcha 3");
|
||||
}
|
||||
|
||||
+6
-4
@@ -19,10 +19,11 @@ package org.jetbrains.k2js.translate.operation;
|
||||
import com.google.dart.compiler.backend.js.ast.JsBinaryOperation;
|
||||
import com.google.dart.compiler.backend.js.ast.JsConditional;
|
||||
import com.google.dart.compiler.backend.js.ast.JsExpression;
|
||||
import com.google.dart.compiler.backend.js.ast.JsNameRef;
|
||||
import com.google.dart.compiler.util.AstUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.psi.JetUnaryExpression;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
import org.jetbrains.k2js.translate.context.TemporaryVariable;
|
||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||
import org.jetbrains.k2js.translate.reference.CallBuilder;
|
||||
import org.jetbrains.k2js.translate.reference.CallType;
|
||||
@@ -63,9 +64,10 @@ public final class UnaryOperationTranslator {
|
||||
|
||||
@NotNull
|
||||
private static JsExpression translateExclExclOperator(@NotNull JetUnaryExpression expression, @NotNull TranslationContext context) {
|
||||
JsNameRef cachedValue = context.declareTemporary(translateAsExpression(getBaseExpression(expression), context), true).reference();
|
||||
JsBinaryOperation notNullCheck = notNullCheck(context, cachedValue);
|
||||
return new JsConditional(notNullCheck, cachedValue, context.namer().throwNPEFunctionCall());
|
||||
TemporaryVariable cachedValue = context.declareTemporary(translateAsExpression(getBaseExpression(expression), context), false);
|
||||
JsBinaryOperation initAndCheckNotNull = AstUtil.newSequence(cachedValue.assignmentExpression(),
|
||||
notNullCheck(context, cachedValue.reference()));
|
||||
return new JsConditional(initAndCheckNotNull, cachedValue.reference(), context.namer().throwNPEFunctionCall());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package foo
|
||||
|
||||
var c = 0
|
||||
val a: Int?
|
||||
get() {
|
||||
c++
|
||||
return 2
|
||||
}
|
||||
|
||||
fun box() : Boolean {
|
||||
return c == 0 && (a!! + 3) == 5 && c == 1
|
||||
}
|
||||
Reference in New Issue
Block a user