[FIR] Introduce shouldNotBeCalled utility function

This commit is contained in:
Dmitriy Novozhilov
2022-11-25 11:51:02 +02:00
committed by Space Team
parent 0b4216c096
commit aaf0a1f396
8 changed files with 24 additions and 13 deletions
@@ -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
)
}
@@ -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<F> :
@@ -36,7 +37,7 @@ interface AbstractFir2IrLazyDeclaration<F> :
}
override val stubGenerator: DeclarationStubGenerator
get() = error("Should not be called")
get() = shouldNotBeCalled()
override val typeTranslator: TypeTranslator
get() = error("Should not be called")
get() = shouldNotBeCalled()
}
@@ -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) {
@@ -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<FirAnnotation>
get() = error("should not be called")
get() = shouldNotBeCalled()
override fun replaceTypeRef(newTypeRef: FirTypeRef) {
error("should not be called")
shouldNotBeCalled()
}
override fun <D> transformAnnotations(transformer: FirTransformer<D>, data: D): FirNamedArgumentExpression {
error("should not be called")
shouldNotBeCalled()
}
override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) {
error("should not be called")
shouldNotBeCalled()
}
override fun <D> transformChildren(transformer: FirTransformer<D>, data: D): FirElement {
error("should not be called")
shouldNotBeCalled()
}
}
@@ -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
@@ -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<FirAnnotation>
get() = error("Should not be called")
get() = shouldNotBeCalled()
override fun build(): FirAnonymousObjectExpression {
return FirAnonymousObjectExpressionImpl(
@@ -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<LookupPredicate> {
abstract override val annotations: Set<AnnotationFqn>
final override val metaAnnotations: Set<AnnotationFqn>
get() = error("Should not be called")
get() = shouldNotBeCalled()
abstract override fun <R, D> accept(visitor: PredicateVisitor<LookupPredicate, R, D>, data: D): R
@@ -296,3 +296,7 @@ fun <E> MutableList<E>.popLast(): E = removeAt(lastIndex)
fun <K : Enum<K>, V> enumMapOf(vararg pairs: Pair<K, V>): EnumMap<K, V> = EnumMap(mapOf(*pairs))
fun <T : Enum<T>> enumSetOf(element: T, vararg elements: T): EnumSet<T> = EnumSet.of(element, *elements)
fun shouldNotBeCalled(message: String = "should not be called"): Nothing {
error(message)
}