JVM_IR: remove a hack from InlineCallableReferenceToLambda
It breaks other things, the same problem is hit by FunctionReference, and it's the translation layer's fault anyway. #KT-46555 Fixed
This commit is contained in:
+12
@@ -3171,6 +3171,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/argumentTypes.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("argumentTypesNoinline.kt")
|
||||
public void testArgumentTypesNoinline() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/argumentTypesNoinline.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("booleanNotIntrinsic.kt")
|
||||
public void testBooleanNotIntrinsic() throws Exception {
|
||||
@@ -3237,6 +3243,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/constructorFromTopLevelOneStringArg.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("dispatchReceiverType.kt")
|
||||
public void testDispatchReceiverType() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/dispatchReceiverType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("enumValueOfMethod.kt")
|
||||
public void testEnumValueOfMethod() throws Exception {
|
||||
|
||||
+2
-11
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrFunctionReferenceImpl
|
||||
import org.jetbrains.kotlin.ir.types.IrSimpleType
|
||||
import org.jetbrains.kotlin.ir.types.IrTypeProjection
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
@@ -126,18 +127,8 @@ private class InlineCallableReferenceToLambdaTransformer(
|
||||
private fun expandInlineFunctionReferenceToLambda(expression: IrCallableReference<*>, referencedFunction: IrFunction): IrExpression {
|
||||
val irBuilder = context.createJvmIrBuilder(currentScope!!.scope.scopeOwnerSymbol, expression.startOffset, expression.endOffset)
|
||||
return irBuilder.irBlock(expression, IrStatementOrigin.LAMBDA) {
|
||||
// We find the number of parameters for constructed lambda from the type of the function reference,
|
||||
// but the actual types have to be copied from referencedFunction; function reference argument type may be too
|
||||
// specific because of approximation. See compiler/testData/codegen/box/callableReference/function/argumentTypes.kt
|
||||
val boundReceiver: Pair<IrValueParameter, IrExpression>? = expression.getArgumentsWithIr().singleOrNull()
|
||||
val nParams = (expression.type as IrSimpleType).arguments.size - 1
|
||||
val toDropAtStart = if (boundReceiver != null) 1 else 0
|
||||
val argumentTypes = referencedFunction.explicitParameters.drop(toDropAtStart).take(nParams).map { parameter ->
|
||||
parameter.type.substitute(
|
||||
referencedFunction.typeParameters,
|
||||
referencedFunction.typeParameters.indices.map { expression.getTypeArgument(it)!! }
|
||||
)
|
||||
}
|
||||
val argumentTypes = (expression.type as IrSimpleType).arguments.dropLast(1).map { (it as IrTypeProjection).type }
|
||||
|
||||
val function = context.irFactory.buildFun {
|
||||
setSourceRange(expression)
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// DONT_TARGET_EXACT_BACKEND: WASM
|
||||
// WASM_MUTE_REASON: CALLABLE_REFERENCES_FAIL
|
||||
inline fun <TT> id(x: TT): TT = x
|
||||
inline fun <TT> String.extId(x: TT): String = this
|
||||
fun <T> id(x: T): T = x
|
||||
fun <T> String.extId(x: T): T = x
|
||||
|
||||
private fun <T> ff(value: T?): String {
|
||||
// In PSI2IR, the funcref is approximated to Function1<Nothing, Pair<String, T>>
|
||||
value?.let(::id)
|
||||
return value?.let("OK"::extId)!!
|
||||
}
|
||||
|
||||
fun box() = ff("arg")
|
||||
fun <T> foo(value: T?): T? = value?.let(::id) // KFunction1<Nothing, T>
|
||||
fun <T> bar(value: T?): T? = value?.let(""::extId)
|
||||
|
||||
fun box() = foo("O")!! + foo("K")!!
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// DONT_TARGET_EXACT_BACKEND: WASM
|
||||
// WASM_MUTE_REASON: CALLABLE_REFERENCES_FAIL
|
||||
fun <T> id(x: T): T = x
|
||||
fun <T> String.extId(x: T): T = x
|
||||
|
||||
fun <T, R> T.myLet(block: (T) -> R): R = block(this)
|
||||
|
||||
fun <T> foo(value: T?): T? = value?.myLet(::id) // KFunction1<Nothing, T>
|
||||
fun <T> bar(value: T?): T? = value?.myLet(""::extId)
|
||||
|
||||
fun box() = foo("O")!! + foo("K")!!
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// MODULE: lib
|
||||
// FILE: X.java
|
||||
package test;
|
||||
|
||||
public class X extends PX {
|
||||
public X(String x) { super(x); }
|
||||
}
|
||||
|
||||
// FILE: PX.java
|
||||
package test;
|
||||
|
||||
class PX {
|
||||
private final String x;
|
||||
|
||||
PX(String x) { this.x = x; }
|
||||
|
||||
public String foo() { return x; }
|
||||
}
|
||||
|
||||
// MODULE: main(lib)
|
||||
// FILE: box.kt
|
||||
import test.X
|
||||
|
||||
fun <T, R> T.myLet(block: (T) -> R): R = block(this)
|
||||
|
||||
fun box() = X("O").let(X::foo) + X("K").myLet(X::foo)
|
||||
+12
@@ -3171,6 +3171,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/argumentTypes.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("argumentTypesNoinline.kt")
|
||||
public void testArgumentTypesNoinline() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/argumentTypesNoinline.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("booleanNotIntrinsic.kt")
|
||||
public void testBooleanNotIntrinsic() throws Exception {
|
||||
@@ -3237,6 +3243,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/constructorFromTopLevelOneStringArg.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("dispatchReceiverType.kt")
|
||||
public void testDispatchReceiverType() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/dispatchReceiverType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("enumValueOfMethod.kt")
|
||||
public void testEnumValueOfMethod() throws Exception {
|
||||
|
||||
+12
@@ -3171,6 +3171,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/argumentTypes.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("argumentTypesNoinline.kt")
|
||||
public void testArgumentTypesNoinline() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/argumentTypesNoinline.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("booleanNotIntrinsic.kt")
|
||||
public void testBooleanNotIntrinsic() throws Exception {
|
||||
@@ -3237,6 +3243,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/constructorFromTopLevelOneStringArg.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("dispatchReceiverType.kt")
|
||||
public void testDispatchReceiverType() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/dispatchReceiverType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("enumValueOfMethod.kt")
|
||||
public void testEnumValueOfMethod() throws Exception {
|
||||
|
||||
+10
@@ -2782,6 +2782,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/argumentTypes.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("argumentTypesNoinline.kt")
|
||||
public void testArgumentTypesNoinline() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/argumentTypesNoinline.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("booleanNotIntrinsic.kt")
|
||||
public void testBooleanNotIntrinsic() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/booleanNotIntrinsic.kt");
|
||||
@@ -2837,6 +2842,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/constructorFromTopLevelOneStringArg.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("dispatchReceiverType.kt")
|
||||
public void testDispatchReceiverType() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/dispatchReceiverType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("enumValueOfMethod.kt")
|
||||
public void testEnumValueOfMethod() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/enumValueOfMethod.kt");
|
||||
|
||||
js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java
Generated
+5
@@ -1982,6 +1982,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/argumentTypes.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("argumentTypesNoinline.kt")
|
||||
public void testArgumentTypesNoinline() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/argumentTypesNoinline.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("booleanNotIntrinsic.kt")
|
||||
public void testBooleanNotIntrinsic() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/booleanNotIntrinsic.kt");
|
||||
|
||||
Generated
+5
@@ -1982,6 +1982,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/argumentTypes.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("argumentTypesNoinline.kt")
|
||||
public void testArgumentTypesNoinline() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/argumentTypesNoinline.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("booleanNotIntrinsic.kt")
|
||||
public void testBooleanNotIntrinsic() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/booleanNotIntrinsic.kt");
|
||||
|
||||
Generated
+5
@@ -1982,6 +1982,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/argumentTypes.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("argumentTypesNoinline.kt")
|
||||
public void testArgumentTypesNoinline() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/argumentTypesNoinline.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("booleanNotIntrinsic.kt")
|
||||
public void testBooleanNotIntrinsic() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/booleanNotIntrinsic.kt");
|
||||
|
||||
Reference in New Issue
Block a user