[KT-11027] Fix the issue
This commit is contained in:
+4
-2
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.js.translate.general.Translation;
|
|||||||
import org.jetbrains.kotlin.js.translate.operation.InOperationTranslator;
|
import org.jetbrains.kotlin.js.translate.operation.InOperationTranslator;
|
||||||
import org.jetbrains.kotlin.js.translate.utils.JsAstUtils;
|
import org.jetbrains.kotlin.js.translate.utils.JsAstUtils;
|
||||||
import org.jetbrains.kotlin.js.translate.utils.TranslationUtils;
|
import org.jetbrains.kotlin.js.translate.utils.TranslationUtils;
|
||||||
|
import org.jetbrains.kotlin.lexer.KtTokens;
|
||||||
import org.jetbrains.kotlin.psi.*;
|
import org.jetbrains.kotlin.psi.*;
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.PsiUtilsKt;
|
import org.jetbrains.kotlin.psi.psiUtil.PsiUtilsKt;
|
||||||
|
|
||||||
@@ -208,8 +209,9 @@ public final class WhenTranslator extends AbstractTranslator {
|
|||||||
Map<KtExpression, JsExpression> subjectAliases = new HashMap<KtExpression, JsExpression>();
|
Map<KtExpression, JsExpression> subjectAliases = new HashMap<KtExpression, JsExpression>();
|
||||||
subjectAliases.put(whenExpression.getSubjectExpression(), expressionToMatch);
|
subjectAliases.put(whenExpression.getSubjectExpression(), expressionToMatch);
|
||||||
TranslationContext callContext = context.innerContextWithAliasesForExpressions(subjectAliases);
|
TranslationContext callContext = context.innerContextWithAliasesForExpressions(subjectAliases);
|
||||||
return new InOperationTranslator(callContext, expressionToMatch, condition.getRangeExpression(), condition.getOperationReference())
|
boolean negated = condition.getOperationReference().getReferencedNameElementType() == KtTokens.NOT_IN;
|
||||||
.translate();
|
return new InOperationTranslator(callContext, expressionToMatch, condition.getRangeExpression(), condition.getOperationReference(),
|
||||||
|
negated).translate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|||||||
+18
-5
@@ -43,13 +43,15 @@ public class InOperationTranslator extends AbstractTranslator {
|
|||||||
private final JsExpression left;
|
private final JsExpression left;
|
||||||
private final KtExpression right;
|
private final KtExpression right;
|
||||||
private final KtSimpleNameExpression operation;
|
private final KtSimpleNameExpression operation;
|
||||||
|
private final boolean negated;
|
||||||
|
|
||||||
public InOperationTranslator(@NotNull TranslationContext context, @NotNull JsExpression left, @NotNull KtExpression right,
|
public InOperationTranslator(@NotNull TranslationContext context, @NotNull JsExpression left, @NotNull KtExpression right,
|
||||||
@NotNull KtSimpleNameExpression operation) {
|
@NotNull KtSimpleNameExpression operation, boolean negated) {
|
||||||
super(context);
|
super(context);
|
||||||
this.left = left;
|
this.left = left;
|
||||||
this.right = right;
|
this.right = right;
|
||||||
this.operation = operation;
|
this.operation = operation;
|
||||||
|
this.negated = negated;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -67,7 +69,11 @@ public class InOperationTranslator extends AbstractTranslator {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private JsExpression translateGeneral(@NotNull ResolvedCall<? extends FunctionDescriptor> call, @NotNull JsExpression rightTranslated) {
|
private JsExpression translateGeneral(@NotNull ResolvedCall<? extends FunctionDescriptor> call, @NotNull JsExpression rightTranslated) {
|
||||||
return CallTranslator.translate(context(), call, rightTranslated);
|
JsExpression result = CallTranslator.translate(context(), call, rightTranslated);
|
||||||
|
if (negated) {
|
||||||
|
result = JsAstUtils.negated(result);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -94,8 +100,15 @@ public class InOperationTranslator extends AbstractTranslator {
|
|||||||
private JsExpression translateInt(@NotNull KtExpression lowerExpression, @NotNull KtExpression upperExpression) {
|
private JsExpression translateInt(@NotNull KtExpression lowerExpression, @NotNull KtExpression upperExpression) {
|
||||||
JsExpression lower = Translation.translateAsExpression(lowerExpression, context());
|
JsExpression lower = Translation.translateAsExpression(lowerExpression, context());
|
||||||
JsExpression upper = Translation.translateAsExpression(upperExpression, context());
|
JsExpression upper = Translation.translateAsExpression(upperExpression, context());
|
||||||
JsExpression first = JsAstUtils.greaterThanEq(left, lower);
|
if (!negated) {
|
||||||
JsExpression second = JsAstUtils.lessThanEq(left, upper);
|
JsExpression first = JsAstUtils.greaterThanEq(left, lower);
|
||||||
return JsAstUtils.and(first, second);
|
JsExpression second = JsAstUtils.lessThanEq(left, upper);
|
||||||
|
return JsAstUtils.and(first, second);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
JsExpression first = JsAstUtils.lessThan(left, lower);
|
||||||
|
JsExpression second = JsAstUtils.greaterThan(left, upper);
|
||||||
|
return JsAstUtils.or(first, second);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-1
@@ -4,7 +4,10 @@ package foo
|
|||||||
|
|
||||||
fun box(): String {
|
fun box(): String {
|
||||||
var result = testFun(-1) + testFun(0) + testFun(5) + testFun(9) + testFun(10) + testFun(150)
|
var result = testFun(-1) + testFun(0) + testFun(5) + testFun(9) + testFun(10) + testFun(150)
|
||||||
return if (result == "misshithithitmisshit!") "OK" else "fail"
|
if (result != "misshithithitmisshit!") return "fail1: $result"
|
||||||
|
result = testFun2(-1) + testFun2(0) + testFun2(9) + testFun2(10)
|
||||||
|
if (result != "hitmissmisshit") return "fail2: $result"
|
||||||
|
return "OK"
|
||||||
}
|
}
|
||||||
fun testFun(index: Int): String {
|
fun testFun(index: Int): String {
|
||||||
var lower = Wrapper(0)
|
var lower = Wrapper(0)
|
||||||
@@ -16,6 +19,12 @@ fun testFun(index: Int): String {
|
|||||||
else -> "miss"
|
else -> "miss"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fun testFun2(index: Int): String {
|
||||||
|
return when (Wrapper(index)) {
|
||||||
|
!in Wrapper(0)..Wrapper(9) -> "hit"
|
||||||
|
else -> "miss"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class Wrapper(val value: Int) : Comparable<Wrapper> {
|
class Wrapper(val value: Int) : Comparable<Wrapper> {
|
||||||
operator fun rangeTo(upper: Wrapper) = WrapperRange(this, upper)
|
operator fun rangeTo(upper: Wrapper) = WrapperRange(this, upper)
|
||||||
|
|||||||
@@ -4,7 +4,10 @@ package foo
|
|||||||
|
|
||||||
fun box(): String {
|
fun box(): String {
|
||||||
var result = testFun(-1) + testFun(0) + testFun(5) + testFun(9) + testFun(10) + testFun(150) + testFun(800)
|
var result = testFun(-1) + testFun(0) + testFun(5) + testFun(9) + testFun(10) + testFun(150) + testFun(800)
|
||||||
return if (result == "misshithithitmisshit!@@@" && invocationCount == 7) "OK" else "fail"
|
if (result != "misshithithitmisshit!@@@" || invocationCount != 7) return "fail1:" + result
|
||||||
|
result = testFun2(-1) + testFun2(0) + testFun2(9) + testFun2(10)
|
||||||
|
if (result != "hitmissmisshit") return "fail2:" + result
|
||||||
|
return "OK"
|
||||||
}
|
}
|
||||||
fun testFun(index: Int): String {
|
fun testFun(index: Int): String {
|
||||||
val thirdRange = 500..1000
|
val thirdRange = 500..1000
|
||||||
@@ -15,6 +18,12 @@ fun testFun(index: Int): String {
|
|||||||
else -> "miss"
|
else -> "miss"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fun testFun2(index: Int): String {
|
||||||
|
return when(index) {
|
||||||
|
!in 0..9 -> "hit"
|
||||||
|
else -> "miss"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun get(value: Int): Int {
|
fun get(value: Int): Int {
|
||||||
invocationCount++
|
invocationCount++
|
||||||
|
|||||||
Reference in New Issue
Block a user