[Wasm] Fix overloading virtual methods by vararg and array element type

Context:
- Kotlin allows functions overloaded with different array element types.
- Varargs are lowered to Array parameters.
- Before this commit, K/Wasm erased an array element type
  from the signature, similar to type argument erasure in other cases.

Fix:
Stop erasing type arguments in arrays when computing v-table signatures.

^KT-58852 Fixed
This commit is contained in:
Svyatoslav Kuzmich
2023-12-12 15:13:41 +01:00
committed by Space Team
parent b5def88ff4
commit 76e132e758
2 changed files with 55 additions and 0 deletions
@@ -54,10 +54,30 @@ private fun IrType.toWasmSignatureType(irBuiltIns: IrBuiltIns): IrType =
}
private fun IrSimpleType.toWasmSignatureSimpleType(irBuiltIns: IrBuiltIns): IrSimpleType {
// Special case: Kotlin allows overloading functions based on Array type arguments
if (this.classifier == irBuiltIns.arrayClass) {
return irBuiltIns.arrayClass.createType(
hasQuestionMark = isNullable(),
arguments = arguments.map { it.toWasmSignatureTypeArgument(irBuiltIns) }
)
}
val klass = (this.erasedUpperBound?.symbol ?: irBuiltIns.anyClass).owner
return klass.defaultType.withNullability(this.isNullable())
}
private fun IrTypeArgument.toWasmSignatureTypeArgument(irBuiltIns: IrBuiltIns): IrTypeArgument {
return when (this) {
is IrStarProjection -> this
is IrTypeProjection -> {
when (val type = type) {
is IrSimpleType -> type.toWasmSignatureSimpleType(irBuiltIns)
else -> this
}
}
}
}
class VirtualMethodMetadata(
val function: IrSimpleFunction,
val signature: WasmSignature