From 789f886d3cf372f4b177e0df8d23d0a06433ca62 Mon Sep 17 00:00:00 2001 From: Kirill Rakhman Date: Fri, 3 Nov 2023 15:27:36 +0100 Subject: [PATCH] [FIR] Implement ADAPTED_CALLABLE_REFERENCE_AGAINST_REFLECTION_TYPE diagnostic #KT-59401 Fixed --- .../diagnostics/KtFirDataClassConverters.kt | 6 ++ .../api/fir/diagnostics/KtFirDiagnostics.kt | 4 ++ .../fir/diagnostics/KtFirDiagnosticsImpl.kt | 5 ++ .../diagnostics/FirDiagnosticsList.kt | 1 + .../fir/analysis/diagnostics/FirErrors.kt | 1 + .../FirNonSuppressibleErrorNames.kt | 1 + .../diagnostics/FirErrorsDefaultMessages.kt | 5 ++ .../coneDiagnosticToFirDiagnostic.kt | 2 + .../jetbrains/kotlin/fir/FirCallResolver.kt | 3 +- .../calls/CallableReferenceResolution.kt | 59 ++++++++++++++----- .../fir/resolve/calls/ResolutionDiagnostic.kt | 2 + .../adapted/noKFunctionForAdaptation.fir.kt | 4 +- ...aptedReferenceAgainstReflectionType.fir.kt | 27 --------- .../adaptedReferenceAgainstReflectionType.kt | 10 ++++ .../adaptedReferenceAgainstReflectionType.txt | 23 -------- ...ingOnReferenceAgainstReflectiveType.fir.kt | 11 +++- ...WarningOnReferenceAgainstReflectiveType.kt | 9 +++ ...arningOnReferenceAgainstReflectiveType.txt | 23 -------- 18 files changed, 104 insertions(+), 92 deletions(-) delete mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/adaptedReferenceAgainstReflectionType.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/adaptedReferenceAgainstReflectionType.txt delete mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/compatibilityWarningOnReferenceAgainstReflectiveType.txt diff --git a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDataClassConverters.kt b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDataClassConverters.kt index a6984e0deba..5e6bd250a72 100644 --- a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDataClassConverters.kt +++ b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDataClassConverters.kt @@ -2597,6 +2597,12 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert token, ) } + add(FirErrors.ADAPTED_CALLABLE_REFERENCE_AGAINST_REFLECTION_TYPE) { firDiagnostic -> + AdaptedCallableReferenceAgainstReflectionTypeImpl( + firDiagnostic as KtPsiDiagnostic, + token, + ) + } add(FirErrors.CLASS_LITERAL_LHS_NOT_A_CLASS) { firDiagnostic -> ClassLiteralLhsNotAClassImpl( firDiagnostic as KtPsiDiagnostic, diff --git a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDiagnostics.kt b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDiagnostics.kt index 58c15a07b90..5e75963e894 100644 --- a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDiagnostics.kt +++ b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDiagnostics.kt @@ -1841,6 +1841,10 @@ sealed interface KtFirDiagnostic : KtDiagnosticWithPsi { override val diagnosticClass get() = CallableReferenceToAnnotationConstructor::class } + interface AdaptedCallableReferenceAgainstReflectionType : KtFirDiagnostic { + override val diagnosticClass get() = AdaptedCallableReferenceAgainstReflectionType::class + } + interface ClassLiteralLhsNotAClass : KtFirDiagnostic { override val diagnosticClass get() = ClassLiteralLhsNotAClass::class } diff --git a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDiagnosticsImpl.kt b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDiagnosticsImpl.kt index 7850ba5f2d4..fb4b31500b7 100644 --- a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDiagnosticsImpl.kt +++ b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDiagnosticsImpl.kt @@ -2212,6 +2212,11 @@ internal class CallableReferenceToAnnotationConstructorImpl( token: KtLifetimeToken, ) : KtAbstractFirDiagnostic(firDiagnostic, token), KtFirDiagnostic.CallableReferenceToAnnotationConstructor +internal class AdaptedCallableReferenceAgainstReflectionTypeImpl( + firDiagnostic: KtPsiDiagnostic, + token: KtLifetimeToken, +) : KtAbstractFirDiagnostic(firDiagnostic, token), KtFirDiagnostic.AdaptedCallableReferenceAgainstReflectionType + internal class ClassLiteralLhsNotAClassImpl( firDiagnostic: KtPsiDiagnostic, token: KtLifetimeToken, diff --git a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt index 1a165a09495..bc55b7e6e32 100644 --- a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt +++ b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt @@ -872,6 +872,7 @@ object DIAGNOSTICS_LIST : DiagnosticList("FirErrors") { } val CALLABLE_REFERENCE_LHS_NOT_A_CLASS by error() val CALLABLE_REFERENCE_TO_ANNOTATION_CONSTRUCTOR by error(PositioningStrategy.REFERENCE_BY_QUALIFIED) + val ADAPTED_CALLABLE_REFERENCE_AGAINST_REFLECTION_TYPE by error() val CLASS_LITERAL_LHS_NOT_A_CLASS by error() val NULLABLE_TYPE_IN_CLASS_LITERAL_LHS by error() diff --git a/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt b/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt index 9033f739cdd..6744beb0189 100644 --- a/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt +++ b/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt @@ -488,6 +488,7 @@ object FirErrors { val EXTENSION_IN_CLASS_REFERENCE_NOT_ALLOWED by error1>(SourceElementPositioningStrategies.REFERENCE_BY_QUALIFIED) val CALLABLE_REFERENCE_LHS_NOT_A_CLASS by error0() val CALLABLE_REFERENCE_TO_ANNOTATION_CONSTRUCTOR by error0(SourceElementPositioningStrategies.REFERENCE_BY_QUALIFIED) + val ADAPTED_CALLABLE_REFERENCE_AGAINST_REFLECTION_TYPE by error0() val CLASS_LITERAL_LHS_NOT_A_CLASS by error0() val NULLABLE_TYPE_IN_CLASS_LITERAL_LHS by error0() val EXPRESSION_OF_NULLABLE_TYPE_IN_CLASS_LITERAL_LHS by error1() diff --git a/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirNonSuppressibleErrorNames.kt b/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirNonSuppressibleErrorNames.kt index 21a7ea7135e..95a06444c19 100644 --- a/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirNonSuppressibleErrorNames.kt +++ b/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirNonSuppressibleErrorNames.kt @@ -319,6 +319,7 @@ val FIR_NON_SUPPRESSIBLE_ERROR_NAMES: Set = setOf( "EXTENSION_IN_CLASS_REFERENCE_NOT_ALLOWED", "CALLABLE_REFERENCE_LHS_NOT_A_CLASS", "CALLABLE_REFERENCE_TO_ANNOTATION_CONSTRUCTOR", + "ADAPTED_CALLABLE_REFERENCE_AGAINST_REFLECTION_TYPE", "CLASS_LITERAL_LHS_NOT_A_CLASS", "NULLABLE_TYPE_IN_CLASS_LITERAL_LHS", "EXPRESSION_OF_NULLABLE_TYPE_IN_CLASS_LITERAL_LHS", diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrorsDefaultMessages.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrorsDefaultMessages.kt index 54029a481f4..cc09c195470 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrorsDefaultMessages.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrorsDefaultMessages.kt @@ -72,6 +72,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.ACTUAL_TYPE_ALIAS import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.ACTUAL_TYPE_ALIAS_WITH_COMPLEX_SUBSTITUTION import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.ACTUAL_TYPE_ALIAS_WITH_USE_SITE_VARIANCE import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.ACTUAL_WITHOUT_EXPECT +import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.ADAPTED_CALLABLE_REFERENCE_AGAINST_REFLECTION_TYPE import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.AMBIGUOUS_ACTUALS import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.AMBIGUOUS_ALTERED_ASSIGN import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.AMBIGUOUS_ANNOTATION_ARGUMENT @@ -1474,6 +1475,10 @@ object FirErrorsDefaultMessages : BaseDiagnosticRendererFactory() { ) map.put(CALLABLE_REFERENCE_LHS_NOT_A_CLASS, "Left-hand side of callable reference cannot be a type parameter.") map.put(CALLABLE_REFERENCE_TO_ANNOTATION_CONSTRUCTOR, "Annotation class cannot be instantiated.") + map.put( + ADAPTED_CALLABLE_REFERENCE_AGAINST_REFLECTION_TYPE, + "Adapted callable reference cannot be resolved against reflective types." + ) map.put(CLASS_LITERAL_LHS_NOT_A_CLASS, "Only classes are allowed on the left-hand side of a class literal.") map.put(NULLABLE_TYPE_IN_CLASS_LITERAL_LHS, "Type in a class literal must not be nullable.") diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt index 9be1f5971d7..0261eb394fe 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt @@ -358,6 +358,8 @@ private fun mapInapplicableCandidateError( isError = rootCause.isError ) + is AdaptedCallableReferenceIsUsedWithReflection -> FirErrors.ADAPTED_CALLABLE_REFERENCE_AGAINST_REFLECTION_TYPE.createOn(source) + else -> genericDiagnostic } }.distinct() diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirCallResolver.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirCallResolver.kt index bb525069598..881f87dd0cd 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirCallResolver.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirCallResolver.kt @@ -400,8 +400,9 @@ class FirCallResolver( manager = TowerResolveManager(localCollector), ) } - val isSuccess = result.currentApplicability.isSuccess + val (reducedCandidates, newApplicability) = reduceCandidates(result, callableReferenceAccess.explicitReceiver) + val isSuccess = reducedCandidates.isNotEmpty() && reducedCandidates.all { it.isSuccessful } val applicability = newApplicability ?: result.currentApplicability (callableReferenceAccess.explicitReceiver as? FirResolvedQualifier)?.replaceResolvedToCompanionObject( diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CallableReferenceResolution.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CallableReferenceResolution.kt index 577af77060a..6c15157193d 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CallableReferenceResolution.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CallableReferenceResolution.kt @@ -29,6 +29,7 @@ import org.jetbrains.kotlin.name.StandardClassIds import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemOperation import org.jetbrains.kotlin.resolve.calls.inference.runTransaction import org.jetbrains.kotlin.resolve.calls.tower.isSuccess +import org.jetbrains.kotlin.types.AbstractTypeChecker import org.jetbrains.kotlin.types.expressions.CoercionStrategy import org.jetbrains.kotlin.utils.addToStdlib.shouldNotBeCalled import org.jetbrains.kotlin.utils.exceptions.errorWithAttachment @@ -47,13 +48,31 @@ internal object CheckCallableReferenceExpectedType : CheckerStage() { val fir: FirCallableDeclaration = candidate.symbol.fir as FirCallableDeclaration - val (rawResultingType, callableReferenceAdaptation) = buildReflectionType(fir, resultingReceiverType, candidate, context) + val isExpectedTypeReflectionType = callInfo.expectedType?.isReflectFunctionType(callInfo.session) == true + val (rawResultingType, callableReferenceAdaptation) = buildResultingTypeAndAdaptation( + fir, + resultingReceiverType, + candidate, + context, + // If the input and output types match the expected type but the expected type is a reflection type, and we need an adaptation, + // we want to report AdaptedCallableReferenceIsUsedWithReflection but *not* InapplicableCandidate because + // AdaptedCallableReferenceIsUsedWithReflection has the higher applicability. + // Therefore, we force a reflection type whenever the expected type is a reflection type. + // + // If the input and output types end up not matching, we'll report InapplicableCandidate, regardless of whether the + // expected/actual type is a reflection type. + forceReflectionType = isExpectedTypeReflectionType + ) val resultingType = candidate.substitutor.substituteOrSelf(rawResultingType) - if (callableReferenceAdaptation.needCompatibilityResolveForCallableReference()) { + if (callableReferenceAdaptation != null) { if (!context.session.languageVersionSettings.supportsFeature(LanguageFeature.DisableCompatibilityModeForNewInference)) { sink.reportDiagnostic(LowerPriorityToPreserveCompatibilityDiagnostic) } + + if (isExpectedTypeReflectionType) { + sink.reportDiagnostic(AdaptedCallableReferenceIsUsedWithReflection) + } } candidate.resultingTypeForCallableReference = resultingType @@ -88,11 +107,17 @@ internal object CheckCallableReferenceExpectedType : CheckerStage() { } } -private fun buildReflectionType( +/** + * The resulting type is a reflection type ([FunctionTypeKind.reflectKind]) + * iff the adaptation is `null` or [forceReflectionType]` == true`. + * Otherwise, it's a non-reflection type ([FunctionTypeKind.nonReflectKind]). + */ +private fun buildResultingTypeAndAdaptation( fir: FirCallableDeclaration, receiverType: ConeKotlinType?, candidate: Candidate, - context: ResolutionContext + context: ResolutionContext, + forceReflectionType: Boolean, ): Pair { val returnTypeRef = context.bodyResolveComponents.returnTypeCalculator.tryCalculateReturnType(fir) return when (fir) { @@ -128,7 +153,7 @@ private fun buildReflectionType( ?: FunctionTypeKind.Function return createFunctionType( - if (callableReferenceAdaptation == null) baseFunctionTypeKind.reflectKind() else baseFunctionTypeKind.nonReflectKind(), + if (callableReferenceAdaptation == null || forceReflectionType) baseFunctionTypeKind.reflectKind() else baseFunctionTypeKind.nonReflectKind(), parameters, receiverType = receiverType.takeIf { fir.receiverParameter != null }, rawReturnType = returnType, @@ -145,16 +170,20 @@ internal class CallableReferenceAdaptation( val coercionStrategy: CoercionStrategy, val defaults: Int, val mappedArguments: CallableReferenceMappedArguments, - val suspendConversionStrategy: CallableReferenceConversionStrategy -) - -private fun CallableReferenceAdaptation?.needCompatibilityResolveForCallableReference(): Boolean { - // KT-13934: check containing declaration for companion object - if (this == null) return false - return defaults != 0 || - suspendConversionStrategy != CallableReferenceConversionStrategy.NoConversion || - coercionStrategy != CoercionStrategy.NO_COERCION || - mappedArguments.values.any { it is ResolvedCallArgument.VarargArgument } + val suspendConversionStrategy: CallableReferenceConversionStrategy, +) { + init { + if (AbstractTypeChecker.RUN_SLOW_ASSERTIONS) { + require( + defaults != 0 || + suspendConversionStrategy != CallableReferenceConversionStrategy.NoConversion || + coercionStrategy != CoercionStrategy.NO_COERCION || + mappedArguments.values.any { it is ResolvedCallArgument.VarargArgument } + ) { + "Adaptation must be non-trivial." + } + } + } } private fun BodyResolveComponents.getCallableReferenceAdaptation( diff --git a/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionDiagnostic.kt b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionDiagnostic.kt index b38bef88c12..35947f2ba4a 100644 --- a/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionDiagnostic.kt +++ b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionDiagnostic.kt @@ -146,3 +146,5 @@ class AmbiguousValuesForContextReceiverParameter( ) : ResolutionDiagnostic(INAPPLICABLE) object ResolutionResultOverridesOtherToPreserveCompatibility : ResolutionDiagnostic(RESOLVED) + +object AdaptedCallableReferenceIsUsedWithReflection : ResolutionDiagnostic(RESOLVED_WITH_ERROR) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/adapted/noKFunctionForAdaptation.fir.kt b/compiler/testData/diagnostics/tests/callableReference/adapted/noKFunctionForAdaptation.fir.kt index 2621c349681..9ba9ecbcaaa 100644 --- a/compiler/testData/diagnostics/tests/callableReference/adapted/noKFunctionForAdaptation.fir.kt +++ b/compiler/testData/diagnostics/tests/callableReference/adapted/noKFunctionForAdaptation.fir.kt @@ -3,12 +3,12 @@ fun foo(x: String = "O"): String = x fun bar(x: String = "K"): String = x fun dump(dumpStrategy: String) { - val k0: kotlin.reflect.KFunction0 = returnAdapter(::foo) // Error: ADAPTED_CALLABLE_REFERENCE_AGAINST_REFLECTION_TYPE + val k0: kotlin.reflect.KFunction0 = returnAdapter(::foo) // Error: ADAPTED_CALLABLE_REFERENCE_AGAINST_REFLECTION_TYPE val k1: kotlin.reflect.KFunction0 = ::foo // Should be error here, too val k2: kotlin.reflect.KFunction0 = if (dumpStrategy == "KotlinLike") ::foo else ::bar - val f0: Function0 = returnAdapter(::foo) + val f0: Function0 = returnAdapter(::foo) val f1: Function0 = ::foo val f2: Function0 = if (dumpStrategy == "KotlinLike") ::foo else ::bar } diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/adaptedReferenceAgainstReflectionType.fir.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/adaptedReferenceAgainstReflectionType.fir.kt deleted file mode 100644 index fc0641a74e3..00000000000 --- a/compiler/testData/diagnostics/tests/callableReference/resolve/adaptedReferenceAgainstReflectionType.fir.kt +++ /dev/null @@ -1,27 +0,0 @@ -// !LANGUAGE: -AdaptedCallableReferenceAgainstReflectiveType +DisableCompatibilityModeForNewInference -// !DIAGNOSTICS: -UNUSED_PARAMETER - -import kotlin.reflect.KFunction1 - -fun foo(x: Int): Unit {} // (1) -fun bar(f: KFunction1) {} - -fun test() { - bar(::foo) // OK, foo resolved to (1) -} - -object Scope { - fun foo(x: Int, y: Int = 0): Int = 0 // (2) - - fun test() { - bar(::foo) // Error and foo should be resolved to (2) - } -} - -object Local { - fun baz(x: Int, y: Int = 0): Int = 0 - - fun test() { - bar(::baz) - } -} diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/adaptedReferenceAgainstReflectionType.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/adaptedReferenceAgainstReflectionType.kt index b73b0e06088..934f94ef74b 100644 --- a/compiler/testData/diagnostics/tests/callableReference/resolve/adaptedReferenceAgainstReflectionType.kt +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/adaptedReferenceAgainstReflectionType.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !LANGUAGE: -AdaptedCallableReferenceAgainstReflectiveType +DisableCompatibilityModeForNewInference // !DIAGNOSTICS: -UNUSED_PARAMETER @@ -15,6 +16,7 @@ object Scope { fun test() { bar(::foo) // Error and foo should be resolved to (2) + bar(Scope::foo) // Error and foo should be resolved to (2) } } @@ -25,3 +27,11 @@ object Local { bar(::baz) } } + +object WrongType { + fun foo(x: String, y: Int = 0) {} // (3) + + fun test() { + bar(::foo) // Should resolve to (1) because (3) has wrong type on top of being adapted + } +} diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/adaptedReferenceAgainstReflectionType.txt b/compiler/testData/diagnostics/tests/callableReference/resolve/adaptedReferenceAgainstReflectionType.txt deleted file mode 100644 index d92330a3167..00000000000 --- a/compiler/testData/diagnostics/tests/callableReference/resolve/adaptedReferenceAgainstReflectionType.txt +++ /dev/null @@ -1,23 +0,0 @@ -package - -public fun bar(/*0*/ f: kotlin.reflect.KFunction1): kotlin.Unit -public fun foo(/*0*/ x: kotlin.Int): kotlin.Unit -public fun test(): kotlin.Unit - -public object Local { - private constructor Local() - public final fun baz(/*0*/ x: kotlin.Int, /*1*/ y: kotlin.Int = ...): kotlin.Int - 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 final fun test(): kotlin.Unit - 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*/ x: kotlin.Int, /*1*/ y: kotlin.Int = ...): kotlin.Int - 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/callableReference/resolve/compatibilityWarningOnReferenceAgainstReflectiveType.fir.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/compatibilityWarningOnReferenceAgainstReflectiveType.fir.kt index 597c63f7b05..cb3eb838ebb 100644 --- a/compiler/testData/diagnostics/tests/callableReference/resolve/compatibilityWarningOnReferenceAgainstReflectiveType.fir.kt +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/compatibilityWarningOnReferenceAgainstReflectiveType.fir.kt @@ -15,6 +15,7 @@ object Scope { fun test() { bar(::foo) + bar(Scope::foo) } } @@ -22,6 +23,14 @@ object Local { fun baz(x: Int, y: Int = 0): Int = 0 fun test() { - bar(::baz) + bar(::baz) } } + +object WrongType { + fun foo(x: String, y: Int = 0) {} // (3) + + fun test() { + bar(::foo) // Should resolve to (1) because (3) has wrong type on top of being adapted + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/compatibilityWarningOnReferenceAgainstReflectiveType.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/compatibilityWarningOnReferenceAgainstReflectiveType.kt index f094fa32a12..48f3c35b20d 100644 --- a/compiler/testData/diagnostics/tests/callableReference/resolve/compatibilityWarningOnReferenceAgainstReflectiveType.kt +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/compatibilityWarningOnReferenceAgainstReflectiveType.kt @@ -15,6 +15,7 @@ object Scope { fun test() { bar(::foo) + bar(Scope::foo) } } @@ -25,3 +26,11 @@ object Local { bar(::baz) } } + +object WrongType { + fun foo(x: String, y: Int = 0) {} // (3) + + fun test() { + bar(::foo) // Should resolve to (1) because (3) has wrong type on top of being adapted + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/compatibilityWarningOnReferenceAgainstReflectiveType.txt b/compiler/testData/diagnostics/tests/callableReference/resolve/compatibilityWarningOnReferenceAgainstReflectiveType.txt deleted file mode 100644 index d92330a3167..00000000000 --- a/compiler/testData/diagnostics/tests/callableReference/resolve/compatibilityWarningOnReferenceAgainstReflectiveType.txt +++ /dev/null @@ -1,23 +0,0 @@ -package - -public fun bar(/*0*/ f: kotlin.reflect.KFunction1): kotlin.Unit -public fun foo(/*0*/ x: kotlin.Int): kotlin.Unit -public fun test(): kotlin.Unit - -public object Local { - private constructor Local() - public final fun baz(/*0*/ x: kotlin.Int, /*1*/ y: kotlin.Int = ...): kotlin.Int - 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 final fun test(): kotlin.Unit - 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*/ x: kotlin.Int, /*1*/ y: kotlin.Int = ...): kotlin.Int - 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 -}