[JS IR] Fix case with bridge with nested classes

^KT-54686 fixed
This commit is contained in:
Ilya Goncharov
2022-10-26 12:56:03 +00:00
committed by Space Team
parent 2e48557a0d
commit fd5fba6f09
12 changed files with 75 additions and 9 deletions
@@ -2363,6 +2363,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/bridges/methodFromTrait.kt");
}
@Test
@TestMetadata("nestedClassTypeParameters.kt")
public void testNestedClassTypeParameters() throws Exception {
runTest("compiler/testData/codegen/box/bridges/nestedClassTypeParameters.kt");
}
@Test
@TestMetadata("noBridgeOnMutableCollectionInheritance.kt")
public void testNoBridgeOnMutableCollectionInheritance() throws Exception {
@@ -415,10 +415,4 @@ class JsIrBackendContext(
outlinedJsCodeFunctions[symbol] = parsedJsFunction
return parsedJsFunction
}
private var irFunctionSignatureCache = hashMapOf<IrFunction, String>()
fun getFunctionSignatureFromCache(f: IrFunction): String {
return irFunctionSignatureCache.getOrPut(f) { calculateJsFunctionSignature(f, this) }
}
}
@@ -34,7 +34,10 @@ class JsBridgesConstruction(context: JsIrBackendContext) : BridgesConstruction<J
private val primitiveToLiteralConstructor = context.intrinsics.primitiveToLiteralConstructor
override fun getFunctionSignature(function: IrSimpleFunction) =
jsFunctionSignature(function, context)
jsFunctionSignature(
function,
context
)
override fun getBridgeOrigin(bridge: IrSimpleFunction): IrDeclarationOrigin =
when {
@@ -158,7 +158,10 @@ fun calculateJsFunctionSignature(declaration: IrFunction, context: JsIrBackendCo
) + "_" + abs(signature.hashCode()).toString(Character.MAX_RADIX) + RESERVED_MEMBER_NAME_SUFFIX
}
fun jsFunctionSignature(declaration: IrFunction, context: JsIrBackendContext): String {
fun jsFunctionSignature(
declaration: IrFunction,
context: JsIrBackendContext
): String {
require(!declaration.isStaticMethodOfClass)
require(declaration.dispatchReceiverParameter != null)
@@ -172,7 +175,7 @@ fun jsFunctionSignature(declaration: IrFunction, context: JsIrBackendContext): S
}
val declarationSignature = (declaration as? IrSimpleFunction)?.resolveFakeOverride() ?: declaration
return context.getFunctionSignatureFromCache(declarationSignature)
return calculateJsFunctionSignature(declarationSignature, context)
}
class NameTables(
@@ -0,0 +1,20 @@
class Outer {
class Inner {
fun foo() = "K"
}
}
interface I<T> {
fun foo(t: T, inner: Outer.Inner): String
}
open class Child : I<String> {
override fun foo(t: String, inner: Outer.Inner): String {
return t + inner.foo()
}
}
fun box(): String {
val child: I<String> = Child()
return child.foo("O", Outer.Inner())
}
@@ -2267,6 +2267,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/bridges/methodFromTrait.kt");
}
@Test
@TestMetadata("nestedClassTypeParameters.kt")
public void testNestedClassTypeParameters() throws Exception {
runTest("compiler/testData/codegen/box/bridges/nestedClassTypeParameters.kt");
}
@Test
@TestMetadata("noBridgeOnMutableCollectionInheritance.kt")
public void testNoBridgeOnMutableCollectionInheritance() throws Exception {
@@ -2363,6 +2363,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/bridges/methodFromTrait.kt");
}
@Test
@TestMetadata("nestedClassTypeParameters.kt")
public void testNestedClassTypeParameters() throws Exception {
runTest("compiler/testData/codegen/box/bridges/nestedClassTypeParameters.kt");
}
@Test
@TestMetadata("noBridgeOnMutableCollectionInheritance.kt")
public void testNoBridgeOnMutableCollectionInheritance() throws Exception {
@@ -1987,6 +1987,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/bridges/methodFromTrait.kt");
}
@TestMetadata("nestedClassTypeParameters.kt")
public void testNestedClassTypeParameters() throws Exception {
runTest("compiler/testData/codegen/box/bridges/nestedClassTypeParameters.kt");
}
@TestMetadata("noBridgeOnMutableCollectionInheritance.kt")
public void testNoBridgeOnMutableCollectionInheritance() throws Exception {
runTest("compiler/testData/codegen/box/bridges/noBridgeOnMutableCollectionInheritance.kt");
@@ -1541,6 +1541,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/bridges/methodFromTrait.kt");
}
@Test
@TestMetadata("nestedClassTypeParameters.kt")
public void testNestedClassTypeParameters() throws Exception {
runTest("compiler/testData/codegen/box/bridges/nestedClassTypeParameters.kt");
}
@Test
@TestMetadata("noBridgeOnMutableCollectionInheritance.kt")
public void testNoBridgeOnMutableCollectionInheritance() throws Exception {
@@ -1595,6 +1595,12 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/bridges/methodFromTrait.kt");
}
@Test
@TestMetadata("nestedClassTypeParameters.kt")
public void testNestedClassTypeParameters() throws Exception {
runTest("compiler/testData/codegen/box/bridges/nestedClassTypeParameters.kt");
}
@Test
@TestMetadata("noBridgeOnMutableCollectionInheritance.kt")
public void testNoBridgeOnMutableCollectionInheritance() throws Exception {
@@ -1417,6 +1417,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
runTest("compiler/testData/codegen/box/bridges/methodFromTrait.kt");
}
@TestMetadata("nestedClassTypeParameters.kt")
public void testNestedClassTypeParameters() throws Exception {
runTest("compiler/testData/codegen/box/bridges/nestedClassTypeParameters.kt");
}
@TestMetadata("noBridgeOnMutableCollectionInheritance.kt")
public void testNoBridgeOnMutableCollectionInheritance() throws Exception {
runTest("compiler/testData/codegen/box/bridges/noBridgeOnMutableCollectionInheritance.kt");
@@ -1633,6 +1633,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest
runTest("compiler/testData/codegen/box/bridges/methodFromTrait.kt");
}
@Test
@TestMetadata("nestedClassTypeParameters.kt")
public void testNestedClassTypeParameters() throws Exception {
runTest("compiler/testData/codegen/box/bridges/nestedClassTypeParameters.kt");
}
@Test
@TestMetadata("noBridgeOnMutableCollectionInheritance.kt")
public void testNoBridgeOnMutableCollectionInheritance() throws Exception {