Substitute type arguments to return type of inlined function references
Such substitution is crucial on codegen stage if the return type is reified (e.g. for `Array`) ^KT-59507: Fixed ^KT-59281: Fixed
This commit is contained in:
committed by
Space Team
parent
f5a00c788a
commit
e5763a692f
+6
@@ -3087,6 +3087,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr
|
||||
runTest("compiler/testData/codegen/box/callableReference/arrayOf.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("arrayOfNulls.kt")
|
||||
public void testArrayOfNulls() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/arrayOfNulls.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("builtinFunctionReferenceOwner.kt")
|
||||
public void testBuiltinFunctionReferenceOwner() throws Exception {
|
||||
|
||||
+6
@@ -3087,6 +3087,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo
|
||||
runTest("compiler/testData/codegen/box/callableReference/arrayOf.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("arrayOfNulls.kt")
|
||||
public void testArrayOfNulls() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/arrayOfNulls.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("builtinFunctionReferenceOwner.kt")
|
||||
public void testBuiltinFunctionReferenceOwner() throws Exception {
|
||||
|
||||
+10
-3
@@ -6,7 +6,10 @@
|
||||
package org.jetbrains.kotlin.backend.common.lower.inline
|
||||
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.*
|
||||
import org.jetbrains.kotlin.backend.common.BodyLoweringPass
|
||||
import org.jetbrains.kotlin.backend.common.CommonBackendContext
|
||||
import org.jetbrains.kotlin.backend.common.IrElementTransformerVoidWithContext
|
||||
import org.jetbrains.kotlin.backend.common.ScopeWithIr
|
||||
import org.jetbrains.kotlin.backend.common.ir.Symbols
|
||||
import org.jetbrains.kotlin.backend.common.ir.isPure
|
||||
import org.jetbrains.kotlin.backend.common.lower.InnerClassesSupport
|
||||
@@ -403,13 +406,17 @@ class FunctionInlining(
|
||||
typeParam.symbol to superType.arguments[typeParam.index].typeOrNull!!
|
||||
}
|
||||
|
||||
require(superType.arguments.isNotEmpty()) { "type should have at least one type argument: ${superType.render()}" }
|
||||
// This expression equals to return type of function reference with substituted type arguments
|
||||
val functionReferenceReturnType = superType.arguments.last().typeOrFail
|
||||
|
||||
val immediateCall = when (inlinedFunction) {
|
||||
is IrConstructor -> {
|
||||
val classTypeParametersCount = inlinedFunction.parentAsClass.typeParameters.size
|
||||
IrConstructorCallImpl.fromSymbolOwner(
|
||||
if (inlineArgumentsWithTheirOriginalTypeAndOffset) irFunctionReference.startOffset else irCall.startOffset,
|
||||
if (inlineArgumentsWithTheirOriginalTypeAndOffset) irFunctionReference.endOffset else irCall.endOffset,
|
||||
inlinedFunction.returnType,
|
||||
functionReferenceReturnType,
|
||||
inlinedFunction.symbol,
|
||||
classTypeParametersCount,
|
||||
INLINED_FUNCTION_REFERENCE
|
||||
@@ -419,7 +426,7 @@ class FunctionInlining(
|
||||
IrCallImpl(
|
||||
if (inlineArgumentsWithTheirOriginalTypeAndOffset) irFunctionReference.startOffset else irCall.startOffset,
|
||||
if (inlineArgumentsWithTheirOriginalTypeAndOffset) irFunctionReference.endOffset else irCall.endOffset,
|
||||
inlinedFunction.returnType,
|
||||
functionReferenceReturnType,
|
||||
inlinedFunction.symbol,
|
||||
inlinedFunction.typeParameters.size,
|
||||
inlinedFunction.valueParameters.size,
|
||||
|
||||
@@ -111,6 +111,12 @@ val IrType.classFqName: FqName?
|
||||
|
||||
val IrTypeArgument.typeOrNull: IrType? get() = (this as? IrTypeProjection)?.type
|
||||
|
||||
val IrTypeArgument.typeOrFail: IrType
|
||||
get() {
|
||||
require(this is IrTypeProjection) { "Type argument should be of type `IrTypeProjection`, but was `${this::class}` instead" }
|
||||
return this.type
|
||||
}
|
||||
|
||||
fun IrType.makeNotNull() = withNullability(false)
|
||||
|
||||
fun IrType.makeNullable() = withNullability(true)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_INLINER: IR
|
||||
// WITH_STDLIB
|
||||
|
||||
fun g(b: (Int, (Int) -> String) -> Array<String>): Array<String> =
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// WITH_STDLIB
|
||||
|
||||
// KT-59544
|
||||
// SKIP_SOURCEMAP_REMAPPING
|
||||
|
||||
inline fun h(b: (Int) -> Array<String?>) = b(1).size
|
||||
|
||||
fun box(): String = ('N' + h(::arrayOfNulls)) + "K"
|
||||
+6
@@ -2931,6 +2931,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/callableReference/arrayOf.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("arrayOfNulls.kt")
|
||||
public void testArrayOfNulls() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/arrayOfNulls.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("builtinFunctionReferenceOwner.kt")
|
||||
public void testBuiltinFunctionReferenceOwner() throws Exception {
|
||||
|
||||
+6
@@ -3087,6 +3087,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/callableReference/arrayOf.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("arrayOfNulls.kt")
|
||||
public void testArrayOfNulls() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/arrayOfNulls.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("builtinFunctionReferenceOwner.kt")
|
||||
public void testBuiltinFunctionReferenceOwner() throws Exception {
|
||||
|
||||
+6
@@ -3087,6 +3087,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack
|
||||
runTest("compiler/testData/codegen/box/callableReference/arrayOf.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("arrayOfNulls.kt")
|
||||
public void testArrayOfNulls() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/arrayOfNulls.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("builtinFunctionReferenceOwner.kt")
|
||||
public void testBuiltinFunctionReferenceOwner() throws Exception {
|
||||
|
||||
+5
@@ -2708,6 +2708,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/callableReference/arrayOf.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("arrayOfNulls.kt")
|
||||
public void testArrayOfNulls() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/arrayOfNulls.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("builtinFunctionReferenceOwner.kt")
|
||||
public void testBuiltinFunctionReferenceOwner() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/builtinFunctionReferenceOwner.kt");
|
||||
|
||||
+6
@@ -1929,6 +1929,12 @@ public class FirJsCodegenBoxTestGenerated extends AbstractFirJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/callableReference/arrayOf.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("arrayOfNulls.kt")
|
||||
public void testArrayOfNulls() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/arrayOfNulls.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("callableReferenceOfCompanionConst.kt")
|
||||
public void testCallableReferenceOfCompanionConst() throws Exception {
|
||||
|
||||
+6
@@ -1929,6 +1929,12 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/callableReference/arrayOf.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("arrayOfNulls.kt")
|
||||
public void testArrayOfNulls() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/arrayOfNulls.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("callableReferenceOfCompanionConst.kt")
|
||||
public void testCallableReferenceOfCompanionConst() throws Exception {
|
||||
|
||||
+6
@@ -1929,6 +1929,12 @@ public class IrJsES6CodegenBoxTestGenerated extends AbstractIrJsES6CodegenBoxTes
|
||||
runTest("compiler/testData/codegen/box/callableReference/arrayOf.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("arrayOfNulls.kt")
|
||||
public void testArrayOfNulls() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/arrayOfNulls.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("callableReferenceOfCompanionConst.kt")
|
||||
public void testCallableReferenceOfCompanionConst() throws Exception {
|
||||
|
||||
+6
@@ -1973,6 +1973,12 @@ public class FirNativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTe
|
||||
runTest("compiler/testData/codegen/box/callableReference/arrayOf.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("arrayOfNulls.kt")
|
||||
public void testArrayOfNulls() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/arrayOfNulls.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("callableReferenceOfCompanionConst.kt")
|
||||
public void testCallableReferenceOfCompanionConst() throws Exception {
|
||||
|
||||
+6
@@ -2029,6 +2029,12 @@ public class FirNativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenB
|
||||
runTest("compiler/testData/codegen/box/callableReference/arrayOf.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("arrayOfNulls.kt")
|
||||
public void testArrayOfNulls() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/arrayOfNulls.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("callableReferenceOfCompanionConst.kt")
|
||||
public void testCallableReferenceOfCompanionConst() throws Exception {
|
||||
|
||||
+6
@@ -1946,6 +1946,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest
|
||||
runTest("compiler/testData/codegen/box/callableReference/arrayOf.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("arrayOfNulls.kt")
|
||||
public void testArrayOfNulls() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/arrayOfNulls.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("callableReferenceOfCompanionConst.kt")
|
||||
public void testCallableReferenceOfCompanionConst() throws Exception {
|
||||
|
||||
+6
@@ -1974,6 +1974,12 @@ public class NativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenBoxT
|
||||
runTest("compiler/testData/codegen/box/callableReference/arrayOf.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("arrayOfNulls.kt")
|
||||
public void testArrayOfNulls() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/arrayOfNulls.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("callableReferenceOfCompanionConst.kt")
|
||||
public void testCallableReferenceOfCompanionConst() throws Exception {
|
||||
|
||||
Generated
+6
@@ -1917,6 +1917,12 @@ public class FirWasmCodegenBoxTestGenerated extends AbstractFirWasmCodegenBoxTes
|
||||
runTest("compiler/testData/codegen/box/callableReference/arrayOf.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("arrayOfNulls.kt")
|
||||
public void testArrayOfNulls() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/arrayOfNulls.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("callableReferenceOfCompanionConst.kt")
|
||||
public void testCallableReferenceOfCompanionConst() throws Exception {
|
||||
|
||||
Generated
+6
@@ -1917,6 +1917,12 @@ public class K1WasmCodegenBoxTestGenerated extends AbstractK1WasmCodegenBoxTest
|
||||
runTest("compiler/testData/codegen/box/callableReference/arrayOf.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("arrayOfNulls.kt")
|
||||
public void testArrayOfNulls() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/arrayOfNulls.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("callableReferenceOfCompanionConst.kt")
|
||||
public void testCallableReferenceOfCompanionConst() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user