diff --git a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java
index f007192b71b..6c4e8b43e6f 100644
--- a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java
+++ b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java
@@ -10028,6 +10028,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/delegatedProperty/extensionPropertyAndExtensionGetValue.kt");
}
+ @TestMetadata("functionRefDelefate.kt")
+ public void testFunctionRefDelefate() throws Exception {
+ runTest("compiler/testData/codegen/box/delegatedProperty/functionRefDelefate.kt");
+ }
+
@TestMetadata("genericDelegate.kt")
public void testGenericDelegate() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/genericDelegate.kt");
diff --git a/compiler/testData/codegen/box/delegatedProperty/functionRefDelefate.kt b/compiler/testData/codegen/box/delegatedProperty/functionRefDelefate.kt
new file mode 100644
index 00000000000..0a15e4ab21e
--- /dev/null
+++ b/compiler/testData/codegen/box/delegatedProperty/functionRefDelefate.kt
@@ -0,0 +1,28 @@
+// KT-40412
+
+// WITH_RUNTIME
+
+// MODULE: lib
+// FILE: lib.kt
+
+import kotlin.properties.ReadOnlyProperty
+import kotlin.reflect.KProperty
+
+var result = "FAIL"
+
+class CaptureContext(val capture: (A) -> Unit) : ReadOnlyProperty Unit> {
+ override fun getValue(thisRef: A, property: KProperty<*>) = { -> capture(thisRef) }
+}
+operator fun ((A) -> Unit).provideDelegate(thisRef: A, property: KProperty<*>) = CaptureContext(this)
+
+fun right(arg: Right) { result = "OK" }
+class Right { val prop: () -> Unit by ::right }
+
+// MODULE: main(lib)
+// FILE: main.kt
+
+fun box(): String {
+ val r = Right()
+ r.prop()
+ return result
+}
\ No newline at end of file
diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java
index 5f8fcb760a8..15da4f904f5 100644
--- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java
+++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java
@@ -11428,6 +11428,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/delegatedProperty/extensionPropertyAndExtensionGetValue.kt");
}
+ @TestMetadata("functionRefDelefate.kt")
+ public void testFunctionRefDelefate() throws Exception {
+ runTest("compiler/testData/codegen/box/delegatedProperty/functionRefDelefate.kt");
+ }
+
@TestMetadata("genericDelegate.kt")
public void testGenericDelegate() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/genericDelegate.kt");
diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java
index 1eda70c0aca..61e8d84ba9d 100644
--- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java
+++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java
@@ -11433,6 +11433,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/delegatedProperty/extensionPropertyAndExtensionGetValue.kt");
}
+ @TestMetadata("functionRefDelefate.kt")
+ public void testFunctionRefDelefate() throws Exception {
+ runTest("compiler/testData/codegen/box/delegatedProperty/functionRefDelefate.kt");
+ }
+
@TestMetadata("genericDelegate.kt")
public void testGenericDelegate() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/genericDelegate.kt");
diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java
index 75cf87608ae..eb0b9a52b57 100644
--- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java
+++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java
@@ -10028,6 +10028,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/delegatedProperty/extensionPropertyAndExtensionGetValue.kt");
}
+ @TestMetadata("functionRefDelefate.kt")
+ public void testFunctionRefDelefate() throws Exception {
+ runTest("compiler/testData/codegen/box/delegatedProperty/functionRefDelefate.kt");
+ }
+
@TestMetadata("genericDelegate.kt")
public void testGenericDelegate() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/genericDelegate.kt");
diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java
index 6742d4f2bb0..8a93f451b35 100644
--- a/js/js.tests/test/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java
+++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java
@@ -8543,6 +8543,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
runTest("compiler/testData/codegen/box/delegatedProperty/extensionPropertyAndExtensionGetValue.kt");
}
+ @TestMetadata("functionRefDelefate.kt")
+ public void testFunctionRefDelefate() throws Exception {
+ runTest("compiler/testData/codegen/box/delegatedProperty/functionRefDelefate.kt");
+ }
+
@TestMetadata("genericDelegate.kt")
public void testGenericDelegate() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/genericDelegate.kt");
diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java
index 153cee8285e..ba4dc21b9da 100644
--- a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java
+++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java
@@ -8543,6 +8543,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/delegatedProperty/extensionPropertyAndExtensionGetValue.kt");
}
+ @TestMetadata("functionRefDelefate.kt")
+ public void testFunctionRefDelefate() throws Exception {
+ runTest("compiler/testData/codegen/box/delegatedProperty/functionRefDelefate.kt");
+ }
+
@TestMetadata("genericDelegate.kt")
public void testGenericDelegate() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/genericDelegate.kt");
diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java
index 34454f1a4cb..b0ebe3915a4 100644
--- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java
+++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java
@@ -8543,6 +8543,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/delegatedProperty/extensionPropertyAndExtensionGetValue.kt");
}
+ @TestMetadata("functionRefDelefate.kt")
+ public void testFunctionRefDelefate() throws Exception {
+ runTest("compiler/testData/codegen/box/delegatedProperty/functionRefDelefate.kt");
+ }
+
@TestMetadata("genericDelegate.kt")
public void testGenericDelegate() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/genericDelegate.kt");