[FIR] Load kotlin.arrayOf function in IrBuiltInsOverFir from Fir
^KT-57690 Fixed ^KT-57807 Fixed
This commit is contained in:
committed by
Space Team
parent
6972391185
commit
fb1cdf643b
@@ -533,38 +533,12 @@ class IrBuiltInsOverFir(
|
||||
}
|
||||
}
|
||||
|
||||
private class KotlinPackageFuns(
|
||||
val arrayOf: IrSimpleFunctionSymbol,
|
||||
)
|
||||
|
||||
private val kotlinBuiltinFunctions by lazy {
|
||||
fun IrClassSymbol.addPackageFun(
|
||||
name: String,
|
||||
returnType: IrType,
|
||||
vararg argumentTypes: Pair<String, IrType>,
|
||||
builder: IrSimpleFunction.() -> Unit
|
||||
) =
|
||||
kotlinIrPackage.createFunction(name, returnType, argumentTypes, postBuild = builder).also {
|
||||
this.owner.declarations.add(it)
|
||||
}.symbol
|
||||
|
||||
val kotlinKt = kotlinIrPackage.createClass(kotlinPackage.child(Name.identifier("KotlinKt")))
|
||||
KotlinPackageFuns(
|
||||
arrayOf = kotlinKt.addPackageFun("arrayOf", arrayClass.defaultType) arrayOf@{
|
||||
val typeParameter = addTypeParameter("T", anyNType)
|
||||
addValueParameter {
|
||||
this.name = Name.identifier("elements")
|
||||
this.type = arrayClass.typeWithParameters(listOf(typeParameter))
|
||||
this.varargElementType = typeParameter.defaultType
|
||||
this.origin = this@arrayOf.origin
|
||||
}
|
||||
returnType = arrayClass.typeWithParameters(listOf(typeParameter))
|
||||
}
|
||||
)
|
||||
override val arrayOf: IrSimpleFunctionSymbol by lazy {
|
||||
// distinct() is needed because we can get two Fir symbols for arrayOf function (from builtins and from stdlib)
|
||||
// with the same IR symbol for them
|
||||
findFunctions(kotlinPackage, Name.identifier("arrayOf")).distinct().single()
|
||||
}
|
||||
|
||||
override val arrayOf: IrSimpleFunctionSymbol get() = kotlinBuiltinFunctions.arrayOf
|
||||
|
||||
private fun <T : Any> getFunctionsByKey(
|
||||
name: Name,
|
||||
vararg packageNameSegments: String,
|
||||
|
||||
+8
@@ -55,4 +55,12 @@ class K2KotlinxSerializationIT : KGPBaseTest() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@DisplayName("Compile production executable with kotlinx.serialization to JS. KT-57690, KT-57807")
|
||||
@GradleTest
|
||||
fun `test kotlinx serialization compile to JS`() {
|
||||
project("kotlinxSerializationK2WithJs", gradleVersion) {
|
||||
build(":compileProductionExecutableKotlinJs")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
plugins {
|
||||
kotlin("js")
|
||||
kotlin("plugin.serialization")
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
mavenLocal()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.0")
|
||||
}
|
||||
|
||||
kotlin {
|
||||
js {
|
||||
binaries.executable()
|
||||
browser {}
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
all {
|
||||
languageSettings.apply {
|
||||
languageVersion = "2.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
fun callArrayOf(): Array<String> {
|
||||
return arrayOf("a", "b")
|
||||
}
|
||||
|
||||
@Serializable
|
||||
class ErrorResponse(
|
||||
val code: Int,
|
||||
val message: String,
|
||||
)
|
||||
Reference in New Issue
Block a user