diff --git a/compiler/backend-common/src/org/jetbrains/kotlin/backend/common/CodegenUtil.kt b/compiler/backend-common/src/org/jetbrains/kotlin/backend/common/CodegenUtil.kt index 2e31900053b..f443441b892 100644 --- a/compiler/backend-common/src/org/jetbrains/kotlin/backend/common/CodegenUtil.kt +++ b/compiler/backend-common/src/org/jetbrains/kotlin/backend/common/CodegenUtil.kt @@ -93,20 +93,18 @@ object CodegenUtil { private fun mapMembers( inherited: CallableMemberDescriptor, traitMember: CallableMemberDescriptor - ): LinkedHashMap { - val result = linkedMapOf() - if (traitMember is SimpleFunctionDescriptor) { - result[traitMember] = inherited as FunctionDescriptor - } else if (traitMember is PropertyDescriptor) { + ): Map = when (traitMember) { + is SimpleFunctionDescriptor -> mapOf(traitMember to inherited as FunctionDescriptor) + is PropertyDescriptor -> linkedMapOf().also { result -> for (traitAccessor in traitMember.accessors) { for (inheritedAccessor in (inherited as PropertyDescriptor).accessors) { - if (inheritedAccessor::class.java == traitAccessor::class.java) { // same accessor kind - result.put(traitAccessor, inheritedAccessor) + if ((inheritedAccessor is PropertyGetterDescriptor) == (traitAccessor is PropertyGetterDescriptor)) { + result[traitAccessor] = inheritedAccessor } } } } - return result + else -> error("Unexpected member: $inherited") } @JvmStatic diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ClassBodyCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ClassBodyCodegen.java index 4a8a3448c11..2d4b6348253 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ClassBodyCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ClassBodyCodegen.java @@ -14,6 +14,7 @@ import org.jetbrains.kotlin.backend.common.bridges.ImplKt; import org.jetbrains.kotlin.builtins.KotlinBuiltIns; import org.jetbrains.kotlin.codegen.context.ClassContext; import org.jetbrains.kotlin.codegen.state.GenerationState; +import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper; import org.jetbrains.kotlin.descriptors.*; import org.jetbrains.kotlin.psi.*; import org.jetbrains.kotlin.psi.synthetics.SyntheticClassOrObjectDescriptor; @@ -219,21 +220,32 @@ public abstract class ClassBodyCodegen extends MemberCodegen entry : CodegenUtil.getNonPrivateTraitMethods(descriptor).entrySet()) { - FunctionDescriptor interfaceFun = entry.getKey(); - //skip java 8 default methods - if (!CodegenUtilKt.isDefinitelyNotDefaultImplsMethod(interfaceFun) && - !JvmAnnotationUtilKt.isCallableMemberCompiledToJvmDefault( - DescriptorUtils.unwrapFakeOverrideToAnyDeclaration(interfaceFun), state.getJvmDefaultMode() - ) - ) { - generateDelegationToDefaultImpl(interfaceFun, entry.getValue()); - } + generateDelegationToDefaultImpl(entry.getKey(), entry.getValue(), receiverType, functionCodegen, state, isErasedInlineClass); } } - private void generateDelegationToDefaultImpl(@NotNull FunctionDescriptor interfaceFun, @NotNull FunctionDescriptor inheritedFun) { + public static void generateDelegationToDefaultImpl( + @NotNull FunctionDescriptor interfaceFun, + @NotNull FunctionDescriptor inheritedFun, + @NotNull JvmKotlinType receiverType, + @NotNull FunctionCodegen functionCodegen, + @NotNull GenerationState state, + boolean isErasedInlineClass + ) { + // Skip Java 8 default methods + if (CodegenUtilKt.isDefinitelyNotDefaultImplsMethod(interfaceFun) || + JvmAnnotationUtilKt.isCallableMemberCompiledToJvmDefault( + DescriptorUtils.unwrapFakeOverrideToAnyDeclaration(interfaceFun), state.getJvmDefaultMode() + ) + ) { + return; + } + KotlinTypeMapper typeMapper = state.getTypeMapper(); functionCodegen.generateMethod( new JvmDeclarationOrigin( CLASS_MEMBER_DELEGATION_TO_DEFAULT_IMPL, descriptorToDeclaration(interfaceFun), interfaceFun, null @@ -248,7 +260,7 @@ public abstract class ClassBodyCodegen extends MemberCodegen { generateBridges(); generateClosureBody(); + if (samType != null) { + ClassDescriptor funInterface = samType.getClassDescriptor(); + if (!(funInterface instanceof JavaClassDescriptor)) { + SamWrapperCodegen.generateDelegatesToDefaultImpl(asmType, classDescriptor, funInterface, functionCodegen, state); + } + } + this.constructor = generateConstructor(); if (isConst(closure)) { diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java index 4c03ea700e2..e77a4781077 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java @@ -70,7 +70,6 @@ import java.io.StringWriter; import java.util.*; import java.util.stream.Collectors; -import static org.jetbrains.kotlin.builtins.KotlinBuiltIns.isNullableAny; import static org.jetbrains.kotlin.codegen.AsmUtil.*; import static org.jetbrains.kotlin.codegen.CodegenUtilKt.generateBridgeForMainFunctionIfNecessary; import static org.jetbrains.kotlin.codegen.serialization.JvmSerializationBindings.METHOD_FOR_FUNCTION; @@ -1064,18 +1063,6 @@ public class FunctionCodegen { ); } - public static boolean isMethodOfAny(@NotNull FunctionDescriptor descriptor) { - String name = descriptor.getName().asString(); - List parameters = descriptor.getValueParameters(); - if (parameters.isEmpty()) { - return name.equals("hashCode") || name.equals("toString"); - } - else if (parameters.size() == 1 && name.equals("equals")) { - return isNullableAny(parameters.get(0).getType()); - } - return false; - } - @NotNull public static String[] getThrownExceptions(@NotNull FunctionDescriptor function, @NotNull KotlinTypeMapper typeMapper) { return ArrayUtil.toStringArray(CollectionsKt.map( diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/SamWrapperCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/SamWrapperCodegen.java index cc377096cfb..29b070a5094 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/SamWrapperCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/SamWrapperCodegen.java @@ -19,6 +19,7 @@ package org.jetbrains.kotlin.codegen; import kotlin.text.StringsKt; import org.jetbrains.annotations.NotNull; import org.jetbrains.kotlin.backend.common.CodegenUtil; +import org.jetbrains.kotlin.codegen.context.ClassContext; import org.jetbrains.kotlin.codegen.state.GenerationState; import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper; import org.jetbrains.kotlin.descriptors.*; @@ -32,6 +33,7 @@ import org.jetbrains.kotlin.psi.KtFile; import org.jetbrains.kotlin.resolve.DescriptorUtils; import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin; import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOriginKt; +import org.jetbrains.kotlin.resolve.scopes.MemberScope; import org.jetbrains.kotlin.storage.LockBasedStorageManager; import org.jetbrains.kotlin.types.KotlinType; import org.jetbrains.kotlin.util.OperatorNameConventions; @@ -42,6 +44,7 @@ import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter; import org.jetbrains.org.objectweb.asm.commons.Method; import java.util.Collections; +import java.util.Map; import static org.jetbrains.kotlin.codegen.AsmUtil.*; import static org.jetbrains.kotlin.resolve.jvm.AsmTypes.*; @@ -87,7 +90,7 @@ public class SamWrapperCodegen { boolean isKotlinFunInterface = !(samType.getClassDescriptor() instanceof JavaClassDescriptor); - ClassDescriptor classDescriptor = new ClassDescriptorImpl( + ClassDescriptorImpl classDescriptor = new ClassDescriptorImpl( samType.getClassDescriptor().getContainingDeclaration(), fqName.shortName(), Modality.FINAL, @@ -97,6 +100,8 @@ public class SamWrapperCodegen { /* isExternal = */ false, LockBasedStorageManager.NO_LOCKS ); + classDescriptor.initialize(MemberScope.Empty.INSTANCE, Collections.emptySet(), null); + // e.g. compare(T, T) SimpleFunctionDescriptor erasedInterfaceFunction = samType.getOriginalAbstractMethod().copy( classDescriptor, @@ -135,12 +140,17 @@ public class SamWrapperCodegen { null); generateConstructor(asmType, functionAsmType, cv); - generateMethod(asmType, functionAsmType, cv, erasedInterfaceFunction, functionType); + + ClassContext context = state.getRootContext().intoClass(classDescriptor, OwnerKind.IMPLEMENTATION, state); + FunctionCodegen functionCodegen = new FunctionCodegen(context, cv, state, parentCodegen); + generateMethod(asmType, functionAsmType, erasedInterfaceFunction, functionType, functionCodegen); if (isKotlinFunInterface) { generateGetFunctionDelegate(cv, asmType, functionAsmType); generateEquals(cv, asmType, functionAsmType, samAsmType); generateHashCode(cv, asmType, functionAsmType); + + generateDelegatesToDefaultImpl(asmType, classDescriptor, samType.getClassDescriptor(), functionCodegen, state); } cv.done(); @@ -171,25 +181,22 @@ public class SamWrapperCodegen { } private void generateMethod( - Type ownerType, - Type functionType, - ClassBuilder cv, - SimpleFunctionDescriptor erasedInterfaceFunction, - KotlinType functionJetType + @NotNull Type ownerType, + @NotNull Type functionType, + @NotNull SimpleFunctionDescriptor erasedInterfaceFunction, + @NotNull KotlinType functionKotlinType, + @NotNull FunctionCodegen functionCodegen ) { - // using root context to avoid creating ClassDescriptor and everything else - FunctionCodegen codegen = new FunctionCodegen(state.getRootContext().intoClass( - (ClassDescriptor) erasedInterfaceFunction.getContainingDeclaration(), OwnerKind.IMPLEMENTATION, state), cv, state, parentCodegen); - - FunctionDescriptor invokeFunction = - functionJetType.getMemberScope().getContributedFunctions(OperatorNameConventions.INVOKE, NoLookupLocation.FROM_BACKEND).iterator().next().getOriginal(); + FunctionDescriptor invokeFunction = functionKotlinType.getMemberScope().getContributedFunctions( + OperatorNameConventions.INVOKE, NoLookupLocation.FROM_BACKEND + ).iterator().next().getOriginal(); StackValue functionField = StackValue.field(functionType, ownerType, FUNCTION_FIELD_NAME, false, StackValue.none()); - codegen.genSamDelegate(erasedInterfaceFunction, invokeFunction, functionField); + functionCodegen.genSamDelegate(erasedInterfaceFunction, invokeFunction, functionField); // generate sam bridges // TODO: erasedInterfaceFunction is actually not an interface function, but function in generated class SimpleFunctionDescriptor originalInterfaceErased = samType.getOriginalAbstractMethod(); - ClosureCodegen.generateBridgesForSAM(originalInterfaceErased, erasedInterfaceFunction, codegen); + ClosureCodegen.generateBridgesForSAM(originalInterfaceErased, erasedInterfaceFunction, functionCodegen); } private static void generateEquals( @@ -248,6 +255,31 @@ public class SamWrapperCodegen { FunctionCodegen.endVisit(iv, "getFunctionDelegate of SAM wrapper"); } + public static void generateDelegatesToDefaultImpl( + @NotNull Type asmType, + @NotNull ClassDescriptor classDescriptor, + @NotNull ClassDescriptor funInterface, + @NotNull FunctionCodegen functionCodegen, + @NotNull GenerationState state + ) { + JvmKotlinType receiverType = new JvmKotlinType(asmType, classDescriptor.getDefaultType()); + + for (DeclarationDescriptor descriptor : DescriptorUtils.getAllDescriptors(funInterface.getDefaultType().getMemberScope())) { + if (!(descriptor instanceof CallableMemberDescriptor)) continue; + CallableMemberDescriptor member = (CallableMemberDescriptor) descriptor; + if (member.getModality() == Modality.ABSTRACT || + Visibilities.isPrivate(member.getVisibility()) || + member.getVisibility() == Visibilities.INVISIBLE_FAKE || + DescriptorUtils.isMethodOfAny(member)) continue; + + for (Map.Entry entry : CodegenUtil.INSTANCE.copyFunctions( + member, member, classDescriptor, Modality.OPEN, Visibilities.PUBLIC, CallableMemberDescriptor.Kind.DECLARATION, false + ).entrySet()) { + ClassBodyCodegen.generateDelegationToDefaultImpl(entry.getKey(), entry.getValue(), receiverType, functionCodegen, state, false); + } + } + } + @NotNull private FqName getWrapperName( @NotNull KtFile containingFile, 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 ee0c85d3df4..1c7fb8e817a 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 @@ -11244,6 +11244,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/funInterface/multimodule.kt"); } + @TestMetadata("nonAbstractMethod.kt") + public void testNonAbstractMethod() throws Exception { + runTest("compiler/testData/codegen/box/funInterface/nonAbstractMethod.kt"); + } + @TestMetadata("nullableSam.kt") public void testNullableSam() throws Exception { runTest("compiler/testData/codegen/box/funInterface/nullableSam.kt"); @@ -15419,6 +15424,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/defaultArgsViaAnonymousObject.kt"); } + @TestMetadata("funInterface.kt") + public void testFunInterface() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/funInterface.kt"); + } + @TestMetadata("inheritedFunctionWithDefaultParameters.kt") public void testInheritedFunctionWithDefaultParameters() throws Exception { runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/inheritedFunctionWithDefaultParameters.kt"); @@ -15676,6 +15686,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/defaultArgsViaAnonymousObject.kt"); } + @TestMetadata("funInterface.kt") + public void testFunInterface() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/funInterface.kt"); + } + @TestMetadata("inheritedFunctionWithDefaultParameters.kt") public void testInheritedFunctionWithDefaultParameters() throws Exception { runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/inheritedFunctionWithDefaultParameters.kt"); diff --git a/compiler/testData/codegen/box/funInterface/funInterfaceInheritance.kt b/compiler/testData/codegen/box/funInterface/funInterfaceInheritance.kt index 5c10295a7a9..007b92fa13b 100644 --- a/compiler/testData/codegen/box/funInterface/funInterfaceInheritance.kt +++ b/compiler/testData/codegen/box/funInterface/funInterfaceInheritance.kt @@ -1,6 +1,5 @@ // !LANGUAGE: +NewInference +FunctionalInterfaceConversion +SamConversionPerArgument +SamConversionForKotlinFunctions - -// IGNORE_BACKEND: JVM, JVM_IR +// IGNORE_BACKEND: JVM_IR // IGNORE_BACKEND_FIR: JVM_IR // SKIP_DCE_DRIVEN @@ -30,4 +29,4 @@ fun box(): String { if (runProxy { 10 } != "10") return "fail2" return runBase { "OK" } -} \ No newline at end of file +} diff --git a/compiler/testData/codegen/box/funInterface/nonAbstractMethod.kt b/compiler/testData/codegen/box/funInterface/nonAbstractMethod.kt new file mode 100644 index 00000000000..f5a4b5fe509 --- /dev/null +++ b/compiler/testData/codegen/box/funInterface/nonAbstractMethod.kt @@ -0,0 +1,23 @@ +// IGNORE_BACKEND: JVM_IR, JS_IR +// IGNORE_BACKEND_FIR: JVM_IR + +interface I { + fun inherited(s: String): String = privateInherited(s) + + private fun privateInherited(s: String): String = s +} + +fun interface F : I { + fun invoke(o: String): String + + fun result(): String = inherited(privateFun("O")) + + private fun privateFun(s: String): String = invoke(s) +} + +fun box(): String { + if (F { o -> o + "K" }.result() != "OK") return "Fail" + + val lambda: (String) -> String = { o -> o + "K" } + return F(lambda).result() +} diff --git a/compiler/testData/codegen/box/jvm8/defaults/allCompatibility/funInterface.kt b/compiler/testData/codegen/box/jvm8/defaults/allCompatibility/funInterface.kt new file mode 100644 index 00000000000..07ab0d8e77c --- /dev/null +++ b/compiler/testData/codegen/box/jvm8/defaults/allCompatibility/funInterface.kt @@ -0,0 +1,24 @@ +// !JVM_DEFAULT_MODE: all-compatibility +// TARGET_BACKEND: JVM +// IGNORE_BACKEND_FIR: JVM_IR +// JVM_TARGET: 1.8 +// WITH_RUNTIME + +interface Base { + fun f(o: String): String = g(o) + + private fun g(o: String): String = o +} + +fun interface F : Base { + fun invoke(o: String): String + + fun result(): String = invoke(f("O")) +} + +fun box(): String { + if (F { o -> o + "K" }.result() != "OK") return "Fail" + + val lambda: (String) -> String = { o -> o + "K" } + return F(lambda).result() +} diff --git a/compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/funInterface.kt b/compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/funInterface.kt new file mode 100644 index 00000000000..1f4bb55a435 --- /dev/null +++ b/compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/funInterface.kt @@ -0,0 +1,24 @@ +// !JVM_DEFAULT_MODE: all +// TARGET_BACKEND: JVM +// IGNORE_BACKEND_FIR: JVM_IR +// JVM_TARGET: 1.8 +// WITH_RUNTIME + +interface Base { + fun f(o: String): String = g(o) + + private fun g(o: String): String = o +} + +fun interface F : Base { + fun invoke(o: String): String + + fun result(): String = invoke(f("O")) +} + +fun box(): String { + if (F { o -> o + "K" }.result() != "OK") return "Fail" + + val lambda: (String) -> String = { o -> o + "K" } + return F(lambda).result() +} diff --git a/compiler/testData/codegen/box/jvm8/javaDefaults/samOnInterfaceWithDefaultMethod.kt b/compiler/testData/codegen/box/jvm8/javaDefaults/samOnInterfaceWithDefaultMethod.kt index 81e39577a10..a69fb2b71df 100644 --- a/compiler/testData/codegen/box/jvm8/javaDefaults/samOnInterfaceWithDefaultMethod.kt +++ b/compiler/testData/codegen/box/jvm8/javaDefaults/samOnInterfaceWithDefaultMethod.kt @@ -26,5 +26,8 @@ interface Test { // FILE: sam.kt fun box(): String { + val lambda = { "X" } + if (JavaCall().call(lambda) != "X") return "Fail" + return JavaCall().call {"OK"} } diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index ccdc1b48b36..fc83a43b3a3 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -12464,6 +12464,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/funInterface/multimodule.kt"); } + @TestMetadata("nonAbstractMethod.kt") + public void testNonAbstractMethod() throws Exception { + runTest("compiler/testData/codegen/box/funInterface/nonAbstractMethod.kt"); + } + @TestMetadata("nullableSam.kt") public void testNullableSam() throws Exception { runTest("compiler/testData/codegen/box/funInterface/nullableSam.kt"); @@ -16639,6 +16644,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/defaultArgsViaAnonymousObject.kt"); } + @TestMetadata("funInterface.kt") + public void testFunInterface() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/funInterface.kt"); + } + @TestMetadata("inheritedFunctionWithDefaultParameters.kt") public void testInheritedFunctionWithDefaultParameters() throws Exception { runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/inheritedFunctionWithDefaultParameters.kt"); @@ -16896,6 +16906,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/defaultArgsViaAnonymousObject.kt"); } + @TestMetadata("funInterface.kt") + public void testFunInterface() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/funInterface.kt"); + } + @TestMetadata("inheritedFunctionWithDefaultParameters.kt") public void testInheritedFunctionWithDefaultParameters() throws Exception { runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/inheritedFunctionWithDefaultParameters.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 754e86d6149..85feffb2300 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -12411,11 +12411,6 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) public static class FunInterface extends AbstractLightAnalysisModeTest { - @TestMetadata("funInterfaceInheritance.kt") - public void ignoreFunInterfaceInheritance() throws Exception { - runTest("compiler/testData/codegen/box/funInterface/funInterfaceInheritance.kt"); - } - private void runTest(String testDataFilePath) throws Exception { KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath); } @@ -12444,6 +12439,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/funInterface/funConversionInVararg.kt"); } + @TestMetadata("funInterfaceInheritance.kt") + public void testFunInterfaceInheritance() throws Exception { + runTest("compiler/testData/codegen/box/funInterface/funInterfaceInheritance.kt"); + } + @TestMetadata("funInterfaceWithReceiver.kt") public void testFunInterfaceWithReceiver() throws Exception { runTest("compiler/testData/codegen/box/funInterface/funInterfaceWithReceiver.kt"); @@ -12464,6 +12464,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/funInterface/multimodule.kt"); } + @TestMetadata("nonAbstractMethod.kt") + public void testNonAbstractMethod() throws Exception { + runTest("compiler/testData/codegen/box/funInterface/nonAbstractMethod.kt"); + } + @TestMetadata("nullableSam.kt") public void testNullableSam() throws Exception { runTest("compiler/testData/codegen/box/funInterface/nullableSam.kt"); @@ -16639,6 +16644,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/defaultArgsViaAnonymousObject.kt"); } + @TestMetadata("funInterface.kt") + public void testFunInterface() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/funInterface.kt"); + } + @TestMetadata("inheritedFunctionWithDefaultParameters.kt") public void testInheritedFunctionWithDefaultParameters() throws Exception { runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/inheritedFunctionWithDefaultParameters.kt"); @@ -16896,6 +16906,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/defaultArgsViaAnonymousObject.kt"); } + @TestMetadata("funInterface.kt") + public void testFunInterface() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/funInterface.kt"); + } + @TestMetadata("inheritedFunctionWithDefaultParameters.kt") public void testInheritedFunctionWithDefaultParameters() throws Exception { runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/inheritedFunctionWithDefaultParameters.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index e59d046fd31..9bb0893599a 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -11244,6 +11244,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/funInterface/multimodule.kt"); } + @TestMetadata("nonAbstractMethod.kt") + public void testNonAbstractMethod() throws Exception { + runTest("compiler/testData/codegen/box/funInterface/nonAbstractMethod.kt"); + } + @TestMetadata("nullableSam.kt") public void testNullableSam() throws Exception { runTest("compiler/testData/codegen/box/funInterface/nullableSam.kt"); @@ -15419,6 +15424,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/defaultArgsViaAnonymousObject.kt"); } + @TestMetadata("funInterface.kt") + public void testFunInterface() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/funInterface.kt"); + } + @TestMetadata("inheritedFunctionWithDefaultParameters.kt") public void testInheritedFunctionWithDefaultParameters() throws Exception { runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/inheritedFunctionWithDefaultParameters.kt"); @@ -15676,6 +15686,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/defaultArgsViaAnonymousObject.kt"); } + @TestMetadata("funInterface.kt") + public void testFunInterface() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/funInterface.kt"); + } + @TestMetadata("inheritedFunctionWithDefaultParameters.kt") public void testInheritedFunctionWithDefaultParameters() throws Exception { runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/inheritedFunctionWithDefaultParameters.kt"); diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/DescriptorUtils.java b/core/descriptors/src/org/jetbrains/kotlin/resolve/DescriptorUtils.java index 38e82368bc9..65323929482 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/DescriptorUtils.java +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/DescriptorUtils.java @@ -5,8 +5,6 @@ package org.jetbrains.kotlin.resolve; -import kotlin.collections.CollectionsKt; -import kotlin.jvm.functions.Function1; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.builtins.KotlinBuiltIns; @@ -631,7 +629,9 @@ public class DescriptorUtils { : descriptor; } - public static boolean isMethodOfAny(@NotNull FunctionDescriptor descriptor) { + public static boolean isMethodOfAny(@NotNull CallableMemberDescriptor descriptor) { + if (!(descriptor instanceof FunctionDescriptor)) return false; + String name = descriptor.getName().asString(); List parameters = descriptor.getValueParameters(); if (parameters.isEmpty()) { 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 a3531190153..2d565099ccc 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 @@ -9654,6 +9654,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/funInterface/multimodule.kt"); } + @TestMetadata("nonAbstractMethod.kt") + public void testNonAbstractMethod() throws Exception { + runTest("compiler/testData/codegen/box/funInterface/nonAbstractMethod.kt"); + } + @TestMetadata("nullableSam.kt") public void testNullableSam() throws Exception { runTest("compiler/testData/codegen/box/funInterface/nullableSam.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 9a4fee7d6b4..d9487b4fa4f 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 @@ -9654,6 +9654,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/funInterface/multimodule.kt"); } + @TestMetadata("nonAbstractMethod.kt") + public void testNonAbstractMethod() throws Exception { + runTest("compiler/testData/codegen/box/funInterface/nonAbstractMethod.kt"); + } + @TestMetadata("nullableSam.kt") public void testNullableSam() throws Exception { runTest("compiler/testData/codegen/box/funInterface/nullableSam.kt");