From 9e9e0211eb175ce8c0c2480fb628d5d47b92eebe Mon Sep 17 00:00:00 2001 From: Victor Petukhov Date: Fri, 11 Feb 2022 11:37:48 +0300 Subject: [PATCH] [FE] Check if type variable is fixed into an empty intersection type and report resolution warnings/errors if needed (completion stage) ^KT-51221 Fixed --- .../kotlin/fir/types/ConeInferenceContext.kt | 5 +++++ .../resolve/inference/InferenceComponents.kt | 2 +- .../inference/BuilderInferenceSession.kt | 4 +++- .../tower/KotlinResolutionCallbacksImpl.kt | 5 +++-- .../KotlinResolutionStatelessCallbacksImpl.kt | 2 +- .../tower/StubTypesBasedInferenceSession.kt | 7 +++++-- .../ConstraintSystemCompletionContext.kt | 9 +++++--- .../model/ConstraintPositionAndErrors.kt | 17 ++++++++++++++- .../model/NewConstraintSystemImpl.kt | 21 +++++++++++++++++-- .../calls/tower/CandidateApplicability.kt | 1 + .../ClassicTypeSystemContextForCS.kt | 5 +++-- .../candidate/ResolutionCandidate.kt | 3 ++- .../components/SimpleConstraintSystemImpl.kt | 8 +++++-- .../calls/model/SimpleCandidateFactory.kt | 5 ++++- .../kotlin/config/LanguageVersionSettings.kt | 1 + .../kotlin/types/model/TypeSystemContext.kt | 13 ++++++++++++ .../types/checker/ClassicTypeSystemContext.kt | 4 ++++ 17 files changed, 93 insertions(+), 19 deletions(-) diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt index 9def9ffe1ff..a0559dfad7d 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt @@ -272,6 +272,11 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo return ConeStubTypeForTypeVariableInSubtyping(typeVariable, ConeNullability.create(typeVariable.defaultType().isMarkedNullable())) } + override fun KotlinTypeMarker.isFinal(): Boolean { + require(this is ConeKotlinType) + return !this.canHaveSubtypes(session) + } + override fun KotlinTypeMarker.removeAnnotations(): KotlinTypeMarker { require(this is ConeKotlinType) return withAttributes(ConeAttributes.Empty) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/InferenceComponents.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/InferenceComponents.kt index c9271262ee9..bab41850a5b 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/InferenceComponents.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/InferenceComponents.kt @@ -37,7 +37,7 @@ class InferenceComponents(val session: FirSession) : FirSessionComponent { val constraintSystemFactory = ConstraintSystemFactory() fun createConstraintSystem(): NewConstraintSystemImpl { - return NewConstraintSystemImpl(injector, typeContext) + return NewConstraintSystemImpl(injector, typeContext, session.languageVersionSettings) } inner class ConstraintSystemFactory { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/BuilderInferenceSession.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/BuilderInferenceSession.kt index c8f8ab54138..10d33792b30 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/BuilderInferenceSession.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/inference/BuilderInferenceSession.kt @@ -61,7 +61,9 @@ class BuilderInferenceSession( psiCallResolver, postponedArgumentsAnalyzer, kotlinConstraintSystemCompleter, callComponents, builtIns ) { private lateinit var lambda: ResolvedLambdaAtom - private val commonSystem = NewConstraintSystemImpl(callComponents.constraintInjector, builtIns, callComponents.kotlinTypeRefiner) + private val commonSystem = NewConstraintSystemImpl( + callComponents.constraintInjector, builtIns, callComponents.kotlinTypeRefiner, topLevelCallContext.languageVersionSettings + ) init { if (topLevelCallContext.inferenceSession is StubTypesBasedInferenceSession<*>) { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionCallbacksImpl.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionCallbacksImpl.kt index 64b90c103ca..20ccafcd28b 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionCallbacksImpl.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionCallbacksImpl.kt @@ -103,8 +103,9 @@ class KotlinResolutionCallbacksImpl( ) as KotlinType } - override fun createEmptyConstraintSystem(): NewConstraintSystem = - NewConstraintSystemImpl(callComponents.constraintInjector, callComponents.builtIns, callComponents.kotlinTypeRefiner) + override fun createEmptyConstraintSystem(): NewConstraintSystem = NewConstraintSystemImpl( + callComponents.constraintInjector, callComponents.builtIns, callComponents.kotlinTypeRefiner, callComponents.languageVersionSettings + ) override fun resolveCallableReferenceArgument( argument: CallableReferenceKotlinCallArgument, diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionStatelessCallbacksImpl.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionStatelessCallbacksImpl.kt index bb30295019d..b9aae5c97d3 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionStatelessCallbacksImpl.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionStatelessCallbacksImpl.kt @@ -113,7 +113,7 @@ class KotlinResolutionStatelessCallbacksImpl( constraintInjector: ConstraintInjector, builtIns: KotlinBuiltIns ): SimpleConstraintSystem { return if (languageVersionSettings.getFlag(AnalysisFlags.constraintSystemForOverloadResolution).forNewInference()) - SimpleConstraintSystemImpl(constraintInjector, builtIns, kotlinTypeRefiner) + SimpleConstraintSystemImpl(constraintInjector, builtIns, kotlinTypeRefiner, languageVersionSettings) else ConstraintSystemBuilderImpl.forSpecificity() } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/StubTypesBasedInferenceSession.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/StubTypesBasedInferenceSession.kt index 1f62d96428a..e4ca94ef1d6 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/StubTypesBasedInferenceSession.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/StubTypesBasedInferenceSession.kt @@ -120,7 +120,9 @@ abstract class StubTypesBasedInferenceSession( for (callInfo in listOf(goodCandidate, badCandidate)) { val atomsToAnalyze = mutableListOf(callInfo.callResolutionResult) - val system = NewConstraintSystemImpl(callComponents.constraintInjector, builtIns, callComponents.kotlinTypeRefiner).apply { + val system = NewConstraintSystemImpl( + callComponents.constraintInjector, builtIns, callComponents.kotlinTypeRefiner, callComponents.languageVersionSettings + ).apply { addOtherSystem(callInfo.callResolutionResult.constraintSystem.getBuilder().currentStorage()) /* * This is needed for very stupid case, when we have some delegate with good `getValue` and bad `setValue` that @@ -159,7 +161,8 @@ abstract class StubTypesBasedInferenceSession( val commonSystem = NewConstraintSystemImpl( callComponents.constraintInjector, builtIns, - callComponents.kotlinTypeRefiner + callComponents.kotlinTypeRefiner, + callComponents.languageVersionSettings ).apply { addOtherSystem(currentConstraintSystem()) } diff --git a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintSystemCompletionContext.kt b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintSystemCompletionContext.kt index b81b3886d5f..b36f2b6d974 100644 --- a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintSystemCompletionContext.kt +++ b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintSystemCompletionContext.kt @@ -8,9 +8,7 @@ package org.jetbrains.kotlin.resolve.calls.inference.components import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.config.LanguageVersionSettings import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilder -import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintSystemError -import org.jetbrains.kotlin.resolve.calls.inference.model.FixVariableConstraintPosition -import org.jetbrains.kotlin.resolve.calls.inference.model.VariableWithConstraints +import org.jetbrains.kotlin.resolve.calls.inference.model.* import org.jetbrains.kotlin.resolve.calls.model.PostponedAtomWithRevisableExpectedType import org.jetbrains.kotlin.resolve.calls.model.PostponedResolvedAtomMarker import org.jetbrains.kotlin.types.model.KotlinTypeMarker @@ -110,4 +108,9 @@ abstract class ConstraintSystemCompletionContext : VariableFixationFinder.Contex private fun findPostponedArgumentWithFixedInputTypes( postponedArguments: List ) = postponedArguments.firstOrNull { argument -> argument.inputTypes.all { containsOnlyFixedVariables(it) } } + + fun List.extractUpperTypes(): List = + filter { constraint -> + constraint.kind == ConstraintKind.UPPER && !constraint.type.contains { !it.typeConstructor().isClassTypeConstructor() } + }.map { it.type } } diff --git a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/model/ConstraintPositionAndErrors.kt b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/model/ConstraintPositionAndErrors.kt index 8c326c1104a..6382b2bedbd 100644 --- a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/model/ConstraintPositionAndErrors.kt +++ b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/model/ConstraintPositionAndErrors.kt @@ -113,7 +113,7 @@ class NewConstraintWarning( override val lowerType: KotlinTypeMarker, override val upperType: KotlinTypeMarker, override val position: IncorporationConstraintPosition, -) : ConstraintSystemError(RESOLVED), NewConstraintMismatch +) : ConstraintSystemError(RESOLVED_WITH_WARNING), NewConstraintMismatch class CapturedTypeFromSubtyping( val typeVariable: TypeVariableMarker, @@ -135,6 +135,21 @@ class ConstrainingTypeIsError( class NoSuccessfulFork(val position: IncorporationConstraintPosition) : ConstraintSystemError(INAPPLICABLE) +sealed interface InferredEmptyIntersection { + val incompatibleTypes: Collection + val typeVariable: TypeVariableMarker +} + +class InferredEmptyIntersectionWarning( + override val incompatibleTypes: Collection, + override val typeVariable: TypeVariableMarker +) : ConstraintSystemError(RESOLVED_WITH_WARNING), InferredEmptyIntersection + +class InferredEmptyIntersectionError( + override val incompatibleTypes: Collection, + override val typeVariable: TypeVariableMarker +) : ConstraintSystemError(INAPPLICABLE), InferredEmptyIntersection + class OnlyInputTypesDiagnostic(val typeVariable: TypeVariableMarker) : ConstraintSystemError(INAPPLICABLE) object LowerPriorityToPreserveCompatibility : ConstraintSystemError(RESOLVED_NEED_PRESERVE_COMPATIBILITY) diff --git a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/model/NewConstraintSystemImpl.kt b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/model/NewConstraintSystemImpl.kt index d6ea7cae4a9..df64d7df10f 100644 --- a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/model/NewConstraintSystemImpl.kt +++ b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/model/NewConstraintSystemImpl.kt @@ -5,6 +5,8 @@ package org.jetbrains.kotlin.resolve.calls.inference.model +import org.jetbrains.kotlin.config.LanguageFeature +import org.jetbrains.kotlin.config.LanguageVersionSettings import org.jetbrains.kotlin.resolve.calls.components.PostponedArgumentsAnalyzerContext import org.jetbrains.kotlin.resolve.calls.inference.* import org.jetbrains.kotlin.resolve.calls.inference.components.* @@ -19,7 +21,8 @@ import kotlin.math.max class NewConstraintSystemImpl( private val constraintInjector: ConstraintInjector, - val typeSystemContext: TypeSystemInferenceExtensionContext + val typeSystemContext: TypeSystemInferenceExtensionContext, + private val languageVersionSettings: LanguageVersionSettings, ) : ConstraintSystemCompletionContext(), TypeSystemInferenceExtensionContext by typeSystemContext, NewConstraintSystem, @@ -408,6 +411,8 @@ class NewConstraintSystemImpl( ) = with(utilContext) { checkState(State.BUILDING, State.COMPLETION) + checkInferredEmptyIntersection(variable, resultType) + constraintInjector.addInitialEqualityConstraint(this@NewConstraintSystemImpl, variable.defaultType(), resultType, position) /* @@ -434,7 +439,19 @@ class NewConstraintSystemImpl( doPostponedComputationsIfAllVariablesAreFixed() } - @OptIn(ExperimentalStdlibApi::class) + private fun checkInferredEmptyIntersection(variable: TypeVariableMarker, resultType: KotlinTypeMarker) { + val intersectionTypeConstructor = resultType.typeConstructor().takeIf { it is IntersectionTypeConstructorMarker } ?: return + val isInferredEmptyIntersectionForbidden = + languageVersionSettings.supportsFeature(LanguageFeature.ForbidInferringTypeVariablesIntoEmptyIntersection) + val intersectionComponents = intersectionTypeConstructor.supertypes() + + if (intersectionComponents.isEmptyIntersection()) { + val errorFactory = + if (isInferredEmptyIntersectionForbidden) ::InferredEmptyIntersectionError else ::InferredEmptyIntersectionWarning + addError(errorFactory(intersectionComponents, variable)) + } + } + private fun checkMissedConstraints() { val constraintSystem = this@NewConstraintSystemImpl val errorsByMissedConstraints = buildList { 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..dfc0cedde30 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 @@ -29,6 +29,7 @@ enum class CandidateApplicability { 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 RESOLVED_WITH_ERROR, // call has error, but it is still successful from resolution perspective + RESOLVED_WITH_WARNING, // generally call is successful, but there are additional resolution warnings (e.g. for deprecation something) RESOLVED, // call success or has uncompleted inference or in other words possible successful candidate } diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ClassicTypeSystemContextForCS.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ClassicTypeSystemContextForCS.kt index 8e5e15c1787..0081240c8e1 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ClassicTypeSystemContextForCS.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ClassicTypeSystemContextForCS.kt @@ -120,7 +120,8 @@ private inline fun Any?.errorMessage(): String { fun NewConstraintSystemImpl( constraintInjector: ConstraintInjector, builtIns: KotlinBuiltIns, - kotlinTypeRefiner: KotlinTypeRefiner + kotlinTypeRefiner: KotlinTypeRefiner, + languageVersionSettings: LanguageVersionSettings ): NewConstraintSystemImpl { - return NewConstraintSystemImpl(constraintInjector, ClassicTypeSystemContextForCS(builtIns, kotlinTypeRefiner)) + return NewConstraintSystemImpl(constraintInjector, ClassicTypeSystemContextForCS(builtIns, kotlinTypeRefiner), languageVersionSettings) } diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/candidate/ResolutionCandidate.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/candidate/ResolutionCandidate.kt index 54d16186f5e..6c3c1bb7f17 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/candidate/ResolutionCandidate.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/candidate/ResolutionCandidate.kt @@ -79,7 +79,8 @@ sealed class ResolutionCandidate : Candidate, KotlinDiagnosticsHolder { fun getSystem(): NewConstraintSystem { if (newSystem == null) { newSystem = NewConstraintSystemImpl( - callComponents.constraintInjector, callComponents.builtIns, callComponents.kotlinTypeRefiner + callComponents.constraintInjector, callComponents.builtIns, + callComponents.kotlinTypeRefiner, callComponents.languageVersionSettings ) if (baseSystem != null) { newSystem!!.addOtherSystem(baseSystem!!) diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/SimpleConstraintSystemImpl.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/SimpleConstraintSystemImpl.kt index b42882159db..96a5ef5b341 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/SimpleConstraintSystemImpl.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/SimpleConstraintSystemImpl.kt @@ -17,6 +17,7 @@ package org.jetbrains.kotlin.resolve.calls.inference.components import org.jetbrains.kotlin.builtins.KotlinBuiltIns +import org.jetbrains.kotlin.config.LanguageVersionSettings import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor import org.jetbrains.kotlin.resolve.calls.components.ClassicTypeSystemContextForCS import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilder @@ -33,9 +34,12 @@ import org.jetbrains.kotlin.types.typeUtil.asTypeProjection class SimpleConstraintSystemImpl( constraintInjector: ConstraintInjector, builtIns: KotlinBuiltIns, - kotlinTypeRefiner: KotlinTypeRefiner + kotlinTypeRefiner: KotlinTypeRefiner, + languageVersionSettings: LanguageVersionSettings ) : SimpleConstraintSystem { - val system = NewConstraintSystemImpl(constraintInjector, ClassicTypeSystemContextForCS(builtIns, kotlinTypeRefiner)) + val system = NewConstraintSystemImpl( + constraintInjector, ClassicTypeSystemContextForCS(builtIns, kotlinTypeRefiner), languageVersionSettings + ) val csBuilder: ConstraintSystemBuilder = system.getBuilder() diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/SimpleCandidateFactory.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/SimpleCandidateFactory.kt index d807d16312a..aa18c5858cf 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/SimpleCandidateFactory.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/SimpleCandidateFactory.kt @@ -33,7 +33,10 @@ class SimpleCandidateFactory( val baseSystem: ConstraintStorage init { - val baseSystem = NewConstraintSystemImpl(callComponents.constraintInjector, callComponents.builtIns, callComponents.kotlinTypeRefiner) + val baseSystem = NewConstraintSystemImpl( + callComponents.constraintInjector, callComponents.builtIns, + callComponents.kotlinTypeRefiner, callComponents.languageVersionSettings + ) if (!inferenceSession.resolveReceiverIndependently()) { baseSystem.addSubsystemFromArgument(kotlinCall.explicitReceiver) baseSystem.addSubsystemFromArgument(kotlinCall.dispatchReceiverForInvokeExtension) diff --git a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt index 2ea81cf37e6..41810fe4810 100644 --- a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt +++ b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt @@ -261,6 +261,7 @@ enum class LanguageFeature( ForbidUsingExtensionPropertyTypeParameterInDelegate(KOTLIN_1_8, kind = BUG_FIX), ModifierNonBuiltinSuspendFunError(KOTLIN_1_8), SynchronizedSuspendError(KOTLIN_1_8), + ForbidInferringTypeVariablesIntoEmptyIntersection(KOTLIN_1_8, kind = BUG_FIX), // KT-51221 // 1.9 diff --git a/core/compiler.common/src/org/jetbrains/kotlin/types/model/TypeSystemContext.kt b/core/compiler.common/src/org/jetbrains/kotlin/types/model/TypeSystemContext.kt index 6c3c30f999a..68206d806a7 100644 --- a/core/compiler.common/src/org/jetbrains/kotlin/types/model/TypeSystemContext.kt +++ b/core/compiler.common/src/org/jetbrains/kotlin/types/model/TypeSystemContext.kt @@ -5,6 +5,7 @@ package org.jetbrains.kotlin.types.model +import org.jetbrains.kotlin.types.AbstractTypeChecker import org.jetbrains.kotlin.types.TypeCheckerState import org.jetbrains.kotlin.types.Variance import kotlin.contracts.ExperimentalContracts @@ -175,6 +176,18 @@ interface TypeSystemInferenceExtensionContext : TypeSystemContext, TypeSystemBui fun createStubTypeForBuilderInference(typeVariable: TypeVariableMarker): StubTypeMarker fun createStubTypeForTypeVariablesInSubtyping(typeVariable: TypeVariableMarker): StubTypeMarker + fun KotlinTypeMarker.isFinal(): Boolean + + fun Collection.isEmptyIntersection(): Boolean = + any { first -> + any { second -> + first !== second && + first.isFinal() && + second.typeConstructor().isClassTypeConstructor() && + !AbstractTypeChecker.isSubtypeOf(this@TypeSystemInferenceExtensionContext, first, second) + } + } + fun KotlinTypeMarker.removeAnnotations(): KotlinTypeMarker fun KotlinTypeMarker.removeExactAnnotation(): KotlinTypeMarker diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/checker/ClassicTypeSystemContext.kt b/core/descriptors/src/org/jetbrains/kotlin/types/checker/ClassicTypeSystemContext.kt index 483addb3266..865d1d0e83f 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/checker/ClassicTypeSystemContext.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/checker/ClassicTypeSystemContext.kt @@ -460,6 +460,10 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext, TypeSy return makeSimpleTypeDefinitelyNotNullOrNotNullInternal(this) } + override fun KotlinTypeMarker.isFinal(): Boolean { + require(this is KotlinType, this::errorMessage) + return !TypeUtils.canHaveSubtypes(KotlinTypeChecker.DEFAULT, this) + } override fun KotlinTypeMarker.removeAnnotations(): KotlinTypeMarker { require(this is UnwrappedType, this::errorMessage)