From 43a83dd07aec59492d579783d1d284f876d15ffd Mon Sep 17 00:00:00 2001 From: Victor Petukhov Date: Wed, 29 Sep 2021 19:13:03 +0300 Subject: [PATCH] Don't add LHS type constraint for callable references too early, before the resolution The constraint depends on a resolution candidate, because it can be Java static or companion object's member (don't need add constraint in this case) ^KT-41978 Fixed --- .../FirBlackBoxCodegenTestGenerated.java | 54 +++++++++++++++++ .../DiagnosticReporterByTrackingStrategy.kt | 1 - .../components/CallableReferenceResolution.kt | 36 ++++++++++++ .../components/PostponeArgumentsChecks.kt | 29 ---------- .../model/ConstraintPositionAndErrorsImpl.kt | 5 -- .../callableReferenceOfCompanionConst.kt | 29 ++++++++++ .../callableReferenceOfCompanionMethod.kt | 37 ++++++++++++ .../callableReferenceOfCompanionProperty.kt | 28 +++++++++ .../callableReferenceOfJavaNestedClass.kt | 32 ++++++++++ .../callableReferenceOfKotlinNestedClass.kt | 29 ++++++++++ .../callableReferenceOfNestedClass.kt | 32 ++++++++++ .../callableReferenceOfObjectMethod.kt | 58 +++++++++++++++++++ .../callableReferenceOfStaticField.kt | 31 ++++++++++ .../callableReferenceOfStaticMethod.kt | 38 ++++++++++++ .../diagnostics/tests/inference/kt39220.kt | 20 +++---- .../codegen/BlackBoxCodegenTestGenerated.java | 54 +++++++++++++++++ .../IrBlackBoxCodegenTestGenerated.java | 54 +++++++++++++++++ .../LightAnalysisModeTestGenerated.java | 45 ++++++++++++++ .../IrJsCodegenBoxES6TestGenerated.java | 25 ++++++++ .../IrJsCodegenBoxTestGenerated.java | 25 ++++++++ .../semantics/JsCodegenBoxTestGenerated.java | 25 ++++++++ 21 files changed, 642 insertions(+), 45 deletions(-) create mode 100644 compiler/testData/codegen/box/callableReference/callableReferenceOfCompanionConst.kt create mode 100644 compiler/testData/codegen/box/callableReference/callableReferenceOfCompanionMethod.kt create mode 100644 compiler/testData/codegen/box/callableReference/callableReferenceOfCompanionProperty.kt create mode 100644 compiler/testData/codegen/box/callableReference/callableReferenceOfJavaNestedClass.kt create mode 100644 compiler/testData/codegen/box/callableReference/callableReferenceOfKotlinNestedClass.kt create mode 100644 compiler/testData/codegen/box/callableReference/callableReferenceOfNestedClass.kt create mode 100644 compiler/testData/codegen/box/callableReference/callableReferenceOfObjectMethod.kt create mode 100644 compiler/testData/codegen/box/callableReference/callableReferenceOfStaticField.kt create mode 100644 compiler/testData/codegen/box/callableReference/callableReferenceOfStaticMethod.kt diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java index 18729aedee5..4374bc62075 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java @@ -2752,6 +2752,60 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/callableReference/builtinFunctionReferenceOwner.kt"); } + @Test + @TestMetadata("callableReferenceOfCompanionConst.kt") + public void testCallableReferenceOfCompanionConst() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/callableReferenceOfCompanionConst.kt"); + } + + @Test + @TestMetadata("callableReferenceOfCompanionMethod.kt") + public void testCallableReferenceOfCompanionMethod() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/callableReferenceOfCompanionMethod.kt"); + } + + @Test + @TestMetadata("callableReferenceOfCompanionProperty.kt") + public void testCallableReferenceOfCompanionProperty() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/callableReferenceOfCompanionProperty.kt"); + } + + @Test + @TestMetadata("callableReferenceOfJavaNestedClass.kt") + public void testCallableReferenceOfJavaNestedClass() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/callableReferenceOfJavaNestedClass.kt"); + } + + @Test + @TestMetadata("callableReferenceOfKotlinNestedClass.kt") + public void testCallableReferenceOfKotlinNestedClass() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/callableReferenceOfKotlinNestedClass.kt"); + } + + @Test + @TestMetadata("callableReferenceOfNestedClass.kt") + public void testCallableReferenceOfNestedClass() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/callableReferenceOfNestedClass.kt"); + } + + @Test + @TestMetadata("callableReferenceOfObjectMethod.kt") + public void testCallableReferenceOfObjectMethod() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/callableReferenceOfObjectMethod.kt"); + } + + @Test + @TestMetadata("callableReferenceOfStaticField.kt") + public void testCallableReferenceOfStaticField() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/callableReferenceOfStaticField.kt"); + } + + @Test + @TestMetadata("callableReferenceOfStaticMethod.kt") + public void testCallableReferenceOfStaticMethod() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/callableReferenceOfStaticMethod.kt"); + } + @Test @TestMetadata("charArrayOf.kt") public void testCharArrayOf() throws Exception { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt index 9efaebd50b3..61a8d814efd 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt @@ -379,7 +379,6 @@ class DiagnosticReporterByTrackingStrategy( when (position) { is ArgumentConstraintPositionImpl -> position.argument is ReceiverConstraintPositionImpl -> position.argument - is LHSArgumentConstraintPositionImpl -> position.argument is LambdaArgumentConstraintPositionImpl -> position.lambda.atom else -> null } diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolution.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolution.kt index 0f52fd73bb3..9e06107d7fa 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolution.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolution.kt @@ -7,16 +7,20 @@ package org.jetbrains.kotlin.resolve.calls.components import org.jetbrains.kotlin.builtins.* import org.jetbrains.kotlin.descriptors.* +import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.calls.components.candidate.CallableReferenceResolutionCandidate import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemOperation import org.jetbrains.kotlin.resolve.calls.inference.components.FreshVariableNewTypeSubstitutor import org.jetbrains.kotlin.resolve.calls.inference.model.* import org.jetbrains.kotlin.resolve.calls.model.* import org.jetbrains.kotlin.resolve.calls.tower.* +import org.jetbrains.kotlin.resolve.descriptorUtil.isCompanionObject import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValueWithSmartCastInfo import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.checker.captureFromExpression import org.jetbrains.kotlin.types.expressions.CoercionStrategy +import org.jetbrains.kotlin.types.model.TypeVariance +import org.jetbrains.kotlin.types.model.convertVariance import org.jetbrains.kotlin.types.typeUtil.immediateSupertypes import org.jetbrains.kotlin.types.typeUtil.supertypes @@ -78,11 +82,21 @@ fun CallableReferenceResolutionCandidate.addConstraints( substitutor: FreshVariableNewTypeSubstitutor, callableReference: CallableReferenceResolutionAtom ) { + val lhsResult = callableReference.lhsResult val position = when (callableReference) { is CallableReferenceKotlinCallArgument -> ArgumentConstraintPositionImpl(callableReference) is CallableReferenceKotlinCall -> CallableReferenceConstraintPositionImpl(callableReference) } + if (lhsResult is LHSResult.Type && expectedType != null && !TypeUtils.noExpectedType(expectedType)) { + // NB: regular objects have lhsResult of `LHSResult.Object` type and won't be proceeded here + val isStaticOrCompanionMember = + DescriptorUtils.isStaticDeclaration(candidate) || candidate.containingDeclaration.isCompanionObject() + if (!isStaticOrCompanionMember) { + constraintSystem.addLhsTypeConstraint(lhsResult.unboundDetailedReceiver.stableType, expectedType, position) + } + } + if (!ErrorUtils.isError(candidate)) { constraintSystem.addReceiverConstraint(substitutor, dispatchReceiver, candidate.dispatchReceiverParameter, position) constraintSystem.addReceiverConstraint(substitutor, extensionReceiver, candidate.extensionReceiverParameter, position) @@ -93,6 +107,28 @@ fun CallableReferenceResolutionCandidate.addConstraints( } } +private fun ConstraintSystemOperation.addLhsTypeConstraint( + lhsType: KotlinType, + expectedType: UnwrappedType, + position: ConstraintPosition +) { + if (!ReflectionTypes.isNumberedTypeWithOneOrMoreNumber(expectedType)) return + + val expectedTypeProjectionForLHS = expectedType.arguments.first() + val expectedTypeForLHS = expectedTypeProjectionForLHS.type + val expectedTypeVariance = expectedTypeProjectionForLHS.projectionKind.convertVariance() + val effectiveVariance = AbstractTypeChecker.effectiveVariance( + expectedType.constructor.parameters.first().variance.convertVariance(), + expectedTypeVariance + ) ?: expectedTypeVariance + + when (effectiveVariance) { + TypeVariance.INV -> addEqualityConstraint(lhsType, expectedTypeForLHS, position) + TypeVariance.IN -> addSubtypeConstraint(expectedTypeForLHS, lhsType, position) + TypeVariance.OUT -> addSubtypeConstraint(lhsType, expectedTypeForLHS, position) + } +} + private fun ConstraintSystemOperation.addReceiverConstraint( toFreshSubstitutor: FreshVariableNewTypeSubstitutor, receiverArgument: CallableReceiver?, diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/PostponeArgumentsChecks.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/PostponeArgumentsChecks.kt index 14454833350..c7cb6feb495 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/PostponeArgumentsChecks.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/PostponeArgumentsChecks.kt @@ -250,11 +250,6 @@ private fun preprocessCallableReference( if (expectedType == null) return result - val lhsResult = argument.lhsResult - if (lhsResult is LHSResult.Type) { - csBuilder.addConstraintFromLHS(argument, lhsResult, expectedType) - } - val notCallableTypeConstructor = csBuilder.getProperSuperTypeConstructors(expectedType) .firstOrNull { !ReflectionTypes.isPossibleExpectedCallableType(it.requireIs()) } @@ -271,30 +266,6 @@ private fun preprocessCallableReference( return result } -private fun ConstraintSystemBuilder.addConstraintFromLHS( - argument: CallableReferenceKotlinCallArgument, - lhsResult: LHSResult.Type, - expectedType: UnwrappedType -) { - if (!ReflectionTypes.isNumberedTypeWithOneOrMoreNumber(expectedType)) return - - val lhsType = lhsResult.unboundDetailedReceiver.stableType - val expectedTypeProjectionForLHS = expectedType.arguments.first() - val expectedTypeForLHS = expectedTypeProjectionForLHS.type - val constraintPosition = LHSArgumentConstraintPositionImpl(argument, lhsResult.qualifier ?: lhsResult.unboundDetailedReceiver) - val expectedTypeVariance = expectedTypeProjectionForLHS.projectionKind.convertVariance() - val effectiveVariance = AbstractTypeChecker.effectiveVariance( - expectedType.constructor.parameters.first().variance.convertVariance(), - expectedTypeVariance - ) ?: expectedTypeVariance - - when (effectiveVariance) { - TypeVariance.INV -> addEqualityConstraint(lhsType, expectedTypeForLHS, constraintPosition) - TypeVariance.IN -> addSubtypeConstraint(expectedTypeForLHS, lhsType, constraintPosition) - TypeVariance.OUT -> addSubtypeConstraint(lhsType, expectedTypeForLHS, constraintPosition) - } -} - private fun preprocessCollectionLiteralArgument( collectionLiteralArgument: CollectionLiteralKotlinCallArgument, expectedType: UnwrappedType? diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/ConstraintPositionAndErrorsImpl.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/ConstraintPositionAndErrorsImpl.kt index a9ce78602fa..8cb7b3ea56c 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/ConstraintPositionAndErrorsImpl.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/ConstraintPositionAndErrorsImpl.kt @@ -46,11 +46,6 @@ class FixVariableConstraintPositionImpl( class KnownTypeParameterConstraintPositionImpl(typeArgument: KotlinType) : KnownTypeParameterConstraintPosition(typeArgument) -class LHSArgumentConstraintPositionImpl( - argument: CallableReferenceKotlinCallArgument, - receiver: DetailedReceiver -) : LHSArgumentConstraintPosition(argument, receiver) - class LambdaArgumentConstraintPositionImpl(lambda: ResolvedLambdaAtom) : LambdaArgumentConstraintPosition(lambda) class DelegatedPropertyConstraintPositionImpl(topLevelCall: KotlinCall) : DelegatedPropertyConstraintPosition(topLevelCall) diff --git a/compiler/testData/codegen/box/callableReference/callableReferenceOfCompanionConst.kt b/compiler/testData/codegen/box/callableReference/callableReferenceOfCompanionConst.kt new file mode 100644 index 00000000000..52dd600974e --- /dev/null +++ b/compiler/testData/codegen/box/callableReference/callableReferenceOfCompanionConst.kt @@ -0,0 +1,29 @@ +// DONT_TARGET_EXACT_BACKEND: WASM + +import kotlin.reflect.KProperty0 + +class Sample { + companion object { + const val maxValue = 1 + } +} + +abstract class Checker { + fun check(): String { + return run( + Sample::maxValue, + { x -> x == 1 } + ) + } + abstract fun run(method: KProperty0, fn: (T1) -> Boolean): String +} + +fun box(): String { + var result = ( object : Checker() { + override fun run(method: KProperty0, fn: (T1) -> Boolean): String { + return "OK" + } + } ).check() + + return result +} diff --git a/compiler/testData/codegen/box/callableReference/callableReferenceOfCompanionMethod.kt b/compiler/testData/codegen/box/callableReference/callableReferenceOfCompanionMethod.kt new file mode 100644 index 00000000000..157419517f4 --- /dev/null +++ b/compiler/testData/codegen/box/callableReference/callableReferenceOfCompanionMethod.kt @@ -0,0 +1,37 @@ +// DONT_TARGET_EXACT_BACKEND: WASM +// WITH_RUNTIME + +// FILE: main.kt +import kotlin.reflect.KFunction2 + +class Sample { + companion object { + fun max(x: Int, y: Int): Int { + return if (x > y) { + x + } else { + y + } + } + } +} + +abstract class Checker { + fun check(): String { + return run( + Sample::max, + { x, y -> x > y } + ) + } + abstract fun run(method: KFunction2, fn: (T1, T2) -> Boolean): String +} + +fun box(): String { + var result = ( object : Checker() { + override fun run(method: KFunction2, fn: (T1, T2) -> Boolean): String { + return "OK" + } + } ).check() + + return result +} diff --git a/compiler/testData/codegen/box/callableReference/callableReferenceOfCompanionProperty.kt b/compiler/testData/codegen/box/callableReference/callableReferenceOfCompanionProperty.kt new file mode 100644 index 00000000000..36529b56d0c --- /dev/null +++ b/compiler/testData/codegen/box/callableReference/callableReferenceOfCompanionProperty.kt @@ -0,0 +1,28 @@ +// DONT_TARGET_EXACT_BACKEND: WASM +import kotlin.reflect.KProperty0 + +class Sample { + companion object { + val maxValue = 1 + } +} + +abstract class Checker { + fun check(): String { + return run( + Sample::maxValue, + { x -> x == 1 } + ) + } + abstract fun run(method: KProperty0, fn: (T1) -> Boolean): String +} + +fun box(): String { + var result = ( object : Checker() { + override fun run(method: KProperty0, fn: (T1) -> Boolean): String { + return "OK" + } + } ).check() + + return result +} diff --git a/compiler/testData/codegen/box/callableReference/callableReferenceOfJavaNestedClass.kt b/compiler/testData/codegen/box/callableReference/callableReferenceOfJavaNestedClass.kt new file mode 100644 index 00000000000..be042aafa09 --- /dev/null +++ b/compiler/testData/codegen/box/callableReference/callableReferenceOfJavaNestedClass.kt @@ -0,0 +1,32 @@ +// DONT_TARGET_EXACT_BACKEND: WASM +// TARGET_BACKEND: JVM +// WITH_RUNTIME + +// FILE: Sample.java +public class Sample { + static class SS {} +} + + +// FILE: main.kt +import kotlin.reflect.KFunction0 + +abstract class Checker { + fun check(): String { + return run( + Sample::SS, + { x -> x == Any() } + ) + } + abstract fun run(method: KFunction0, fn: (T1) -> Boolean): String +} + +fun box(): String { + var result = ( object : Checker() { + override fun run(method: KFunction0, fn: (T1) -> Boolean): String { + return "OK" + } + } ).check() + + return result +} diff --git a/compiler/testData/codegen/box/callableReference/callableReferenceOfKotlinNestedClass.kt b/compiler/testData/codegen/box/callableReference/callableReferenceOfKotlinNestedClass.kt new file mode 100644 index 00000000000..ad9c390d3ab --- /dev/null +++ b/compiler/testData/codegen/box/callableReference/callableReferenceOfKotlinNestedClass.kt @@ -0,0 +1,29 @@ +// DONT_TARGET_EXACT_BACKEND: WASM +// WITH_RUNTIME + +// FILE: main.kt +import kotlin.reflect.KFunction1 + +class Sample { + inner class SS +} + +abstract class Checker { + fun check(): String { + return run( + Sample::SS, + { x, y -> x == Any() && y == Any() } + ) + } + abstract fun run(method: KFunction1, fn: (T1, T2) -> Boolean): String +} + +fun box(): String { + var result = ( object : Checker() { + override fun run(method: KFunction1, fn: (T1, T2) -> Boolean): String { + return "OK" + } + } ).check() + + return result +} diff --git a/compiler/testData/codegen/box/callableReference/callableReferenceOfNestedClass.kt b/compiler/testData/codegen/box/callableReference/callableReferenceOfNestedClass.kt new file mode 100644 index 00000000000..be042aafa09 --- /dev/null +++ b/compiler/testData/codegen/box/callableReference/callableReferenceOfNestedClass.kt @@ -0,0 +1,32 @@ +// DONT_TARGET_EXACT_BACKEND: WASM +// TARGET_BACKEND: JVM +// WITH_RUNTIME + +// FILE: Sample.java +public class Sample { + static class SS {} +} + + +// FILE: main.kt +import kotlin.reflect.KFunction0 + +abstract class Checker { + fun check(): String { + return run( + Sample::SS, + { x -> x == Any() } + ) + } + abstract fun run(method: KFunction0, fn: (T1) -> Boolean): String +} + +fun box(): String { + var result = ( object : Checker() { + override fun run(method: KFunction0, fn: (T1) -> Boolean): String { + return "OK" + } + } ).check() + + return result +} diff --git a/compiler/testData/codegen/box/callableReference/callableReferenceOfObjectMethod.kt b/compiler/testData/codegen/box/callableReference/callableReferenceOfObjectMethod.kt new file mode 100644 index 00000000000..8a7802bdd76 --- /dev/null +++ b/compiler/testData/codegen/box/callableReference/callableReferenceOfObjectMethod.kt @@ -0,0 +1,58 @@ +// DONT_TARGET_EXACT_BACKEND: WASM +// WITH_RUNTIME + +// FILE: main.kt +import kotlin.reflect.KFunction2 + +class Sample { + object A { + fun max(x: Int, y: Int): Int { + return if (x > y) { + x + } else { + y + } + } + } +} + +object A2 { + fun max(x: Int, y: Int): Int { + return if (x > y) { + x + } else { + y + } + } +} + +abstract class Checker { + fun check(): String { + return run( + Sample.A::max, + { x, y -> x > y } + ) + } + fun check2(): String { + return run( + A2::max, + { x, y -> x > y } + ) + } + abstract fun run(method: KFunction2, fn: (T1, T2) -> Boolean): String +} + +fun box(): String { + var result = ( object : Checker() { + override fun run(method: KFunction2, fn: (T1, T2) -> Boolean): String { + return "O" + } + } ).check() + result += ( object : Checker() { + override fun run(method: KFunction2, fn: (T1, T2) -> Boolean): String { + return "K" + } + } ).check2() + + return result +} diff --git a/compiler/testData/codegen/box/callableReference/callableReferenceOfStaticField.kt b/compiler/testData/codegen/box/callableReference/callableReferenceOfStaticField.kt new file mode 100644 index 00000000000..9ed1af8c271 --- /dev/null +++ b/compiler/testData/codegen/box/callableReference/callableReferenceOfStaticField.kt @@ -0,0 +1,31 @@ +// DONT_TARGET_EXACT_BACKEND: WASM +// TARGET_BACKEND: JVM +// WITH_RUNTIME + +// FILE: Sample.java +public class Sample { + public static int max = 1; +} + +// FILE: main.kt +import kotlin.reflect.KProperty0 + +abstract class Checker { + fun check(): String { + return run( + Sample::max, + { x -> x == Any() } + ) + } + abstract fun run(method: KProperty0, fn: (T1) -> Boolean): String +} + +fun box(): String { + var result = ( object : Checker() { + override fun run(method: KProperty0, fn: (T1) -> Boolean): String { + return "OK" + } + } ).check() + + return result +} diff --git a/compiler/testData/codegen/box/callableReference/callableReferenceOfStaticMethod.kt b/compiler/testData/codegen/box/callableReference/callableReferenceOfStaticMethod.kt new file mode 100644 index 00000000000..e2b9717f1b9 --- /dev/null +++ b/compiler/testData/codegen/box/callableReference/callableReferenceOfStaticMethod.kt @@ -0,0 +1,38 @@ +// DONT_TARGET_EXACT_BACKEND: WASM +// TARGET_BACKEND: JVM +// WITH_RUNTIME + +// FILE: Sample.java +public class Sample { + public static int max(int x, int y) { + if (x > y) { + return x; + } else { + return y; + } + } +} + +// FILE: main.kt + +import kotlin.reflect.KFunction2 + +abstract class Checker { + fun check(): String { + return run( + Sample::max, + { x, y -> x > y } + ) + } + abstract fun run(method: KFunction2, fn: (T1, T2) -> Boolean): String +} + +fun box(): String { + var result = ( object : Checker() { + override fun run(method: KFunction2, fn: (T1, T2) -> Boolean): String { + return "OK" + } + } ).check() + + return result +} diff --git a/compiler/testData/diagnostics/tests/inference/kt39220.kt b/compiler/testData/diagnostics/tests/inference/kt39220.kt index a363735a913..6fdf32210de 100644 --- a/compiler/testData/diagnostics/tests/inference/kt39220.kt +++ b/compiler/testData/diagnostics/tests/inference/kt39220.kt @@ -27,22 +27,22 @@ interface Foo { // CR on property with to receivers are forbidden fun test() { // with LHS and property - bar8(Foo::x1) + bar8(Foo::x1) bar8(Foo::x1) - bar8(Foo::x1) + bar8(Foo::x1) // with LHS and mutable property - bar8(Foo::x2) + bar8(Foo::x2) bar8(Foo::x2) - bar8(Foo::x2) + bar8(Foo::x2) // with LHS and propery + mutable property (mixed) - bar8(Foo::x3) + bar8(Foo::x3) bar8(Foo::x3) - bar8(Foo::x3) - bar9(Foo::x3) + bar8(Foo::x3) + bar9(Foo::x3) bar9(Foo::x3) - bar9(Foo::x3) + bar9(Foo::x3) } } @@ -84,9 +84,9 @@ fun main() { bar1(::resolve) // OK // with LHS and conflicting projection - bar2(Foo::resolve) + bar2(Foo::resolve) bar2(Foo::resolve) - bar2(Foo::resolve) + bar2(Foo::resolve) // with LHS and Any? expected type bar3(Foo::resolve) diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java index 63e282c25c0..9b96a08b5ee 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java @@ -2680,6 +2680,60 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/callableReference/builtinFunctionReferenceOwner.kt"); } + @Test + @TestMetadata("callableReferenceOfCompanionConst.kt") + public void testCallableReferenceOfCompanionConst() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/callableReferenceOfCompanionConst.kt"); + } + + @Test + @TestMetadata("callableReferenceOfCompanionMethod.kt") + public void testCallableReferenceOfCompanionMethod() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/callableReferenceOfCompanionMethod.kt"); + } + + @Test + @TestMetadata("callableReferenceOfCompanionProperty.kt") + public void testCallableReferenceOfCompanionProperty() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/callableReferenceOfCompanionProperty.kt"); + } + + @Test + @TestMetadata("callableReferenceOfJavaNestedClass.kt") + public void testCallableReferenceOfJavaNestedClass() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/callableReferenceOfJavaNestedClass.kt"); + } + + @Test + @TestMetadata("callableReferenceOfKotlinNestedClass.kt") + public void testCallableReferenceOfKotlinNestedClass() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/callableReferenceOfKotlinNestedClass.kt"); + } + + @Test + @TestMetadata("callableReferenceOfNestedClass.kt") + public void testCallableReferenceOfNestedClass() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/callableReferenceOfNestedClass.kt"); + } + + @Test + @TestMetadata("callableReferenceOfObjectMethod.kt") + public void testCallableReferenceOfObjectMethod() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/callableReferenceOfObjectMethod.kt"); + } + + @Test + @TestMetadata("callableReferenceOfStaticField.kt") + public void testCallableReferenceOfStaticField() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/callableReferenceOfStaticField.kt"); + } + + @Test + @TestMetadata("callableReferenceOfStaticMethod.kt") + public void testCallableReferenceOfStaticMethod() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/callableReferenceOfStaticMethod.kt"); + } + @Test @TestMetadata("charArrayOf.kt") public void testCharArrayOf() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index a98b4313710..6b95a1d2f73 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java @@ -2752,6 +2752,60 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/callableReference/builtinFunctionReferenceOwner.kt"); } + @Test + @TestMetadata("callableReferenceOfCompanionConst.kt") + public void testCallableReferenceOfCompanionConst() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/callableReferenceOfCompanionConst.kt"); + } + + @Test + @TestMetadata("callableReferenceOfCompanionMethod.kt") + public void testCallableReferenceOfCompanionMethod() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/callableReferenceOfCompanionMethod.kt"); + } + + @Test + @TestMetadata("callableReferenceOfCompanionProperty.kt") + public void testCallableReferenceOfCompanionProperty() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/callableReferenceOfCompanionProperty.kt"); + } + + @Test + @TestMetadata("callableReferenceOfJavaNestedClass.kt") + public void testCallableReferenceOfJavaNestedClass() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/callableReferenceOfJavaNestedClass.kt"); + } + + @Test + @TestMetadata("callableReferenceOfKotlinNestedClass.kt") + public void testCallableReferenceOfKotlinNestedClass() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/callableReferenceOfKotlinNestedClass.kt"); + } + + @Test + @TestMetadata("callableReferenceOfNestedClass.kt") + public void testCallableReferenceOfNestedClass() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/callableReferenceOfNestedClass.kt"); + } + + @Test + @TestMetadata("callableReferenceOfObjectMethod.kt") + public void testCallableReferenceOfObjectMethod() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/callableReferenceOfObjectMethod.kt"); + } + + @Test + @TestMetadata("callableReferenceOfStaticField.kt") + public void testCallableReferenceOfStaticField() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/callableReferenceOfStaticField.kt"); + } + + @Test + @TestMetadata("callableReferenceOfStaticMethod.kt") + public void testCallableReferenceOfStaticMethod() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/callableReferenceOfStaticMethod.kt"); + } + @Test @TestMetadata("charArrayOf.kt") public void testCharArrayOf() throws Exception { diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 7cc82e67b23..5f2cabffdd6 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -2379,6 +2379,51 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/callableReference/builtinFunctionReferenceOwner.kt"); } + @TestMetadata("callableReferenceOfCompanionConst.kt") + public void testCallableReferenceOfCompanionConst() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/callableReferenceOfCompanionConst.kt"); + } + + @TestMetadata("callableReferenceOfCompanionMethod.kt") + public void testCallableReferenceOfCompanionMethod() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/callableReferenceOfCompanionMethod.kt"); + } + + @TestMetadata("callableReferenceOfCompanionProperty.kt") + public void testCallableReferenceOfCompanionProperty() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/callableReferenceOfCompanionProperty.kt"); + } + + @TestMetadata("callableReferenceOfJavaNestedClass.kt") + public void testCallableReferenceOfJavaNestedClass() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/callableReferenceOfJavaNestedClass.kt"); + } + + @TestMetadata("callableReferenceOfKotlinNestedClass.kt") + public void testCallableReferenceOfKotlinNestedClass() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/callableReferenceOfKotlinNestedClass.kt"); + } + + @TestMetadata("callableReferenceOfNestedClass.kt") + public void testCallableReferenceOfNestedClass() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/callableReferenceOfNestedClass.kt"); + } + + @TestMetadata("callableReferenceOfObjectMethod.kt") + public void testCallableReferenceOfObjectMethod() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/callableReferenceOfObjectMethod.kt"); + } + + @TestMetadata("callableReferenceOfStaticField.kt") + public void testCallableReferenceOfStaticField() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/callableReferenceOfStaticField.kt"); + } + + @TestMetadata("callableReferenceOfStaticMethod.kt") + public void testCallableReferenceOfStaticMethod() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/callableReferenceOfStaticMethod.kt"); + } + @TestMetadata("charArrayOf.kt") public void testCharArrayOf() throws Exception { runTest("compiler/testData/codegen/box/callableReference/charArrayOf.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java index 93b6b232cf3..f6b8e76e541 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java @@ -1644,6 +1644,31 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes runTest("compiler/testData/codegen/box/callableReference/arrayOf.kt"); } + @TestMetadata("callableReferenceOfCompanionConst.kt") + public void testCallableReferenceOfCompanionConst() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/callableReferenceOfCompanionConst.kt"); + } + + @TestMetadata("callableReferenceOfCompanionMethod.kt") + public void testCallableReferenceOfCompanionMethod() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/callableReferenceOfCompanionMethod.kt"); + } + + @TestMetadata("callableReferenceOfCompanionProperty.kt") + public void testCallableReferenceOfCompanionProperty() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/callableReferenceOfCompanionProperty.kt"); + } + + @TestMetadata("callableReferenceOfKotlinNestedClass.kt") + public void testCallableReferenceOfKotlinNestedClass() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/callableReferenceOfKotlinNestedClass.kt"); + } + + @TestMetadata("callableReferenceOfObjectMethod.kt") + public void testCallableReferenceOfObjectMethod() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/callableReferenceOfObjectMethod.kt"); + } + @TestMetadata("charArrayOf.kt") public void testCharArrayOf() throws Exception { runTest("compiler/testData/codegen/box/callableReference/charArrayOf.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java index 65e7fb4e1d8..460b09565c5 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java @@ -1644,6 +1644,31 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/callableReference/arrayOf.kt"); } + @TestMetadata("callableReferenceOfCompanionConst.kt") + public void testCallableReferenceOfCompanionConst() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/callableReferenceOfCompanionConst.kt"); + } + + @TestMetadata("callableReferenceOfCompanionMethod.kt") + public void testCallableReferenceOfCompanionMethod() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/callableReferenceOfCompanionMethod.kt"); + } + + @TestMetadata("callableReferenceOfCompanionProperty.kt") + public void testCallableReferenceOfCompanionProperty() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/callableReferenceOfCompanionProperty.kt"); + } + + @TestMetadata("callableReferenceOfKotlinNestedClass.kt") + public void testCallableReferenceOfKotlinNestedClass() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/callableReferenceOfKotlinNestedClass.kt"); + } + + @TestMetadata("callableReferenceOfObjectMethod.kt") + public void testCallableReferenceOfObjectMethod() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/callableReferenceOfObjectMethod.kt"); + } + @TestMetadata("charArrayOf.kt") public void testCharArrayOf() throws Exception { runTest("compiler/testData/codegen/box/callableReference/charArrayOf.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index 2109488194c..6a6744d9ee7 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -1609,6 +1609,31 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/callableReference/arrayOf.kt"); } + @TestMetadata("callableReferenceOfCompanionConst.kt") + public void testCallableReferenceOfCompanionConst() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/callableReferenceOfCompanionConst.kt"); + } + + @TestMetadata("callableReferenceOfCompanionMethod.kt") + public void testCallableReferenceOfCompanionMethod() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/callableReferenceOfCompanionMethod.kt"); + } + + @TestMetadata("callableReferenceOfCompanionProperty.kt") + public void testCallableReferenceOfCompanionProperty() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/callableReferenceOfCompanionProperty.kt"); + } + + @TestMetadata("callableReferenceOfKotlinNestedClass.kt") + public void testCallableReferenceOfKotlinNestedClass() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/callableReferenceOfKotlinNestedClass.kt"); + } + + @TestMetadata("callableReferenceOfObjectMethod.kt") + public void testCallableReferenceOfObjectMethod() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/callableReferenceOfObjectMethod.kt"); + } + @TestMetadata("charArrayOf.kt") public void testCharArrayOf() throws Exception { runTest("compiler/testData/codegen/box/callableReference/charArrayOf.kt");