[Wasm] Fix generic call return type for functions with default parameters
This commit is contained in:
committed by
Space Team
parent
b8f797af00
commit
44190937b0
+6
@@ -4829,6 +4829,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr
|
||||
runTest("compiler/testData/codegen/box/casts/dontCreateInconsistentTypeDuringStarProjectionSubstitution.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("genericReturnCast.kt")
|
||||
public void testGenericReturnCast() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/casts/genericReturnCast.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("intersectionTypeMultipleBounds.kt")
|
||||
public void testIntersectionTypeMultipleBounds() throws Exception {
|
||||
|
||||
+6
@@ -4829,6 +4829,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo
|
||||
runTest("compiler/testData/codegen/box/casts/dontCreateInconsistentTypeDuringStarProjectionSubstitution.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("genericReturnCast.kt")
|
||||
public void testGenericReturnCast() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/casts/genericReturnCast.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("intersectionTypeMultipleBounds.kt")
|
||||
public void testIntersectionTypeMultipleBounds() throws Exception {
|
||||
|
||||
+13
-4
@@ -270,7 +270,7 @@ open class DefaultParameterInjector(
|
||||
return (0 until functionAccess.valueArgumentsCount).count { functionAccess.getValueArgument(it) != null } != functionAccess.symbol.owner.valueParameters.size
|
||||
}
|
||||
|
||||
private fun <T : IrFunctionAccessExpression> visitFunctionAccessExpression(expression: T, builder: (IrFunctionSymbol) -> T): T {
|
||||
private fun <T : IrFunctionAccessExpression> visitFunctionAccessExpression(expression: T, builder: (IrFunctionSymbol) -> T): IrExpression {
|
||||
if (!shouldReplaceWithSyntheticFunction(expression))
|
||||
return expression
|
||||
|
||||
@@ -282,7 +282,7 @@ open class DefaultParameterInjector(
|
||||
|
||||
val isStatic = isStatic(expression.symbol.owner)
|
||||
|
||||
return builder(symbol).apply {
|
||||
val newCall = builder(symbol).apply {
|
||||
copyTypeArgumentsFrom(expression)
|
||||
|
||||
var receivers = 0
|
||||
@@ -307,6 +307,15 @@ open class DefaultParameterInjector(
|
||||
log { "call::extension@: ${ir2string(expression.extensionReceiver)}" }
|
||||
log { "call::dispatch@: ${ir2string(expression.dispatchReceiver)}" }
|
||||
}
|
||||
|
||||
return newCall.takeIf { it.type == expression.type } ?: IrTypeOperatorCallImpl(
|
||||
startOffset = newCall.startOffset,
|
||||
endOffset = newCall.endOffset,
|
||||
type = expression.type,
|
||||
operator = IrTypeOperator.IMPLICIT_CAST,
|
||||
typeOperand = expression.type,
|
||||
argument = newCall
|
||||
)
|
||||
}
|
||||
|
||||
override fun visitDelegatingConstructorCall(expression: IrDelegatingConstructorCall): IrExpression {
|
||||
@@ -352,8 +361,8 @@ open class DefaultParameterInjector(
|
||||
|
||||
override fun visitCall(expression: IrCall): IrExpression {
|
||||
expression.transformChildrenVoid()
|
||||
return visitFunctionAccessExpression(expression) {
|
||||
with(expression) {
|
||||
with(expression) {
|
||||
return visitFunctionAccessExpression(expression) {
|
||||
IrCallImpl(
|
||||
startOffset, endOffset, (it as IrSimpleFunctionSymbol).owner.returnType, it,
|
||||
typeArgumentsCount = typeArgumentsCount,
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
fun <T : Any?> someFunc(a: T, arg: T? = null): T = arg ?: a
|
||||
|
||||
fun box(): String {
|
||||
var key: String? = null
|
||||
key = someFunc("a")
|
||||
if (key != "a") return "FAIL1"
|
||||
key = someFunc("a", "b")
|
||||
if (key != "b") return "FAIL2"
|
||||
|
||||
var key1: Int? = null
|
||||
key1 = someFunc(42)
|
||||
if (key1 != 42) return "FAIL3"
|
||||
key1 = someFunc(42, 24)
|
||||
if (key1 != 24) return "FAIL3"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+6
@@ -4667,6 +4667,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/casts/dontCreateInconsistentTypeDuringStarProjectionSubstitution.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("genericReturnCast.kt")
|
||||
public void testGenericReturnCast() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/casts/genericReturnCast.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("intersectionTypeMultipleBounds.kt")
|
||||
public void testIntersectionTypeMultipleBounds() throws Exception {
|
||||
|
||||
+6
@@ -4829,6 +4829,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/casts/dontCreateInconsistentTypeDuringStarProjectionSubstitution.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("genericReturnCast.kt")
|
||||
public void testGenericReturnCast() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/casts/genericReturnCast.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("intersectionTypeMultipleBounds.kt")
|
||||
public void testIntersectionTypeMultipleBounds() throws Exception {
|
||||
|
||||
+6
@@ -4829,6 +4829,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack
|
||||
runTest("compiler/testData/codegen/box/casts/dontCreateInconsistentTypeDuringStarProjectionSubstitution.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("genericReturnCast.kt")
|
||||
public void testGenericReturnCast() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/casts/genericReturnCast.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("intersectionTypeMultipleBounds.kt")
|
||||
public void testIntersectionTypeMultipleBounds() throws Exception {
|
||||
|
||||
+5
@@ -4071,6 +4071,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/casts/dontCreateInconsistentTypeDuringStarProjectionSubstitution.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("genericReturnCast.kt")
|
||||
public void testGenericReturnCast() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/casts/genericReturnCast.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("intersectionTypeMultipleBounds.kt")
|
||||
public void testIntersectionTypeMultipleBounds() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/casts/intersectionTypeMultipleBounds.kt");
|
||||
|
||||
+6
@@ -3389,6 +3389,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/casts/dontCreateInconsistentTypeDuringStarProjectionSubstitution.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("genericReturnCast.kt")
|
||||
public void testGenericReturnCast() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/casts/genericReturnCast.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("intersectionTypeMultipleBounds.kt")
|
||||
public void testIntersectionTypeMultipleBounds() throws Exception {
|
||||
|
||||
+6
@@ -3443,6 +3443,12 @@ public class FirJsCodegenBoxTestGenerated extends AbstractFirJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/casts/dontCreateInconsistentTypeDuringStarProjectionSubstitution.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("genericReturnCast.kt")
|
||||
public void testGenericReturnCast() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/casts/genericReturnCast.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("intersectionTypeMultipleBounds.kt")
|
||||
public void testIntersectionTypeMultipleBounds() throws Exception {
|
||||
|
||||
+6
@@ -3443,6 +3443,12 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/casts/dontCreateInconsistentTypeDuringStarProjectionSubstitution.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("genericReturnCast.kt")
|
||||
public void testGenericReturnCast() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/casts/genericReturnCast.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("intersectionTypeMultipleBounds.kt")
|
||||
public void testIntersectionTypeMultipleBounds() throws Exception {
|
||||
|
||||
+6
@@ -3443,6 +3443,12 @@ public class IrJsES6CodegenBoxTestGenerated extends AbstractIrJsES6CodegenBoxTes
|
||||
runTest("compiler/testData/codegen/box/casts/dontCreateInconsistentTypeDuringStarProjectionSubstitution.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("genericReturnCast.kt")
|
||||
public void testGenericReturnCast() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/casts/genericReturnCast.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("intersectionTypeMultipleBounds.kt")
|
||||
public void testIntersectionTypeMultipleBounds() throws Exception {
|
||||
|
||||
+6
@@ -3594,6 +3594,12 @@ public class FirNativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTe
|
||||
runTest("compiler/testData/codegen/box/casts/dontCreateInconsistentTypeDuringStarProjectionSubstitution.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("genericReturnCast.kt")
|
||||
public void testGenericReturnCast() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/casts/genericReturnCast.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("intersectionTypeMultipleBounds.kt")
|
||||
public void testIntersectionTypeMultipleBounds() throws Exception {
|
||||
|
||||
+6
@@ -3555,6 +3555,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest
|
||||
runTest("compiler/testData/codegen/box/casts/dontCreateInconsistentTypeDuringStarProjectionSubstitution.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("genericReturnCast.kt")
|
||||
public void testGenericReturnCast() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/casts/genericReturnCast.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("intersectionTypeMultipleBounds.kt")
|
||||
public void testIntersectionTypeMultipleBounds() throws Exception {
|
||||
|
||||
Generated
+5
@@ -3036,6 +3036,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
|
||||
runTest("compiler/testData/codegen/box/casts/dontCreateInconsistentTypeDuringStarProjectionSubstitution.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("genericReturnCast.kt")
|
||||
public void testGenericReturnCast() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/casts/genericReturnCast.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("intersectionTypeMultipleBounds.kt")
|
||||
public void testIntersectionTypeMultipleBounds() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/casts/intersectionTypeMultipleBounds.kt");
|
||||
|
||||
Reference in New Issue
Block a user