[FIR2IR] Correctly calculate signature for non-dynamic calls on dynamic receiver
If dispatch receiver is dynamic and call on it is not dynamic that means that this call was resolved to some specific declaration because of smartcast. So we should use original type of this declaration as dispatch receiver during calculation of IdSignature instead of Any (which came from dynamic type). Otherwise we will have two different signatures for the same member declaration ^KT-57682 Fixed
This commit is contained in:
committed by
Space Team
parent
e3c7241abd
commit
d7d7620db2
@@ -229,7 +229,14 @@ private fun FirCallableSymbol<*>.toSymbolForCall(
|
||||
}
|
||||
// Member fake override or bound callable reference
|
||||
dispatchReceiver !is FirNoReceiverExpression -> {
|
||||
dispatchReceiver.typeRef.coneType.let { it.findClassRepresentation(it, declarationStorage.session) }
|
||||
val callSiteDispatchReceiverType = dispatchReceiver.typeRef.coneType
|
||||
val declarationSiteDispatchReceiverType = dispatchReceiverType
|
||||
val type = if (callSiteDispatchReceiverType is ConeDynamicType && declarationSiteDispatchReceiverType != null) {
|
||||
declarationSiteDispatchReceiverType
|
||||
} else {
|
||||
callSiteDispatchReceiverType
|
||||
}
|
||||
type.findClassRepresentation(type, declarationStorage.session)
|
||||
}
|
||||
// Unbound callable reference to member (non-extension)
|
||||
isReference && fir.receiverParameter == null -> {
|
||||
@@ -752,4 +759,4 @@ fun FirCallableDeclaration.contextReceiversForFunctionOrContainingProperty(): Li
|
||||
|
||||
fun IrActualizationResult?.extractFirDeclarations(): Set<FirDeclaration>? {
|
||||
return this?.actualizedExpectDeclarations?.mapNotNullTo(mutableSetOf()) { ((it as IrMetadataSourceOwner).metadata as FirMetadataSource).fir }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// ISSUE: KT-57682
|
||||
fun test_1(x: String) = x.length
|
||||
|
||||
fun test_2(x: dynamic): Int = when (x) {
|
||||
is String -> x.length
|
||||
else -> x.something
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val result = test_1("a") + test_2("ab")
|
||||
return if (result == 3) "OK" else "fail"
|
||||
}
|
||||
+6
@@ -35055,6 +35055,12 @@ public class FirJsCodegenBoxTestGenerated extends AbstractFirJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/smartCasts/smartCastInsideIf.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("smartcastOnDynamic.kt")
|
||||
public void testSmartcastOnDynamic() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/smartCasts/smartcastOnDynamic.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("whenSmartCast.kt")
|
||||
public void testWhenSmartCast() throws Exception {
|
||||
|
||||
+6
@@ -35055,6 +35055,12 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/smartCasts/smartCastInsideIf.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("smartcastOnDynamic.kt")
|
||||
public void testSmartcastOnDynamic() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/smartCasts/smartcastOnDynamic.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("whenSmartCast.kt")
|
||||
public void testWhenSmartCast() throws Exception {
|
||||
|
||||
+6
@@ -35055,6 +35055,12 @@ public class IrJsES6CodegenBoxTestGenerated extends AbstractIrJsES6CodegenBoxTes
|
||||
runTest("compiler/testData/codegen/box/smartCasts/smartCastInsideIf.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("smartcastOnDynamic.kt")
|
||||
public void testSmartcastOnDynamic() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/smartCasts/smartcastOnDynamic.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("whenSmartCast.kt")
|
||||
public void testWhenSmartCast() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user