[JS IR] Use type upper bounds for calculating function signatures
^KT-59239 Fixed
This commit is contained in:
committed by
Space Team
parent
a4d40498c7
commit
fc898c7620
+6
@@ -2942,6 +2942,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr
|
||||
runTest("compiler/testData/codegen/box/builtinStubMethods/extendJavaClasses/numberMixedHierarchy.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overrideAbstractSetMethod.kt")
|
||||
public void testOverrideAbstractSetMethod() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/builtinStubMethods/extendJavaClasses/overrideAbstractSetMethod.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("removeAtBridgeToJavaClass.kt")
|
||||
public void testRemoveAtBridgeToJavaClass() throws Exception {
|
||||
|
||||
+6
@@ -2942,6 +2942,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo
|
||||
runTest("compiler/testData/codegen/box/builtinStubMethods/extendJavaClasses/numberMixedHierarchy.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overrideAbstractSetMethod.kt")
|
||||
public void testOverrideAbstractSetMethod() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/builtinStubMethods/extendJavaClasses/overrideAbstractSetMethod.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("removeAtBridgeToJavaClass.kt")
|
||||
public void testRemoveAtBridgeToJavaClass() throws Exception {
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsManglerIr
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.symbols.IrReturnableBlockSymbol
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.isUnit
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
|
||||
@@ -115,6 +116,13 @@ fun Int.toJsIdentifier(): String {
|
||||
}
|
||||
}
|
||||
|
||||
private fun List<IrType>.joinTypes(): String {
|
||||
if (isEmpty()) {
|
||||
return ""
|
||||
}
|
||||
return joinToString("$", "$") { superType -> superType.asString() }
|
||||
}
|
||||
|
||||
fun calculateJsFunctionSignature(declaration: IrFunction, context: JsIrBackendContext): String {
|
||||
val declarationName = declaration.nameIfPropertyAccessor() ?: declaration.getJsNameOrKotlinName().asString()
|
||||
|
||||
@@ -125,20 +133,18 @@ fun calculateJsFunctionSignature(declaration: IrFunction, context: JsIrBackendCo
|
||||
declaration.typeParameters.ifNotEmpty {
|
||||
nameBuilder.append("_\$t")
|
||||
forEach { typeParam ->
|
||||
nameBuilder.append("_").append(typeParam.name.asString())
|
||||
typeParam.superTypes.ifNotEmpty {
|
||||
nameBuilder.append("$")
|
||||
joinTo(nameBuilder, "") { type -> type.asString() }
|
||||
}
|
||||
nameBuilder.append("_").append(typeParam.name.asString()).append(typeParam.superTypes.joinTypes())
|
||||
}
|
||||
}
|
||||
declaration.extensionReceiverParameter?.let {
|
||||
nameBuilder.append("_r$${it.type.asString()}")
|
||||
val superTypes = it.type.superTypes().joinTypes()
|
||||
nameBuilder.append("_r$${it.type.asString()}$superTypes")
|
||||
}
|
||||
declaration.valueParameters.ifNotEmpty {
|
||||
joinTo(nameBuilder, "") {
|
||||
val defaultValueSign = if (it.origin == JsLoweredDeclarationOrigin.JS_SHADOWED_DEFAULT_PARAMETER) "?" else ""
|
||||
"_${it.type.asString()}$defaultValueSign"
|
||||
val superTypes = it.type.superTypes().joinTypes()
|
||||
"_${it.type.asString()}$superTypes$defaultValueSign"
|
||||
}
|
||||
}
|
||||
declaration.returnType.let {
|
||||
|
||||
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
// DONT_TARGET_EXACT_BACKEND: JS
|
||||
// WITH_STDLIB
|
||||
|
||||
class MySet<K, V, E : Map.Entry<K, V>>: AbstractSet<E>() {
|
||||
override fun contains(element: E): Boolean { return element.key !== null }
|
||||
|
||||
override val size: Int get() = 0
|
||||
override fun isEmpty(): Boolean = false
|
||||
override fun containsAll(elements: Collection<E>): Boolean = false
|
||||
|
||||
override fun iterator(): Iterator<E> = TODO("")
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val h = MySet<Int, Int, Map.Entry<Int, Int>>()
|
||||
val c = (object {}).let { h.contains(it as Any?) }
|
||||
return if (c) "NOT OK" else "OK"
|
||||
}
|
||||
+6
@@ -2786,6 +2786,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/builtinStubMethods/extendJavaClasses/numberMixedHierarchy.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overrideAbstractSetMethod.kt")
|
||||
public void testOverrideAbstractSetMethod() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/builtinStubMethods/extendJavaClasses/overrideAbstractSetMethod.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("removeAtBridgeToJavaClass.kt")
|
||||
public void testRemoveAtBridgeToJavaClass() throws Exception {
|
||||
|
||||
+6
@@ -2942,6 +2942,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/builtinStubMethods/extendJavaClasses/numberMixedHierarchy.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overrideAbstractSetMethod.kt")
|
||||
public void testOverrideAbstractSetMethod() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/builtinStubMethods/extendJavaClasses/overrideAbstractSetMethod.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("removeAtBridgeToJavaClass.kt")
|
||||
public void testRemoveAtBridgeToJavaClass() throws Exception {
|
||||
|
||||
+6
@@ -2942,6 +2942,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack
|
||||
runTest("compiler/testData/codegen/box/builtinStubMethods/extendJavaClasses/numberMixedHierarchy.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("overrideAbstractSetMethod.kt")
|
||||
public void testOverrideAbstractSetMethod() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/builtinStubMethods/extendJavaClasses/overrideAbstractSetMethod.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("removeAtBridgeToJavaClass.kt")
|
||||
public void testRemoveAtBridgeToJavaClass() throws Exception {
|
||||
|
||||
+5
@@ -2438,6 +2438,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/builtinStubMethods/extendJavaClasses/numberMixedHierarchy.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("overrideAbstractSetMethod.kt")
|
||||
public void testOverrideAbstractSetMethod() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/builtinStubMethods/extendJavaClasses/overrideAbstractSetMethod.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("removeAtBridgeToJavaClass.kt")
|
||||
public void testRemoveAtBridgeToJavaClass() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/builtinStubMethods/extendJavaClasses/removeAtBridgeToJavaClass.kt");
|
||||
|
||||
Reference in New Issue
Block a user