diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java index 17a6e98ec74..f333ffe4d97 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java @@ -7959,6 +7959,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte runTest("compiler/testData/diagnostics/tests/funInterface/genericSubstitutionForFunInterface.kt"); } + @TestMetadata("noCompatibilityResolveForFunInterfaces.kt") + public void testNoCompatibilityResolveForFunInterfaces() throws Exception { + runTest("compiler/testData/diagnostics/tests/funInterface/noCompatibilityResolveForFunInterfaces.kt"); + } + @TestMetadata("resolveFunInterfaceWithoutMainMethod.kt") public void testResolveFunInterfaceWithoutMainMethod() throws Exception { runTest("compiler/testData/diagnostics/tests/funInterface/resolveFunInterfaceWithoutMainMethod.kt"); @@ -13611,6 +13616,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/j+k/sam"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); } + @TestMetadata("compatibilityResolveToOuterScopeForKotlinFunctions.kt") + public void testCompatibilityResolveToOuterScopeForKotlinFunctions() throws Exception { + runTest("compiler/testData/diagnostics/tests/j+k/sam/compatibilityResolveToOuterScopeForKotlinFunctions.kt"); + } + @TestMetadata("enhancedSamConstructor.kt") public void testEnhancedSamConstructor() throws Exception { runTest("compiler/testData/diagnostics/tests/j+k/sam/enhancedSamConstructor.kt"); diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/sam/JavaBasedSamConversionResolver.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/sam/JavaBasedSamConversionResolver.kt index 93935cb6f7c..374b7ae239c 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/sam/JavaBasedSamConversionResolver.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/sam/JavaBasedSamConversionResolver.kt @@ -38,4 +38,7 @@ object JavaBasedSamConversionOracle : SamConversionOracle { val descriptor = samType.constructor.declarationDescriptor return descriptor is ClassDescriptor && (descriptor.isFun || descriptor is JavaClassDescriptor) } + + override fun isJavaApplicableCandidate(candidate: CallableDescriptor): Boolean = + shouldRunSamConversionForFunction(candidate) } \ No newline at end of file diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/sam/JvmSamConversionOracle.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/sam/JvmSamConversionOracle.kt index a1072a43e6a..e22ebdd0b8b 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/sam/JvmSamConversionOracle.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/sam/JvmSamConversionOracle.kt @@ -22,4 +22,7 @@ class JvmSamConversionOracle( override fun isPossibleSamType(samType: KotlinType): Boolean = JavaBasedSamConversionOracle.isPossibleSamType(samType) + + override fun isJavaApplicableCandidate(candidate: CallableDescriptor): Boolean = + JavaBasedSamConversionOracle.shouldRunSamConversionForFunction(candidate) } \ No newline at end of file diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/samConversionUtils.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/samConversionUtils.kt index 914dfa51306..41ad17dcfbc 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/samConversionUtils.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/samConversionUtils.kt @@ -11,6 +11,7 @@ import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.ParameterDescriptor import org.jetbrains.kotlin.incremental.record +import org.jetbrains.kotlin.resolve.calls.inference.model.LowerPriorityToPreserveCompatibility import org.jetbrains.kotlin.resolve.calls.model.* import org.jetbrains.kotlin.resolve.sam.SAM_LOOKUP_NAME import org.jetbrains.kotlin.resolve.sam.getFunctionTypeForPossibleSamType @@ -86,6 +87,10 @@ object SamTypeConversions : ParameterTypeConversion { SamConversionDescription(convertedTypeByOriginal, convertedTypeByCandidate!!) ) + if (needCompatibilityResolve(candidate, expectedParameterType)) { + candidate.addDiagnostic(LowerPriorityToPreserveCompatibility) + } + val samDescriptor = originalExpectedType.constructor.declarationDescriptor if (samDescriptor is ClassDescriptor) { callComponents.lookupTracker.record(candidate.scopeTower.location, samDescriptor, SAM_LOOKUP_NAME) @@ -93,4 +98,13 @@ object SamTypeConversions : ParameterTypeConversion { return convertedTypeByCandidate } + + private fun needCompatibilityResolve(candidate: KotlinResolutionCandidate, typeToConvert: UnwrappedType): Boolean { + // fun interfaces is a new feature with a new modifier, so no compatibility resolve is needed + val descriptor = typeToConvert.constructor.declarationDescriptor + if (descriptor is ClassDescriptor && descriptor.isFun) return false + + // now conversions for Kotlin candidates are possible, so we have to perform compatibility resolve + return !candidate.callComponents.samConversionOracle.isJavaApplicableCandidate(candidate.resolvedCall.candidateDescriptor) + } } diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/ConstraintPositionAndErrors.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/ConstraintPositionAndErrors.kt index ea0861043f0..2a2eaa9a6d5 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/ConstraintPositionAndErrors.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/ConstraintPositionAndErrors.kt @@ -19,8 +19,7 @@ package org.jetbrains.kotlin.resolve.calls.inference.model import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor import org.jetbrains.kotlin.resolve.calls.model.* import org.jetbrains.kotlin.resolve.calls.tower.ResolutionCandidateApplicability -import org.jetbrains.kotlin.resolve.calls.tower.ResolutionCandidateApplicability.INAPPLICABLE -import org.jetbrains.kotlin.resolve.calls.tower.ResolutionCandidateApplicability.INAPPLICABLE_WRONG_RECEIVER +import org.jetbrains.kotlin.resolve.calls.tower.ResolutionCandidateApplicability.* import org.jetbrains.kotlin.resolve.scopes.receivers.DetailedReceiver import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.model.KotlinTypeMarker @@ -123,3 +122,5 @@ class ConstrainingTypeIsError( val constraintType: KotlinTypeMarker, val position: IncorporationConstraintPosition ) : ConstraintSystemCallDiagnostic(INAPPLICABLE) + +object LowerPriorityToPreserveCompatibility : ConstraintSystemCallDiagnostic(RESOLVED_NEED_PRESERVE_COMPATIBILITY) diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/ImplicitScopeTower.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/ImplicitScopeTower.kt index 576ab7c0eb9..adf3366ac45 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/ImplicitScopeTower.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/ImplicitScopeTower.kt @@ -86,6 +86,7 @@ fun getResultApplicability(diagnostics: Collection) = enum class ResolutionCandidateApplicability { RESOLVED, // call success or has uncompleted inference or in other words possible successful candidate RESOLVED_WITH_ERROR, // call has error, but it is still successful from resolution perspective + RESOLVED_NEED_PRESERVE_COMPATIBILITY, // call resolved successfully, but using new features that changes resolve RESOLVED_LOW_PRIORITY, CONVENTION_ERROR, // missing infix, operator etc MAY_THROW_RUNTIME_ERROR, // unsafe call or unstable smart cast @@ -120,6 +121,7 @@ class UsedSmartCastForDispatchReceiver(val smartCastType: KotlinType) : Resoluti object ErrorDescriptorDiagnostic : ResolutionDiagnostic(RESOLVED) // todo discuss and change to INAPPLICABLE object LowPriorityDescriptorDiagnostic : ResolutionDiagnostic(RESOLVED_LOW_PRIORITY) object DynamicDescriptorDiagnostic : ResolutionDiagnostic(RESOLVED_LOW_PRIORITY) +object ResolvedUsingNewFeatures : ResolutionDiagnostic(RESOLVED_NEED_PRESERVE_COMPATIBILITY) object UnstableSmartCastDiagnostic : ResolutionDiagnostic(RESOLVED_WITH_ERROR) object HiddenExtensionRelatedToDynamicTypes : ResolutionDiagnostic(HIDDEN) object HiddenDescriptor : ResolutionDiagnostic(HIDDEN) diff --git a/compiler/testData/diagnostics/tests/funInterface/noCompatibilityResolveForFunInterfaces.fir.kt b/compiler/testData/diagnostics/tests/funInterface/noCompatibilityResolveForFunInterfaces.fir.kt new file mode 100644 index 00000000000..b093b5023ea --- /dev/null +++ b/compiler/testData/diagnostics/tests/funInterface/noCompatibilityResolveForFunInterfaces.fir.kt @@ -0,0 +1,65 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION + +fun interface KRunnable { + fun invoke() +} + +object Test1 { + fun foo(x: Any) {} + fun foo(f: () -> Unit) {} + + object Scope { + fun foo(r: KRunnable) {} + + fun test(f: () -> Unit) { + foo(f) + } + } +} + +object Test2 { + fun foo(f: () -> String) {} + + object Scope { + fun foo(r: KRunnable) {} + + fun test(f: () -> Unit) { + foo(f) + } + } +} + +object Test3 { + fun foo(i: Int, r: KRunnable): Int = 0 + fun foo(n: Number, f: () -> Unit): String = "" + + fun test(f: () -> Unit) { + val result = foo(1, f) + result + } +} + +object Test4 { + fun foo(i: Int, r: KRunnable): Int = 0 + fun foo(n: Number, f: () -> Unit): String = "" + + fun bar() {} + + fun test() { + val result = foo(1, ::bar) + result + } +} + +object Test5 { + fun foo(x: Any) {} + fun foo(f: () -> Unit) {} + + object Scope { + fun foo(r: KRunnable) {} + + fun test() { + foo { } + } + } +} diff --git a/compiler/testData/diagnostics/tests/funInterface/noCompatibilityResolveForFunInterfaces.kt b/compiler/testData/diagnostics/tests/funInterface/noCompatibilityResolveForFunInterfaces.kt new file mode 100644 index 00000000000..97a44d5746c --- /dev/null +++ b/compiler/testData/diagnostics/tests/funInterface/noCompatibilityResolveForFunInterfaces.kt @@ -0,0 +1,65 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION + +fun interface KRunnable { + fun invoke() +} + +object Test1 { + fun foo(x: Any) {} + fun foo(f: () -> Unit) {} + + object Scope { + fun foo(r: KRunnable) {} + + fun test(f: () -> Unit) { + foo(f) + } + } +} + +object Test2 { + fun foo(f: () -> String) {} + + object Scope { + fun foo(r: KRunnable) {} + + fun test(f: () -> Unit) { + foo(f) + } + } +} + +object Test3 { + fun foo(i: Int, r: KRunnable): Int = 0 + fun foo(n: Number, f: () -> Unit): String = "" + + fun test(f: () -> Unit) { + val result = foo(1, f) + result + } +} + +object Test4 { + fun foo(i: Int, r: KRunnable): Int = 0 + fun foo(n: Number, f: () -> Unit): String = "" + + fun bar() {} + + fun test() { + val result = foo(1, ::bar) + result + } +} + +object Test5 { + fun foo(x: Any) {} + fun foo(f: () -> Unit) {} + + object Scope { + fun foo(r: KRunnable) {} + + fun test() { + foo { } + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/funInterface/noCompatibilityResolveForFunInterfaces.txt b/compiler/testData/diagnostics/tests/funInterface/noCompatibilityResolveForFunInterfaces.txt new file mode 100644 index 00000000000..30ab81ef704 --- /dev/null +++ b/compiler/testData/diagnostics/tests/funInterface/noCompatibilityResolveForFunInterfaces.txt @@ -0,0 +1,82 @@ +package + +public fun interface KRunnable { + 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 invoke(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public object Test1 { + private constructor Test1() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final fun foo(/*0*/ f: () -> kotlin.Unit): kotlin.Unit + public final fun foo(/*0*/ x: kotlin.Any): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + public object Scope { + private constructor Scope() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final fun foo(/*0*/ r: KRunnable): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final fun test(/*0*/ f: () -> kotlin.Unit): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} + +public object Test2 { + private constructor Test2() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final fun foo(/*0*/ f: () -> kotlin.String): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + public object Scope { + private constructor Scope() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final fun foo(/*0*/ r: KRunnable): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final fun test(/*0*/ f: () -> kotlin.Unit): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} + +public object Test3 { + private constructor Test3() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final fun foo(/*0*/ i: kotlin.Int, /*1*/ r: KRunnable): kotlin.Int + public final fun foo(/*0*/ n: kotlin.Number, /*1*/ f: () -> kotlin.Unit): kotlin.String + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final fun test(/*0*/ f: () -> kotlin.Unit): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public object Test4 { + private constructor Test4() + public final fun bar(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final fun foo(/*0*/ i: kotlin.Int, /*1*/ r: KRunnable): kotlin.Int + public final fun foo(/*0*/ n: kotlin.Number, /*1*/ f: () -> kotlin.Unit): kotlin.String + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final fun test(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public object Test5 { + private constructor Test5() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final fun foo(/*0*/ f: () -> kotlin.Unit): kotlin.Unit + public final fun foo(/*0*/ x: kotlin.Any): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + public object Scope { + private constructor Scope() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final fun foo(/*0*/ r: KRunnable): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final fun test(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} diff --git a/compiler/testData/diagnostics/tests/j+k/sam/compatibilityResolveToOuterScopeForKotlinFunctions.fir.kt b/compiler/testData/diagnostics/tests/j+k/sam/compatibilityResolveToOuterScopeForKotlinFunctions.fir.kt new file mode 100644 index 00000000000..d1faa64bd45 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/sam/compatibilityResolveToOuterScopeForKotlinFunctions.fir.kt @@ -0,0 +1,61 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION + +object Test1 { + fun foo(x: Any) {} + fun foo(f: () -> Unit) {} + + object Scope { + fun foo(r: Runnable) {} + + fun test(f: () -> Unit) { + foo(f) + } + } +} + +object Test2 { + fun foo(f: () -> String) {} + + object Scope { + fun foo(r: Runnable) {} + + fun test(f: () -> Unit) { + foo(f) + } + } +} + +object Test3 { + fun foo(i: Int, r: Runnable): Int = 0 + fun foo(n: Number, f: () -> Unit): String = "" + + fun test(f: () -> Unit) { + val result = foo(1, f) + result + } +} + +object Test4 { + fun foo(i: Int, r: Runnable): Int = 0 + fun foo(n: Number, f: () -> Unit): String = "" + + fun bar() {} + + fun test() { + val result = foo(1, ::bar) + result + } +} + +object Test5 { + fun foo(x: Any) {} + fun foo(f: () -> Unit) {} + + object Scope { + fun foo(r: Runnable) {} + + fun test() { + foo { } + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/j+k/sam/compatibilityResolveToOuterScopeForKotlinFunctions.kt b/compiler/testData/diagnostics/tests/j+k/sam/compatibilityResolveToOuterScopeForKotlinFunctions.kt new file mode 100644 index 00000000000..d1faa64bd45 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/sam/compatibilityResolveToOuterScopeForKotlinFunctions.kt @@ -0,0 +1,61 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION + +object Test1 { + fun foo(x: Any) {} + fun foo(f: () -> Unit) {} + + object Scope { + fun foo(r: Runnable) {} + + fun test(f: () -> Unit) { + foo(f) + } + } +} + +object Test2 { + fun foo(f: () -> String) {} + + object Scope { + fun foo(r: Runnable) {} + + fun test(f: () -> Unit) { + foo(f) + } + } +} + +object Test3 { + fun foo(i: Int, r: Runnable): Int = 0 + fun foo(n: Number, f: () -> Unit): String = "" + + fun test(f: () -> Unit) { + val result = foo(1, f) + result + } +} + +object Test4 { + fun foo(i: Int, r: Runnable): Int = 0 + fun foo(n: Number, f: () -> Unit): String = "" + + fun bar() {} + + fun test() { + val result = foo(1, ::bar) + result + } +} + +object Test5 { + fun foo(x: Any) {} + fun foo(f: () -> Unit) {} + + object Scope { + fun foo(r: Runnable) {} + + fun test() { + foo { } + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/j+k/sam/compatibilityResolveToOuterScopeForKotlinFunctions.txt b/compiler/testData/diagnostics/tests/j+k/sam/compatibilityResolveToOuterScopeForKotlinFunctions.txt new file mode 100644 index 00000000000..ebf4fd0b184 --- /dev/null +++ b/compiler/testData/diagnostics/tests/j+k/sam/compatibilityResolveToOuterScopeForKotlinFunctions.txt @@ -0,0 +1,75 @@ +package + +public object Test1 { + private constructor Test1() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final fun foo(/*0*/ f: () -> kotlin.Unit): kotlin.Unit + public final fun foo(/*0*/ x: kotlin.Any): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + public object Scope { + private constructor Scope() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final fun foo(/*0*/ r: java.lang.Runnable): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final fun test(/*0*/ f: () -> kotlin.Unit): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} + +public object Test2 { + private constructor Test2() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final fun foo(/*0*/ f: () -> kotlin.String): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + public object Scope { + private constructor Scope() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final fun foo(/*0*/ r: java.lang.Runnable): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final fun test(/*0*/ f: () -> kotlin.Unit): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} + +public object Test3 { + private constructor Test3() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final fun foo(/*0*/ i: kotlin.Int, /*1*/ r: java.lang.Runnable): kotlin.Int + public final fun foo(/*0*/ n: kotlin.Number, /*1*/ f: () -> kotlin.Unit): kotlin.String + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final fun test(/*0*/ f: () -> kotlin.Unit): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public object Test4 { + private constructor Test4() + public final fun bar(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final fun foo(/*0*/ i: kotlin.Int, /*1*/ r: java.lang.Runnable): kotlin.Int + public final fun foo(/*0*/ n: kotlin.Number, /*1*/ f: () -> kotlin.Unit): kotlin.String + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final fun test(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public object Test5 { + private constructor Test5() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final fun foo(/*0*/ f: () -> kotlin.Unit): kotlin.Unit + public final fun foo(/*0*/ x: kotlin.Any): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + public object Scope { + private constructor Scope() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final fun foo(/*0*/ r: java.lang.Runnable): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final fun test(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 49af09f6deb..40c660d9eac 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -7966,6 +7966,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTestWithFirVali runTest("compiler/testData/diagnostics/tests/funInterface/genericSubstitutionForFunInterface.kt"); } + @TestMetadata("noCompatibilityResolveForFunInterfaces.kt") + public void testNoCompatibilityResolveForFunInterfaces() throws Exception { + runTest("compiler/testData/diagnostics/tests/funInterface/noCompatibilityResolveForFunInterfaces.kt"); + } + @TestMetadata("resolveFunInterfaceWithoutMainMethod.kt") public void testResolveFunInterfaceWithoutMainMethod() throws Exception { runTest("compiler/testData/diagnostics/tests/funInterface/resolveFunInterfaceWithoutMainMethod.kt"); @@ -13618,6 +13623,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTestWithFirVali KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/j+k/sam"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); } + @TestMetadata("compatibilityResolveToOuterScopeForKotlinFunctions.kt") + public void testCompatibilityResolveToOuterScopeForKotlinFunctions() throws Exception { + runTest("compiler/testData/diagnostics/tests/j+k/sam/compatibilityResolveToOuterScopeForKotlinFunctions.kt"); + } + @TestMetadata("enhancedSamConstructor.kt") public void testEnhancedSamConstructor() throws Exception { runTest("compiler/testData/diagnostics/tests/j+k/sam/enhancedSamConstructor.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java index d92f79b0a33..9dbc2711f0d 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java @@ -7961,6 +7961,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing runTest("compiler/testData/diagnostics/tests/funInterface/genericSubstitutionForFunInterface.kt"); } + @TestMetadata("noCompatibilityResolveForFunInterfaces.kt") + public void testNoCompatibilityResolveForFunInterfaces() throws Exception { + runTest("compiler/testData/diagnostics/tests/funInterface/noCompatibilityResolveForFunInterfaces.kt"); + } + @TestMetadata("resolveFunInterfaceWithoutMainMethod.kt") public void testResolveFunInterfaceWithoutMainMethod() throws Exception { runTest("compiler/testData/diagnostics/tests/funInterface/resolveFunInterfaceWithoutMainMethod.kt"); @@ -13613,6 +13618,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/j+k/sam"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); } + @TestMetadata("compatibilityResolveToOuterScopeForKotlinFunctions.kt") + public void testCompatibilityResolveToOuterScopeForKotlinFunctions() throws Exception { + runTest("compiler/testData/diagnostics/tests/j+k/sam/compatibilityResolveToOuterScopeForKotlinFunctions.kt"); + } + @TestMetadata("enhancedSamConstructor.kt") public void testEnhancedSamConstructor() throws Exception { runTest("compiler/testData/diagnostics/tests/j+k/sam/enhancedSamConstructor.kt"); diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/sam/SamConversionOracle.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/sam/SamConversionOracle.kt index 4a21f5ca8fb..85ce2ad71ab 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/sam/SamConversionOracle.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/sam/SamConversionOracle.kt @@ -14,6 +14,7 @@ import org.jetbrains.kotlin.types.KotlinType interface SamConversionOracle { fun shouldRunSamConversionForFunction(candidate: CallableDescriptor): Boolean fun isPossibleSamType(samType: KotlinType): Boolean + fun isJavaApplicableCandidate(candidate: CallableDescriptor): Boolean } class SamConversionOracleDefault : SamConversionOracle { @@ -23,4 +24,6 @@ class SamConversionOracleDefault : SamConversionOracle { val descriptor = samType.constructor.declarationDescriptor return descriptor is ClassDescriptor && descriptor.isFun } + + override fun isJavaApplicableCandidate(candidate: CallableDescriptor): Boolean = false } \ No newline at end of file