diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsSmokeTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsSmokeTestGenerated.java index 355c0deea66..f47e4dc1464 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsSmokeTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsSmokeTestGenerated.java @@ -12383,6 +12383,11 @@ public class FirDiagnosticsSmokeTestGenerated extends AbstractFirDiagnosticsSmok runTest("compiler/testData/diagnostics/tests/j+k/sam/privateCandidatesWithWrongArguments.kt"); } + @TestMetadata("recursiveSamsAndInvoke.kt") + public void testRecursiveSamsAndInvoke() throws Exception { + runTest("compiler/testData/diagnostics/tests/j+k/sam/recursiveSamsAndInvoke.kt"); + } + @TestMetadata("samOnTypeParameter.kt") public void testSamOnTypeParameter() throws Exception { runTest("compiler/testData/diagnostics/tests/j+k/sam/samOnTypeParameter.kt"); diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/SamAdapterFunctionsScope.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/SamAdapterFunctionsScope.kt index f062ea2dbb3..acea1170180 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/SamAdapterFunctionsScope.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/SamAdapterFunctionsScope.kt @@ -60,8 +60,7 @@ class SamAdapterFunctionsScope( private val deprecationResolver: DeprecationResolver, private val lookupTracker: LookupTracker ) : SyntheticScope.Default() { - private val samViaSyntheticScopeDisabled = languageVersionSettings.supportsFeature(LanguageFeature.NewInference) && - languageVersionSettings.supportsFeature(LanguageFeature.SamConversionForKotlinFunctions) + private val samViaSyntheticScopeDisabled = languageVersionSettings.supportsFeature(LanguageFeature.NewInference) private val extensionForFunction = storageManager.createMemoizedFunctionWithNullableValues { function -> diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt index 1a3250fbb2a..516efead521 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt @@ -5,9 +5,8 @@ package org.jetbrains.kotlin.resolve.calls.components -import org.jetbrains.kotlin.builtins.functions.FunctionClassDescriptor -import org.jetbrains.kotlin.builtins.getFunctionalClassKind import org.jetbrains.kotlin.builtins.getReceiverTypeFromFunctionType +import org.jetbrains.kotlin.builtins.isFunctionType import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.impl.TypeAliasConstructorDescriptor import org.jetbrains.kotlin.resolve.calls.components.TypeArgumentsToParametersMapper.TypeArgumentsMapping.NoExplicitArguments @@ -27,7 +26,6 @@ import org.jetbrains.kotlin.resolve.calls.tower.VisibilityError import org.jetbrains.kotlin.types.ErrorUtils import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.UnwrappedType -import org.jetbrains.kotlin.types.checker.anySuperTypeConstructor import org.jetbrains.kotlin.types.typeUtil.contains import org.jetbrains.kotlin.utils.addToStdlib.safeAs @@ -300,7 +298,7 @@ private fun KotlinResolutionCandidate.getExpectedTypeWithSAMConversion( if (!callComponents.samConversionTransformer.shouldRunSamConversionForFunction(resolvedCall.candidateDescriptor)) return null val argumentIsFunctional = when (argument) { - is SimpleKotlinCallArgument -> argument.receiver.stableType.isSubtypeOfFunctionType() + is SimpleKotlinCallArgument -> argument.receiver.stableType.isFunctionType is LambdaKotlinCallArgument, is CallableReferenceKotlinCallArgument -> true else -> false } @@ -324,10 +322,6 @@ private fun KotlinResolutionCandidate.getExpectedTypeWithSAMConversion( return convertedTypeByCandidate } -private fun UnwrappedType.isSubtypeOfFunctionType() = anySuperTypeConstructor { - it.declarationDescriptor?.getFunctionalClassKind() == FunctionClassDescriptor.Kind.Function -} - internal object CheckReceivers : ResolutionPart() { private fun KotlinResolutionCandidate.checkReceiver( receiverArgument: SimpleKotlinCallArgument?, diff --git a/compiler/testData/diagnostics/tests/callableReference/generic/dependOnArgumentType.kt b/compiler/testData/diagnostics/tests/callableReference/generic/dependOnArgumentType.kt index 6bf8bbf1615..fbe342c6e36 100644 --- a/compiler/testData/diagnostics/tests/callableReference/generic/dependOnArgumentType.kt +++ b/compiler/testData/diagnostics/tests/callableReference/generic/dependOnArgumentType.kt @@ -16,14 +16,14 @@ fun bar(s: T) {} fun complex(t: T, f: (T) -> Unit) {} fun test1() { - foo(1, A::invokeLater) // KT-24507 SAM conversion accidentally applied to callable reference and incorrectly handled via BE + foo(1, A::invokeLater) // KT-24507 SAM conversion accidentally applied to callable reference and incorrectly handled via BE foo(1, ::bar) complex(1, ::bar) } fun test2(x: R) { - foo(x, A::invokeLater) // KT-24507 SAM conversion accidentally applied to callable reference and incorrectly handled via BE + foo(x, A::invokeLater) // KT-24507 SAM conversion accidentally applied to callable reference and incorrectly handled via BE foo(x, ::bar) complex(x, ::bar) diff --git a/compiler/testData/diagnostics/tests/j+k/sam/recursiveSamsAndInvoke.kt b/compiler/testData/diagnostics/tests/j+k/sam/recursiveSamsAndInvoke.kt new file mode 100644 index 00000000000..6457136dfdd --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/sam/recursiveSamsAndInvoke.kt @@ -0,0 +1,28 @@ +// FILE: MyFuture.java + +public interface MyFuture { + MyFuture addListener(MyListener> listener); +} + +// FILE: MyListener.java + +public interface MyListener> { + void operationComplete(F future) throws Exception; +} + +// FILE: test.kt + +typealias Handler = (cause: Throwable?) -> Unit + +fun MyFuture.setup() { + addListener(ListenerImpl>()) + addListener { } +} + +class ListenerImpl> : MyListener, Handler { + override fun operationComplete(future: F) { + } + + override fun invoke(cause: Throwable?) { + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/j+k/sam/recursiveSamsAndInvoke.txt b/compiler/testData/diagnostics/tests/j+k/sam/recursiveSamsAndInvoke.txt new file mode 100644 index 00000000000..3acf90b68ec --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/sam/recursiveSamsAndInvoke.txt @@ -0,0 +1,27 @@ +package + +public fun MyFuture.setup(): kotlin.Unit + +public final class ListenerImpl> : MyListener, Handler /* = (cause: kotlin.Throwable?) -> kotlin.Unit */ { + public constructor ListenerImpl>() + public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ fun invoke(/*0*/ cause: kotlin.Throwable?): kotlin.Unit + public open override /*1*/ fun operationComplete(/*0*/ future: F): kotlin.Unit + public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface MyFuture { + public abstract fun addListener(/*0*/ listener: MyListener!>!): MyFuture! + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface MyListener!> { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public abstract fun operationComplete(/*0*/ future: F!): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} +public typealias Handler = (cause: kotlin.Throwable?) -> kotlin.Unit diff --git a/compiler/testData/diagnostics/tests/scopes/protectedVisibility/syntheticSAMExtensions.kt b/compiler/testData/diagnostics/tests/scopes/protectedVisibility/syntheticSAMExtensions.kt index f0e62c09462..308acfa0c82 100644 --- a/compiler/testData/diagnostics/tests/scopes/protectedVisibility/syntheticSAMExtensions.kt +++ b/compiler/testData/diagnostics/tests/scopes/protectedVisibility/syntheticSAMExtensions.kt @@ -21,7 +21,7 @@ class B : A() { } if (d.x is B) { - d.x.foo {} + d.x.foo {} } } } diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 37e5da660cc..7c6ae029ffc 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -12390,6 +12390,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { runTest("compiler/testData/diagnostics/tests/j+k/sam/privateCandidatesWithWrongArguments.kt"); } + @TestMetadata("recursiveSamsAndInvoke.kt") + public void testRecursiveSamsAndInvoke() throws Exception { + runTest("compiler/testData/diagnostics/tests/j+k/sam/recursiveSamsAndInvoke.kt"); + } + @TestMetadata("samOnTypeParameter.kt") public void testSamOnTypeParameter() throws Exception { runTest("compiler/testData/diagnostics/tests/j+k/sam/samOnTypeParameter.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java index af232e71107..6b511f68390 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java @@ -12385,6 +12385,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing runTest("compiler/testData/diagnostics/tests/j+k/sam/privateCandidatesWithWrongArguments.kt"); } + @TestMetadata("recursiveSamsAndInvoke.kt") + public void testRecursiveSamsAndInvoke() throws Exception { + runTest("compiler/testData/diagnostics/tests/j+k/sam/recursiveSamsAndInvoke.kt"); + } + @TestMetadata("samOnTypeParameter.kt") public void testSamOnTypeParameter() throws Exception { runTest("compiler/testData/diagnostics/tests/j+k/sam/samOnTypeParameter.kt");