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 ee12de24110..edfa9768c1b 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirCallResolver.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirCallResolver.kt @@ -835,7 +835,7 @@ class AllCandidatesCollector( } // We want to get candidates at all tower levels. - override fun shouldStopAtTheLevel(group: TowerGroup): Boolean = false + override fun shouldStopAtTheGroup(group: TowerGroup): Boolean = false val allCandidates: List get() = allCandidatesSet.toList() 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 221260b2e64..aa12d4a9a14 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 @@ -7,8 +7,8 @@ package org.jetbrains.kotlin.fir.resolve.calls import org.jetbrains.kotlin.KtFakeSourceElementKind import org.jetbrains.kotlin.KtSourceElement -import org.jetbrains.kotlin.fir.FirElement -import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.config.LanguageFeature +import org.jetbrains.kotlin.fir.* import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.fir.declarations.utils.isSuspend import org.jetbrains.kotlin.fir.expressions.FirAnnotation @@ -24,8 +24,6 @@ import org.jetbrains.kotlin.fir.resolve.inference.extractInputOutputTypesFromCal import org.jetbrains.kotlin.fir.types.isSuspendFunctionType import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol import org.jetbrains.kotlin.fir.types.* -import org.jetbrains.kotlin.fir.unwrapFakeOverrides -import org.jetbrains.kotlin.fir.visibilityChecker import org.jetbrains.kotlin.fir.visitors.FirTransformer import org.jetbrains.kotlin.fir.visitors.FirVisitor import org.jetbrains.kotlin.name.StandardClassIds @@ -53,7 +51,9 @@ internal object CheckCallableReferenceExpectedType : CheckerStage() { val resultingType = candidate.substitutor.substituteOrSelf(rawResultingType) if (callableReferenceAdaptation.needCompatibilityResolveForCallableReference()) { - sink.reportDiagnostic(LowerPriorityToPreserveCompatibilityDiagnostic) + if (!context.session.languageVersionSettings.supportsFeature(LanguageFeature.DisableCompatibilityModeForNewInference)) { + sink.reportDiagnostic(LowerPriorityToPreserveCompatibilityDiagnostic) + } } candidate.resultingTypeForCallableReference = resultingType diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CandidateCollector.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CandidateCollector.kt index da5a0a3a40a..efdeb64a599 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CandidateCollector.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/CandidateCollector.kt @@ -8,8 +8,9 @@ package org.jetbrains.kotlin.fir.resolve.calls import org.jetbrains.kotlin.fir.resolve.BodyResolveComponents import org.jetbrains.kotlin.fir.resolve.calls.tower.TowerGroup import org.jetbrains.kotlin.resolve.calls.tower.CandidateApplicability +import org.jetbrains.kotlin.resolve.calls.tower.CandidateApplicability.DSL_SCOPE_VIOLATION +import org.jetbrains.kotlin.resolve.calls.tower.CandidateApplicability.K2_SYNTHETIC_RESOLVED import org.jetbrains.kotlin.resolve.calls.tower.isSuccess -import org.jetbrains.kotlin.resolve.calls.tower.shouldStopResolve open class CandidateCollector( val components: BodyResolveComponents, @@ -48,10 +49,12 @@ open class CandidateCollector( fun bestCandidates(): List = candidates - open fun shouldStopAtTheLevel(group: TowerGroup): Boolean = - currentApplicability.shouldStopResolve && bestGroup < group + open fun shouldStopAtTheGroup(group: TowerGroup): Boolean = + shouldStopResolve && bestGroup < group - fun isSuccess(): Boolean { - return currentApplicability.isSuccess - } + private val shouldStopResolve: Boolean + get() = currentApplicability == DSL_SCOPE_VIOLATION || currentApplicability >= K2_SYNTHETIC_RESOLVED + + val isSuccess: Boolean + get() = currentApplicability.isSuccess } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionStages.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionStages.kt index 4e2d0caf1fe..9f3213a07d4 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionStages.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolutionStages.kt @@ -504,7 +504,7 @@ internal object EagerResolveOfCallableReferences : CheckerStage() { internal object DiscriminateSynthetics : CheckerStage() { override suspend fun check(candidate: Candidate, callInfo: CallInfo, sink: CheckerSink, context: ResolutionContext) { if (candidate.symbol is SyntheticSymbol) { - sink.reportDiagnostic(ResolvedWithLowPriority) + sink.reportDiagnostic(ResolvedWithSynthetic) } } } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirInvokeResolveTowerExtension.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirInvokeResolveTowerExtension.kt index dddb428a099..5157def6c8f 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirInvokeResolveTowerExtension.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirInvokeResolveTowerExtension.kt @@ -5,7 +5,6 @@ package org.jetbrains.kotlin.fir.resolve.calls.tower -import org.jetbrains.kotlin.fir.declarations.FirCallableDeclaration import org.jetbrains.kotlin.fir.expressions.FirExpression import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression import org.jetbrains.kotlin.fir.expressions.FirResolvedQualifier @@ -316,7 +315,7 @@ private fun BodyResolveComponents.createExplicitReceiverForInvokeByCallable( explicitReceiver = info.explicitReceiver } - if (candidate.currentApplicability == CandidateApplicability.PROPERTY_AS_OPERATOR) { + if (candidate.currentApplicability == CandidateApplicability.K2_PROPERTY_AS_OPERATOR) { nonFatalDiagnostics.add(ConePropertyAsOperator(candidate.symbol as FirPropertySymbol)) } }.build().let(::transformQualifiedAccessUsingSmartcastInfo) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirTowerResolveTask.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirTowerResolveTask.kt index a88edca9215..fb632a27a91 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirTowerResolveTask.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirTowerResolveTask.kt @@ -164,7 +164,7 @@ internal abstract class FirBaseTowerResolveTask( finalGroup, towerLevel ) - if (collector.isSuccess()) onSuccessfulLevel(finalGroup) + if (collector.isSuccess) onSuccessfulLevel(finalGroup) return result == ProcessResult.SCOPE_EMPTY } } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/TowerLevelHandler.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/TowerLevelHandler.kt index abbc6119404..3e8714d9cf6 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/TowerLevelHandler.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/TowerLevelHandler.kt @@ -45,7 +45,7 @@ internal class TowerLevelHandler { CallKind.VariableAccess -> { processResult += towerLevel.processPropertiesByName(info, processor) - if (!collector.isSuccess() && towerLevel is ScopeTowerLevel && !towerLevel.areThereExtensionReceiverOptions()) { + if (!collector.isSuccess && towerLevel is ScopeTowerLevel && !towerLevel.areThereExtensionReceiverOptions()) { processResult += towerLevel.processObjectsByName(info, processor) } } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/TowerResolveManager.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/TowerResolveManager.kt index 94239f47252..ff78c868305 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/TowerResolveManager.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/TowerResolveManager.kt @@ -17,7 +17,7 @@ import kotlin.coroutines.resume class TowerResolveManager private constructor(private val shouldStopAtTheLevel: (TowerGroup) -> Boolean) { - constructor(collector: CandidateCollector) : this(collector::shouldStopAtTheLevel) + constructor(collector: CandidateCollector) : this(collector::shouldStopAtTheGroup) private val queue = PriorityQueue() diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt index aea9979ad8a..4d49db0dd01 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt @@ -149,7 +149,7 @@ class FirCallCompletionResultsWriterTransformer( result.replaceContextReceiverArguments(subCandidate.contextReceiverArguments()) - if (result is FirPropertyAccessExpressionImpl && calleeReference.candidate.currentApplicability == CandidateApplicability.PROPERTY_AS_OPERATOR) { + if (result is FirPropertyAccessExpressionImpl && calleeReference.candidate.currentApplicability == CandidateApplicability.K2_PROPERTY_AS_OPERATOR) { result.nonFatalDiagnostics.add(ConePropertyAsOperator(calleeReference.candidate.symbol as FirPropertySymbol)) } 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 f8586f96402..068bc2f45a5 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 @@ -84,6 +84,8 @@ object VisibilityError : ResolutionDiagnostic(VISIBILITY_ERROR) object ResolvedWithLowPriority : ResolutionDiagnostic(RESOLVED_LOW_PRIORITY) +object ResolvedWithSynthetic : ResolutionDiagnostic(K2_SYNTHETIC_RESOLVED) + class InapplicableWrongReceiver( val expectedType: ConeKotlinType? = null, val actualType: ConeKotlinType? = null, @@ -123,7 +125,7 @@ class OperatorCallOfNonOperatorFunction(val function: FirNamedFunctionSymbol) : class InferenceError(val constraintError: ConstraintSystemError) : ResolutionDiagnostic(constraintError.applicability) class Unsupported(val message: String, val source: KtSourceElement? = null) : ResolutionDiagnostic(UNSUPPORTED) -object PropertyAsOperator : ResolutionDiagnostic(PROPERTY_AS_OPERATOR) +object PropertyAsOperator : ResolutionDiagnostic(K2_PROPERTY_AS_OPERATOR) class DslScopeViolation(val calleeSymbol: FirBasedSymbol<*>) : ResolutionDiagnostic(DSL_SCOPE_VIOLATION) diff --git a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/tower/CandidateApplicability.kt b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/tower/CandidateApplicability.kt index 36731392dd3..62ec410574a 100644 --- a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/tower/CandidateApplicability.kt +++ b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/tower/CandidateApplicability.kt @@ -26,14 +26,12 @@ enum class CandidateApplicability { // Below has isSuccess = true RESOLVED_LOW_PRIORITY, - PROPERTY_AS_OPERATOR, // using property of functional type as an operator. From resolution perspective, this is considered successful. + K2_PROPERTY_AS_OPERATOR, // using property of functional type as an operator. From resolution perspective, this is considered successful. RESOLVED_NEED_PRESERVE_COMPATIBILITY, // call resolved successfully, but using new features that changes resolve + K2_SYNTHETIC_RESOLVED, // used in K2 for (Java) synthetic discrimination at the same level RESOLVED_WITH_ERROR, // call has error, but it is still successful from resolution perspective RESOLVED, // call success or has uncompleted inference or in other words possible successful candidate } val CandidateApplicability.isSuccess: Boolean get() = this >= CandidateApplicability.RESOLVED_LOW_PRIORITY - -val CandidateApplicability.shouldStopResolve: Boolean - get() = this >= CandidateApplicability.DSL_SCOPE_VIOLATION 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 a7cc029bff1..ff65b7f61e1 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 @@ -150,7 +150,6 @@ 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(UNSTABLE_SMARTCAST) object HiddenExtensionRelatedToDynamicTypes : ResolutionDiagnostic(HIDDEN) object HiddenDescriptor : ResolutionDiagnostic(HIDDEN) diff --git a/compiler/testData/codegen/box/suspendConversion/suspendConversionCompatibility.kt b/compiler/testData/codegen/box/suspendConversion/suspendConversionCompatibility.kt index 7297baf4949..06cf66fa177 100644 --- a/compiler/testData/codegen/box/suspendConversion/suspendConversionCompatibility.kt +++ b/compiler/testData/codegen/box/suspendConversion/suspendConversionCompatibility.kt @@ -1,8 +1,6 @@ // !LANGUAGE: +SuspendConversion // !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION // WITH_STDLIB -// IGNORE_BACKEND_FIR: JVM_IR -// FIR status: java.lang.Integer cannot be cast to java.lang.String object Test1 { fun foo(f: () -> Unit) {} diff --git a/compiler/testData/diagnostics/tests/callableReference/correctCandidateWithCompatibilityForSeveralCandidates.fir.kt b/compiler/testData/diagnostics/tests/callableReference/correctCandidateWithCompatibilityForSeveralCandidates.fir.kt index ce4b6ed6bea..222fae1c135 100644 --- a/compiler/testData/diagnostics/tests/callableReference/correctCandidateWithCompatibilityForSeveralCandidates.fir.kt +++ b/compiler/testData/diagnostics/tests/callableReference/correctCandidateWithCompatibilityForSeveralCandidates.fir.kt @@ -15,7 +15,7 @@ object Scope { fun test() { // Despite the fact ::bar is resolved with compatibility warning, it's important not to propagate it to the outer call val result = foo(::bar) - result + result } } } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/callableReference/referenceAdaptationCompatibility.fir.kt b/compiler/testData/diagnostics/tests/callableReference/referenceAdaptationCompatibility.fir.kt index 1670fcd336d..173c8a261d7 100644 --- a/compiler/testData/diagnostics/tests/callableReference/referenceAdaptationCompatibility.fir.kt +++ b/compiler/testData/diagnostics/tests/callableReference/referenceAdaptationCompatibility.fir.kt @@ -9,7 +9,7 @@ object Test1 { fun test() { val result = foo(::bar) - result + result } } } @@ -36,7 +36,7 @@ object Test3 { fun test() { val result = foo(::bar) - result + result } } } diff --git a/compiler/testData/diagnostics/tests/funInterface/noCompatibilityResolveForFunInterfaces.fir.kt b/compiler/testData/diagnostics/tests/funInterface/noCompatibilityResolveForFunInterfaces.fir.kt index 1b84b91831d..f54e65788b0 100644 --- a/compiler/testData/diagnostics/tests/funInterface/noCompatibilityResolveForFunInterfaces.fir.kt +++ b/compiler/testData/diagnostics/tests/funInterface/noCompatibilityResolveForFunInterfaces.fir.kt @@ -12,7 +12,7 @@ object Test1 { fun foo(r: KRunnable) {} fun test(f: () -> Unit) { - foo(f) + foo(f) } } } diff --git a/compiler/testData/diagnostics/tests/j+k/sam/compatibilityResolveToOuterScopeForKotlinFunctions.fir.kt b/compiler/testData/diagnostics/tests/j+k/sam/compatibilityResolveToOuterScopeForKotlinFunctions.fir.kt index 58e01ebe796..72c8bb283de 100644 --- a/compiler/testData/diagnostics/tests/j+k/sam/compatibilityResolveToOuterScopeForKotlinFunctions.fir.kt +++ b/compiler/testData/diagnostics/tests/j+k/sam/compatibilityResolveToOuterScopeForKotlinFunctions.fir.kt @@ -18,7 +18,7 @@ object Test1 { fun foo(r: Runnable) {} fun test(f: () -> Unit) { - foo(f) + foo(f) } } } @@ -65,7 +65,7 @@ object Test5 { fun foo(r: Runnable) {} fun test() { - foo { } + foo { } } } } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/suspendConversion/suspendAndFunConversionInDisabledMode.fir.kt b/compiler/testData/diagnostics/tests/suspendConversion/suspendAndFunConversionInDisabledMode.fir.kt index 99e9f633398..e3d79d82558 100644 --- a/compiler/testData/diagnostics/tests/suspendConversion/suspendAndFunConversionInDisabledMode.fir.kt +++ b/compiler/testData/diagnostics/tests/suspendConversion/suspendAndFunConversionInDisabledMode.fir.kt @@ -12,7 +12,7 @@ object Test1 { fun call(r: SuspendRunnable) {} fun bar(f: () -> Unit) { - call(f) + call(f) } } } diff --git a/compiler/testData/diagnostics/tests/suspendConversion/suspendConversionCompatibility.fir.kt b/compiler/testData/diagnostics/tests/suspendConversion/suspendConversionCompatibility.fir.kt index 94f91433563..517e44e34d7 100644 --- a/compiler/testData/diagnostics/tests/suspendConversion/suspendConversionCompatibility.fir.kt +++ b/compiler/testData/diagnostics/tests/suspendConversion/suspendConversionCompatibility.fir.kt @@ -22,7 +22,7 @@ object Test2 { fun test() { val result = foo(::bar) - result + result } } } diff --git a/compiler/testData/diagnostics/tests/suspendConversion/suspendConversionCompatibilityInDisabledMode.fir.kt b/compiler/testData/diagnostics/tests/suspendConversion/suspendConversionCompatibilityInDisabledMode.fir.kt index 12ca5a79983..b6dd4dd0a23 100644 --- a/compiler/testData/diagnostics/tests/suspendConversion/suspendConversionCompatibilityInDisabledMode.fir.kt +++ b/compiler/testData/diagnostics/tests/suspendConversion/suspendConversionCompatibilityInDisabledMode.fir.kt @@ -29,7 +29,7 @@ object Test2 { fun test() { val result = foo(::bar) - result + result } } } diff --git a/compiler/testData/diagnostics/testsWithStdLib/targetedBuiltIns/blackListed.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/targetedBuiltIns/blackListed.fir.kt index 96b2e931352..1d1bd1f39a2 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/targetedBuiltIns/blackListed.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/targetedBuiltIns/blackListed.fir.kt @@ -17,5 +17,5 @@ fun bar(x: MutableList, y: java.util.ArrayList, z: A) { x.sort { a, b -> a.length - b.length } y.sort { a, b -> a.length - b.length } - z.sort { a, b -> a.length - b.length } + z.sort { a, b -> a.length - b.length } }