diff --git a/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/FunctionReferenceLowering.kt b/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/FunctionReferenceLowering.kt index 38fbb61d30d..c9e094c20e3 100644 --- a/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/FunctionReferenceLowering.kt +++ b/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/FunctionReferenceLowering.kt @@ -789,7 +789,7 @@ internal class FunctionReferenceLowering(private val context: JvmBackendContext) call.putValueArgument(index++, irString("")) // signature: "" call.putValueArgument(index++, irString("")) - // flags: 8 = 4 << 1 + // flags: 8 = 3 << 1 call.putValueArgument(index, irInt(8)) } else if (!isLambda && useOptimizedSuperClass) { val callableReferenceTarget = adaptedReferenceOriginalTarget ?: callee diff --git a/compiler/testData/codegen/box/callableReference/funInterfaceConstructor/funInterfaceConstructedObjectsEquality.kt b/compiler/testData/codegen/box/callableReference/funInterfaceConstructor/funInterfaceConstructedObjectsEquality.kt index 6cbce70d949..2f41e40ff81 100644 --- a/compiler/testData/codegen/box/callableReference/funInterfaceConstructor/funInterfaceConstructedObjectsEquality.kt +++ b/compiler/testData/codegen/box/callableReference/funInterfaceConstructor/funInterfaceConstructedObjectsEquality.kt @@ -17,13 +17,39 @@ val ks1: (() -> String) -> KSupplier = val ks11Foo = ks1(::foo) val ks21Foo = ks2(::foo) +fun interface KStringSupplier { + fun get(): String +} + +val kss: (() -> String) -> KStringSupplier = + ::KStringSupplier + +val ks11Bar = ks1(::bar) + +val kssFoo = kss(::foo) + +fun checkEqual(message: String, a1: Any, a2: Any) { + if (a1 != a2) { + throw Exception("$message: equals: $a1 != $a2") + } + if (a1.hashCode() != a2.hashCode()) { + throw Exception("$message: hashCode: ${a1.hashCode()} != ${a2.hashCode()}") + } +} + +fun checkNotEqual(message: String, a1: Any, a2: Any) { + if (a1 == a2) { + throw Exception("$message: equals: $a1 == $a2") + } +} + fun box(): String { - if (ks11Foo != ks12Foo) - return "failed: ks11Foo != ks12Foo (same ctor, different source files)" - if (ks11Foo != ks21Foo) - return "failed: ks11Foo != ks21Foo (different ctors, same source file)" - if (ks11Foo != ks22Foo) - return "failed: ks11Foo != ks22Foo (different ctors, different source files)" + checkEqual("ks11Foo == ks12Foo (same ctor, different source files)", ks11Foo, ks12Foo) + checkEqual("ks11Foo == ks21Foo (different ctors, same source file)", ks11Foo, ks21Foo) + checkEqual("ks11Foo == ks22Foo (different ctors, different source files)", ks11Foo, ks22Foo) + + checkNotEqual("ks11Foo != ks11Bar (different funs)", ks11Foo, ks11Bar) + checkNotEqual("ks11Foo != kssFoo (different fun interfaces)", ks11Foo, kssFoo) return "OK" } @@ -36,8 +62,10 @@ fun interface KSupplier { fun foo() = "abc" +fun bar() = "def" + val ks2: (() -> String) -> KSupplier = ::KSupplier val ks12Foo = ks1(::foo) -val ks22Foo = ks2(::foo) +val ks22Foo = ks2(::foo) \ No newline at end of file diff --git a/compiler/testData/codegen/box/callableReference/funInterfaceConstructor/funInterfaceConstructorEquality.kt b/compiler/testData/codegen/box/callableReference/funInterfaceConstructor/funInterfaceConstructorEquality.kt index d23c19b5210..39071f2e06a 100644 --- a/compiler/testData/codegen/box/callableReference/funInterfaceConstructor/funInterfaceConstructorEquality.kt +++ b/compiler/testData/codegen/box/callableReference/funInterfaceConstructor/funInterfaceConstructorEquality.kt @@ -20,13 +20,34 @@ val ks2: (() -> String) -> KSupplier = val kn1: (() -> Number) -> KSupplier = ::KSupplier + +fun interface KRunnable { + fun run() +} + + +fun checkEqual(message: String, a1: Any, a2: Any) { + if (a1 != a2) { + throw Exception("$message: equals: $a1 != $a2") + } + if (a1.hashCode() != a2.hashCode()) { + throw Exception("$message: hashCode: ${a1.hashCode()} != ${a2.hashCode()}") + } +} + +fun checkNotEqual(message: String, a1: Any, a2: Any) { + if (a1 == a2) { + throw Exception("$message: equals: $a1 == $a2") + } +} + fun box(): String { - if (ks1 != ks2) - return "Failed: ks1 != ks2 (same file, same SAM type)" - if (ks1 != ks3) - return "Failed: ks1 != ks3 (different file, same SAM type)" - if (ks1 != kn1) - return "Failed: ks1 != kn1 (same file, same SAM interface, different type arguments)" + checkEqual("ks1 == ks2 (same file, same SAM type)", ks1, ks2) + checkEqual("ks1 == ks3 (different file, same SAM type)", ks1, ks3) + checkEqual("ks1 == kn1 (same file, same SAM interface, different type arguments)", ks1, kn1) + + val kr: (() -> Unit) -> KRunnable = ::KRunnable + checkNotEqual("ks1 != kr (different fun interfaces)", ks1, kr) return "OK" } diff --git a/libraries/stdlib/jvm/runtime/kotlin/jvm/internal/FunctionReference.java b/libraries/stdlib/jvm/runtime/kotlin/jvm/internal/FunctionReference.java index 4d0d1b12c82..0c58b40f2d6 100644 --- a/libraries/stdlib/jvm/runtime/kotlin/jvm/internal/FunctionReference.java +++ b/libraries/stdlib/jvm/runtime/kotlin/jvm/internal/FunctionReference.java @@ -31,7 +31,7 @@ public class FunctionReference extends CallableReference implements FunctionBase * fun useSuspend(f: suspend () -> Unit) {} * useSuspend(::target) * - *
    4 - whether it is a synthetic fun interface constructor, i.e.,
    +     *     
      3 - whether it is a synthetic fun interface constructor, i.e.,
            *         fun interface KRunnable {
            *             fun run()
            *         }