[FIR2IR] Properly handle callable references to static functions

This commit is contained in:
Dmitriy Novozhilov
2021-03-25 11:38:28 +03:00
parent 37db27da58
commit 38ab37d7eb
4 changed files with 25 additions and 1 deletions
@@ -292,7 +292,7 @@ internal class AdapterGenerator(
boundDispatchReceiver != null -> irCall.dispatchReceiver = receiverValue
boundExtensionReceiver != null -> irCall.extensionReceiver = receiverValue
}
} else if (callableReferenceAccess.explicitReceiver is FirResolvedQualifier) {
} else if (callableReferenceAccess.explicitReceiver is FirResolvedQualifier && ((firAdaptee as? FirMemberDeclaration)?.isStatic != true)) {
// Unbound callable reference 'A::foo'
val adaptedReceiverParameter = adapterFunction.valueParameters[0]
val adaptedReceiverValue = IrGetValueImpl(
@@ -15098,6 +15098,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/fir"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@Test
@TestMetadata("callableReferenceToStaticFunction.kt")
public void testCallableReferenceToStaticFunction() throws Exception {
runTest("compiler/testData/codegen/box/fir/callableReferenceToStaticFunction.kt");
}
@Test
@TestMetadata("ClassBuilder.kt")
public void testClassBuilder() throws Exception {
@@ -0,0 +1,12 @@
// TARGET_BACKEND: JVM_IR
// FULL_JDK
// WITH_STDLIB
import java.nio.file.Files
import java.nio.file.Path
fun test(path: Path): Path? {
return path.takeIf(Files::exists)
}
fun box() = "OK"
@@ -15098,6 +15098,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/fir"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@Test
@TestMetadata("callableReferenceToStaticFunction.kt")
public void testCallableReferenceToStaticFunction() throws Exception {
runTest("compiler/testData/codegen/box/fir/callableReferenceToStaticFunction.kt");
}
@Test
@TestMetadata("ClassBuilder.kt")
public void testClassBuilder() throws Exception {