[JS IR] Fix clashes between bridge and delegated function call

The patch fixes the js function signature rules to avoid clashes
 between bridge and delegated call. Use overridden symbols dfs of
 JsName annotation in order to get the correct bridge name.

^KT-52968 Fixed
This commit is contained in:
Alexander Korepanov
2022-07-20 16:01:18 +02:00
committed by Space
parent 6525f7a7ac
commit caa1570e25
10 changed files with 345 additions and 3 deletions
@@ -146,8 +146,10 @@ abstract class BridgesConstruction<T : JsCommonBackendContext>(val context: T) :
copyReceiverParametersFrom(bridge, substitutionMap)
copyValueParametersFrom(bridge, substitutionMap)
annotations += bridge.annotations
overriddenSymbols += delegateTo.overriddenSymbols
// the js function signature building process (jsFunctionSignature()) uses dfs throught overriddenSymbols for getting js name,
// therefore it is very important to put bridge symbol at the beginning, it allows to get correct js function name
overriddenSymbols += bridge.symbol
overriddenSymbols += delegateTo.overriddenSymbols
}
irFunction.body = context.irFactory.createBlockBody(UNDEFINED_OFFSET, UNDEFINED_OFFSET) {
@@ -66,13 +66,25 @@ fun IrAnnotationContainer.isJsNativeInvoke(): Boolean = hasAnnotation(JsAnnotati
fun IrAnnotationContainer.isAnnotatedWithJsFun(): Boolean = hasAnnotation(JsAnnotations.jsFunFqn)
private fun IrOverridableDeclaration<*>.dfsOverridableJsNameOrNull(): String? {
for (overriddenSymbol in overriddenSymbols) {
val symbolOwner = overriddenSymbol.owner
if (symbolOwner is IrAnnotationContainer) {
symbolOwner.getJsName()?.let { return it }
}
if (symbolOwner is IrOverridableDeclaration<*>) {
symbolOwner.dfsOverridableJsNameOrNull()?.let { return it }
}
}
return null
}
fun IrDeclarationWithName.getJsNameForOverriddenDeclaration(): String? {
val jsName = getJsName()
return when {
jsName != null -> jsName
this is IrOverridableDeclaration<*> ->
overriddenSymbols.firstNotNullOfOrNull { (it.owner as? IrAnnotationContainer)?.getJsName() }
this is IrOverridableDeclaration<*> -> dfsOverridableJsNameOrNull()
else -> null
}
}