JS: Fix ClassCastException that occurs when 'when' clause has map range #KT-23458 Fixed
This commit is contained in:
committed by
Anton Bannykh
parent
65ba57bcae
commit
84e49e5b57
+5
@@ -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");
|
||||
|
||||
+5
@@ -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");
|
||||
|
||||
+4
-2
@@ -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"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user