JS: Fix ClassCastException that occurs when 'when' clause has map range #KT-23458 Fixed

This commit is contained in:
Toshiaki Kameyama
2018-06-05 10:04:57 +09:00
committed by Anton Bannykh
parent 65ba57bcae
commit 84e49e5b57
4 changed files with 27 additions and 2 deletions
@@ -3202,6 +3202,11 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
runTest("js/js.translator/testData/box/expression/when/whenWithLongRangeClause.kt");
}
@TestMetadata("whenWithMapRangeClause.kt")
public void testWhenWithMapRangeClause() throws Exception {
runTest("js/js.translator/testData/box/expression/when/whenWithMapRangeClause.kt");
}
@TestMetadata("whenWithOneStmWhen.kt")
public void testWhenWithOneStmWhen() throws Exception {
runTest("js/js.translator/testData/box/expression/when/whenWithOneStmWhen.kt");
@@ -3202,6 +3202,11 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest {
runTest("js/js.translator/testData/box/expression/when/whenWithLongRangeClause.kt");
}
@TestMetadata("whenWithMapRangeClause.kt")
public void testWhenWithMapRangeClause() throws Exception {
runTest("js/js.translator/testData/box/expression/when/whenWithMapRangeClause.kt");
}
@TestMetadata("whenWithOneStmWhen.kt")
public void testWhenWithOneStmWhen() throws Exception {
runTest("js/js.translator/testData/box/expression/when/whenWithOneStmWhen.kt");
@@ -31,6 +31,7 @@ import org.jetbrains.kotlin.js.translate.utils.*
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.Call.CallType
import org.jetbrains.kotlin.psi.KtExpression
import org.jetbrains.kotlin.psi.KtWhenConditionInRange
import org.jetbrains.kotlin.resolve.calls.callResolverUtil.isInvokeCallOnVariable
import org.jetbrains.kotlin.resolve.calls.callUtil.isSafeCall
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
@@ -148,8 +149,9 @@ private fun translateFunctionCall(
var callExpression = callInfo.translateFunctionCall()
if (CallExpressionTranslator.shouldBeInlined(inlineResolvedCall.resultingDescriptor, context)) {
setInlineCallMetadata(callExpression, resolvedCall.call.callElement as KtExpression,
inlineResolvedCall.resultingDescriptor, context)
val callElement = resolvedCall.call.callElement
val ktExpression = (callElement as? KtWhenConditionInRange)?.rangeExpression ?: callElement as KtExpression
setInlineCallMetadata(callExpression, ktExpression, inlineResolvedCall.resultingDescriptor, context)
}
if (resolvedCall.resultingDescriptor.isSuspend) {
@@ -0,0 +1,13 @@
// IGNORE_BACKEND: JS_IR
// EXPECTED_REACHABLE_NODES: 1096
package foo
fun box(): String {
val map = mapOf(1 to "")
val i = 1
return when (i) {
in map -> "OK"
else -> "fail"
}
}