From ff77155b5a0930d62277a6a1f6a80868df34a6d9 Mon Sep 17 00:00:00 2001 From: Zalim Bashorov Date: Tue, 8 Dec 2020 00:01:57 +0300 Subject: [PATCH] [JS IR] A type argument of the jsClass intrinsic must be a class (IrClass) --- .../irToJs/JsIntrinsicTransformers.kt | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/JsIntrinsicTransformers.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/JsIntrinsicTransformers.kt index 004be491487..22f1aa5ab77 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/JsIntrinsicTransformers.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/transformers/irToJs/JsIntrinsicTransformers.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -17,9 +17,11 @@ import org.jetbrains.kotlin.ir.expressions.IrFunctionReference import org.jetbrains.kotlin.ir.symbols.IrClassifierSymbol import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol import org.jetbrains.kotlin.ir.symbols.IrSymbol +import org.jetbrains.kotlin.ir.types.classOrNull import org.jetbrains.kotlin.ir.types.classifierOrFail import org.jetbrains.kotlin.ir.util.getInlineClassBackingField import org.jetbrains.kotlin.ir.util.isEffectivelyExternal +import org.jetbrains.kotlin.ir.util.render import org.jetbrains.kotlin.js.backend.ast.* typealias IrCallTransformer = (IrCall, context: JsGenerationContext) -> JsExpression @@ -89,15 +91,18 @@ class JsIntrinsicTransformers(backendContext: JsIrBackendContext) { } add(intrinsics.jsClass) { call, context -> - val classifier: IrClassifierSymbol = call.getTypeArgument(0)!!.classifierOrFail - val owner = classifier.owner + val typeArgument = call.getTypeArgument(0) + val classSymbol = typeArgument?.classOrNull + ?: error("Type argument of jsClass must be statically known class, but " + typeArgument?.render()) + + val klass = classSymbol.owner when { - owner is IrClass && owner.isEffectivelyExternal() -> - context.getRefForExternalClass(owner) + klass.isEffectivelyExternal() -> + context.getRefForExternalClass(klass) else -> - context.getNameForStaticDeclaration(owner as IrDeclarationWithName).makeRef() + context.getNameForStaticDeclaration(klass as IrDeclarationWithName).makeRef() } }