From aaf0a1f396843287d2112d169784db220621efe2 Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Fri, 25 Nov 2022 11:51:02 +0200 Subject: [PATCH] [FIR] Introduce shouldNotBeCalled utility function --- .../kotlin/fir/backend/Fir2IrPluginContext.kt | 3 ++- .../fir/lazy/AbstractFir2IrLazyDeclaration.kt | 5 +++-- .../fir/scopes/impl/FirNestedClassifierScope.kt | 3 ++- .../resolve/calls/CallableReferenceResolution.kt | 13 +++++++------ .../resolve/providers/impl/FirTypeResolverImpl.kt | 3 ++- .../builder/FirAnonymousObjectExpressionBuilder.kt | 3 ++- .../fir/extensions/predicate/LookupPredicate.kt | 3 ++- .../src/org/jetbrains/kotlin/utils/addToStdlib.kt | 4 ++++ 8 files changed, 24 insertions(+), 13 deletions(-) diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrPluginContext.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrPluginContext.kt index d004cb13828..e6c277cbdc7 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrPluginContext.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrPluginContext.kt @@ -33,6 +33,7 @@ import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.platform.TargetPlatform import org.jetbrains.kotlin.resolve.BindingContext +import org.jetbrains.kotlin.utils.addToStdlib.shouldNotBeCalled class Fir2IrPluginContext( private val components: Fir2IrComponents, @@ -94,7 +95,7 @@ class Fir2IrPluginContext( return referenceCallableSymbols( classId, getCallablesFromScope = { getDeclaredConstructors() }, - getCallablesFromProvider = { error("should not be called") }, + getCallablesFromProvider = { shouldNotBeCalled() }, Fir2IrDeclarationStorage::getIrConstructorSymbol ) } diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/lazy/AbstractFir2IrLazyDeclaration.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/lazy/AbstractFir2IrLazyDeclaration.kt index 15dd218dc71..e4076115393 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/lazy/AbstractFir2IrLazyDeclaration.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/lazy/AbstractFir2IrLazyDeclaration.kt @@ -15,6 +15,7 @@ import org.jetbrains.kotlin.ir.declarations.lazy.lazyVar import org.jetbrains.kotlin.ir.expressions.IrConstructorCall import org.jetbrains.kotlin.ir.util.DeclarationStubGenerator import org.jetbrains.kotlin.ir.util.TypeTranslator +import org.jetbrains.kotlin.utils.addToStdlib.shouldNotBeCalled import kotlin.properties.ReadWriteProperty interface AbstractFir2IrLazyDeclaration : @@ -36,7 +37,7 @@ interface AbstractFir2IrLazyDeclaration : } override val stubGenerator: DeclarationStubGenerator - get() = error("Should not be called") + get() = shouldNotBeCalled() override val typeTranslator: TypeTranslator - get() = error("Should not be called") + get() = shouldNotBeCalled() } diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirNestedClassifierScope.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirNestedClassifierScope.kt index 23fdbd1c4df..9ea849211d8 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirNestedClassifierScope.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirNestedClassifierScope.kt @@ -21,6 +21,7 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol import org.jetbrains.kotlin.fir.types.ConeKotlinType import org.jetbrains.kotlin.fir.types.impl.ConeTypeParameterTypeImpl import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.utils.addToStdlib.shouldNotBeCalled abstract class FirNestedClassifierScope(val klass: FirClass, val useSiteSession: FirSession) : FirContainingNamesAwareScope() { protected abstract fun getNestedClassSymbol(name: Name): FirClassLikeSymbol<*>? @@ -69,7 +70,7 @@ class FirCompositeNestedClassifierScope( useSiteSession: FirSession ) : FirNestedClassifierScope(klass, useSiteSession) { override fun getNestedClassSymbol(name: Name): FirRegularClassSymbol? { - error("Should not be called") + shouldNotBeCalled() } override fun processClassifiersByNameWithSubstitution(name: Name, processor: (FirClassifierSymbol<*>, ConeSubstitutor) -> Unit) { 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 ef66f79a159..3fd57da6a97 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 @@ -32,6 +32,7 @@ import org.jetbrains.kotlin.resolve.calls.inference.model.SimpleConstraintSystem import org.jetbrains.kotlin.resolve.calls.inference.runTransaction import org.jetbrains.kotlin.resolve.calls.tower.isSuccess import org.jetbrains.kotlin.types.expressions.CoercionStrategy +import org.jetbrains.kotlin.utils.addToStdlib.shouldNotBeCalled internal object CheckCallableReferenceExpectedType : CheckerStage() { @@ -370,25 +371,25 @@ class FirFakeArgumentForCallableReference( get() = null override val typeRef: FirTypeRef - get() = error("should not be called") + get() = shouldNotBeCalled() override val annotations: List - get() = error("should not be called") + get() = shouldNotBeCalled() override fun replaceTypeRef(newTypeRef: FirTypeRef) { - error("should not be called") + shouldNotBeCalled() } override fun transformAnnotations(transformer: FirTransformer, data: D): FirNamedArgumentExpression { - error("should not be called") + shouldNotBeCalled() } override fun acceptChildren(visitor: FirVisitor, data: D) { - error("should not be called") + shouldNotBeCalled() } override fun transformChildren(transformer: FirTransformer, data: D): FirElement { - error("should not be called") + shouldNotBeCalled() } } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/providers/impl/FirTypeResolverImpl.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/providers/impl/FirTypeResolverImpl.kt index ce94715ef4f..0a28c11adba 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/providers/impl/FirTypeResolverImpl.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/providers/impl/FirTypeResolverImpl.kt @@ -37,6 +37,7 @@ import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintSystemError import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind import org.jetbrains.kotlin.resolve.calls.tower.CandidateApplicability import org.jetbrains.kotlin.resolve.deprecation.DeprecationLevelValue +import org.jetbrains.kotlin.utils.addToStdlib.shouldNotBeCalled @ThreadSafeMutableState class FirTypeResolverImpl(private val session: FirSession) : FirTypeResolver() { @@ -557,7 +558,7 @@ class FirTypeResolverImpl(private val session: FirSession) : FirTypeResolver() { get() = emptyList() override val callInfo: AbstractCallInfo - get() = throw UnsupportedOperationException("Should not be called") + get() = shouldNotBeCalled() override fun equals(other: Any?): Boolean { if (this === other) return true diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/builder/FirAnonymousObjectExpressionBuilder.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/builder/FirAnonymousObjectExpressionBuilder.kt index 56ecd3deead..6fef87d40e1 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/builder/FirAnonymousObjectExpressionBuilder.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/expressions/builder/FirAnonymousObjectExpressionBuilder.kt @@ -14,6 +14,7 @@ import org.jetbrains.kotlin.fir.expressions.FirAnonymousObjectExpression import org.jetbrains.kotlin.fir.expressions.impl.FirAnonymousObjectExpressionImpl import org.jetbrains.kotlin.fir.types.FirTypeRef import org.jetbrains.kotlin.fir.types.impl.FirImplicitTypeRefImpl +import org.jetbrains.kotlin.utils.addToStdlib.shouldNotBeCalled import kotlin.contracts.ExperimentalContracts import kotlin.contracts.contract @@ -24,7 +25,7 @@ class FirAnonymousObjectExpressionBuilder : FirAnnotationContainerBuilder, FirEx lateinit var anonymousObject: FirAnonymousObject override val annotations: MutableList - get() = error("Should not be called") + get() = shouldNotBeCalled() override fun build(): FirAnonymousObjectExpression { return FirAnonymousObjectExpressionImpl( diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/extensions/predicate/LookupPredicate.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/extensions/predicate/LookupPredicate.kt index 779b3e5b67c..3bd6fed7256 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/extensions/predicate/LookupPredicate.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/extensions/predicate/LookupPredicate.kt @@ -6,11 +6,12 @@ package org.jetbrains.kotlin.fir.extensions.predicate import org.jetbrains.kotlin.fir.extensions.AnnotationFqn +import org.jetbrains.kotlin.utils.addToStdlib.shouldNotBeCalled sealed class LookupPredicate : AbstractPredicate { abstract override val annotations: Set final override val metaAnnotations: Set - get() = error("Should not be called") + get() = shouldNotBeCalled() abstract override fun accept(visitor: PredicateVisitor, data: D): R diff --git a/core/util.runtime/src/org/jetbrains/kotlin/utils/addToStdlib.kt b/core/util.runtime/src/org/jetbrains/kotlin/utils/addToStdlib.kt index 1029cb5c1f7..7b62cdf7345 100644 --- a/core/util.runtime/src/org/jetbrains/kotlin/utils/addToStdlib.kt +++ b/core/util.runtime/src/org/jetbrains/kotlin/utils/addToStdlib.kt @@ -296,3 +296,7 @@ fun MutableList.popLast(): E = removeAt(lastIndex) fun , V> enumMapOf(vararg pairs: Pair): EnumMap = EnumMap(mapOf(*pairs)) fun > enumSetOf(element: T, vararg elements: T): EnumSet = EnumSet.of(element, *elements) + +fun shouldNotBeCalled(message: String = "should not be called"): Nothing { + error(message) +}