[FIR] remove user code leaks from compiler.fir.providers module, add more information to some errors
This commit is contained in:
committed by
Space Team
parent
9f847da13e
commit
e6c8bf6644
@@ -25,8 +25,10 @@ import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag
|
||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.fir.utils.exceptions.withFirEntry
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.types.AbstractTypeChecker
|
||||
import org.jetbrains.kotlin.utils.exceptions.errorWithAttachment
|
||||
|
||||
abstract class FirModuleVisibilityChecker : FirSessionComponent {
|
||||
abstract fun isInFriendModule(declaration: FirMemberDeclaration): Boolean
|
||||
@@ -463,7 +465,9 @@ fun FirBasedSymbol<*>.getOwnerLookupTag(): ConeClassLikeLookupTag? {
|
||||
is FirClassLikeSymbol<*> -> getContainingClassLookupTag()
|
||||
is FirCallableSymbol<*> -> containingClassLookupTag()
|
||||
is FirScriptSymbol -> null
|
||||
else -> error("Unsupported owner search for ${fir.javaClass}: ${fir.render()}")
|
||||
else -> errorWithAttachment("Unsupported owner search for ${fir::class.java}") {
|
||||
withFirEntry("ownerDeclaration", fir)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,10 +22,12 @@ import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl
|
||||
import org.jetbrains.kotlin.fir.utils.exceptions.withFirLookupTagEntry
|
||||
import org.jetbrains.kotlin.name.SpecialNames
|
||||
import org.jetbrains.kotlin.name.StandardClassIds
|
||||
import org.jetbrains.kotlin.types.ConstantValueKind
|
||||
import org.jetbrains.kotlin.util.WeakPair
|
||||
import org.jetbrains.kotlin.utils.exceptions.errorWithAttachment
|
||||
|
||||
fun ConeClassifierLookupTag.toSymbol(useSiteSession: FirSession): FirClassifierSymbol<*>? =
|
||||
when (this) {
|
||||
|
||||
+5
-1
@@ -15,12 +15,14 @@ import org.jetbrains.kotlin.fir.resolve.withCombinedAttributesFrom
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl
|
||||
import org.jetbrains.kotlin.fir.utils.exceptions.withConeTypeEntry
|
||||
import org.jetbrains.kotlin.name.StandardClassIds
|
||||
import org.jetbrains.kotlin.types.model.TypeConstructorMarker
|
||||
import org.jetbrains.kotlin.types.model.TypeSubstitutorMarker
|
||||
import org.jetbrains.kotlin.types.model.TypeVariableMarker
|
||||
import org.jetbrains.kotlin.types.model.typeConstructor
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.runIf
|
||||
import org.jetbrains.kotlin.utils.exceptions.errorWithAttachment
|
||||
|
||||
abstract class AbstractConeSubstitutor(protected val typeContext: ConeTypeContext) : ConeSubstitutor() {
|
||||
protected fun wrapProjection(old: ConeTypeProjection, newType: ConeKotlinType): ConeTypeProjection {
|
||||
@@ -160,7 +162,9 @@ abstract class AbstractConeSubstitutor(protected val typeContext: ConeTypeContex
|
||||
newArguments as Array<ConeTypeProjection>,
|
||||
attributes
|
||||
)
|
||||
else -> error("Unknown class-like type to substitute: $this, ${this::class}")
|
||||
else -> errorWithAttachment("Unknown class-like type to substitute, ${this::class}") {
|
||||
withConeTypeEntry("type", this@substituteArguments)
|
||||
}
|
||||
}
|
||||
}
|
||||
return null
|
||||
|
||||
+6
-1
@@ -13,6 +13,8 @@ import org.jetbrains.kotlin.fir.scopes.FirOverrideChecker
|
||||
import org.jetbrains.kotlin.fir.scopes.FirTypeScope
|
||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
|
||||
import org.jetbrains.kotlin.fir.utils.exceptions.withFirEntry
|
||||
import org.jetbrains.kotlin.utils.exceptions.errorWithAttachment
|
||||
|
||||
abstract class AbstractFirOverrideScope(
|
||||
val session: FirSession,
|
||||
@@ -54,7 +56,10 @@ internal fun FirOverrideChecker.similarFunctionsOrBothProperties(
|
||||
overrideCandidate is FirConstructor -> false
|
||||
overrideCandidate is FirProperty -> baseDeclaration is FirProperty && isOverriddenProperty(overrideCandidate, baseDeclaration)
|
||||
overrideCandidate is FirField -> baseDeclaration is FirField
|
||||
else -> error("Unknown fir callable type: $overrideCandidate, $baseDeclaration")
|
||||
else -> errorWithAttachment("Unknown fir callable type") {
|
||||
withFirEntry("overrideCandidate", overrideCandidate)
|
||||
withFirEntry("baseDeclaration", baseDeclaration)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-1
@@ -24,8 +24,10 @@ import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||
import org.jetbrains.kotlin.fir.symbols.lazyResolveToPhase
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.fir.utils.exceptions.withFirEntry
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.runIf
|
||||
import org.jetbrains.kotlin.utils.exceptions.errorWithAttachment
|
||||
|
||||
class FirClassSubstitutionScope(
|
||||
private val session: FirSession,
|
||||
@@ -365,7 +367,9 @@ class FirSubstitutionOverrideStorage(val session: FirSession) : FirSessionCompon
|
||||
when (original) {
|
||||
is FirPropertySymbol -> scope.createSubstitutionOverrideProperty(original)
|
||||
is FirFieldSymbol -> scope.createSubstitutionOverrideField(original)
|
||||
else -> error("symbol $original is not overridable")
|
||||
else -> errorWithAttachment("symbol ${original::class.java} is not overridable") {
|
||||
withFirEntry("original", original.fir)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-1
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.name.CallableId
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.name.StandardClassIds
|
||||
import org.jetbrains.kotlin.utils.exceptions.errorWithAttachment
|
||||
|
||||
class FirDelegatedMemberScope(
|
||||
private val session: FirSession,
|
||||
@@ -221,7 +222,9 @@ fun FirSimpleFunction.isPublicInAny(): Boolean {
|
||||
return when (name.asString()) {
|
||||
"hashCode", "toString" -> valueParameters.isEmpty()
|
||||
"equals" -> valueParameters.singleOrNull()?.hasTypeOf(StandardClassIds.Any, allowNullable = true) == true
|
||||
else -> error("Unexpected method name: $name")
|
||||
else -> errorWithAttachment("Unexpected method name") {
|
||||
withEntry("methodName", name) { name.asString() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-1
@@ -21,7 +21,9 @@ import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
|
||||
import org.jetbrains.kotlin.fir.utils.exceptions.withConeTypeEntry
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.utils.exceptions.errorWithAttachment
|
||||
import kotlin.contracts.ExperimentalContracts
|
||||
import kotlin.contracts.contract
|
||||
|
||||
@@ -41,7 +43,9 @@ class FirIntegerConstantOperatorScope(
|
||||
scopeSession,
|
||||
FakeOverrideTypeCalculator.DoNothing,
|
||||
requiredMembersPhase = FirResolvePhase.STATUS,
|
||||
) ?: error("Scope for $baseType not found")
|
||||
) ?: errorWithAttachment("Scope for ${baseType::class.java} not found") {
|
||||
withConeTypeEntry("type", baseType)
|
||||
}
|
||||
}
|
||||
|
||||
private val mappedFunctions = mutableMapOf<Name, FirNamedFunctionSymbol>()
|
||||
|
||||
@@ -24,12 +24,14 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirAnonymousObjectSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
|
||||
import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl
|
||||
import org.jetbrains.kotlin.fir.types.impl.ConeTypeParameterTypeImpl
|
||||
import org.jetbrains.kotlin.fir.utils.exceptions.withConeTypeEntry
|
||||
import org.jetbrains.kotlin.name.StandardClassIds
|
||||
import org.jetbrains.kotlin.types.AbstractTypeChecker
|
||||
import org.jetbrains.kotlin.types.AbstractTypeRefiner
|
||||
import org.jetbrains.kotlin.types.TypeCheckerState
|
||||
import org.jetbrains.kotlin.types.model.*
|
||||
import org.jetbrains.kotlin.utils.DFS
|
||||
import org.jetbrains.kotlin.utils.exceptions.errorWithAttachment
|
||||
|
||||
interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeContext {
|
||||
|
||||
@@ -142,7 +144,9 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo
|
||||
override fun KotlinTypeMarker.typeDepth() = when (this) {
|
||||
is ConeSimpleKotlinType -> typeDepth()
|
||||
is ConeFlexibleType -> maxOf(lowerBound().typeDepth(), upperBound().typeDepth())
|
||||
else -> error("Type should be simple or flexible: $this")
|
||||
else -> errorWithAttachment("Type should be simple or flexible: ${this::class.java}") {
|
||||
withConeTypeEntry("type", this@typeDepth as? ConeKotlinType)
|
||||
}
|
||||
}
|
||||
|
||||
override fun SimpleTypeMarker.typeDepth(): Int {
|
||||
@@ -526,7 +530,10 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo
|
||||
isFunction
|
||||
} ?: false
|
||||
}
|
||||
functionalSupertype ?: error("Failed to find functional supertype for $simpleType")
|
||||
functionalSupertype
|
||||
?: errorWithAttachment("Failed to find functional supertype for ${simpleType::class.java}") {
|
||||
withConeTypeEntry("type", simpleType)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,15 +21,20 @@ import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor
|
||||
import org.jetbrains.kotlin.fir.resolve.substitution.substitutorByMap
|
||||
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeClassifierLookupTag
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeTypeParameterLookupTag
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||
import org.jetbrains.kotlin.fir.symbols.lazyResolveToPhase
|
||||
import org.jetbrains.kotlin.fir.utils.exceptions.withConeTypeEntry
|
||||
import org.jetbrains.kotlin.fir.utils.exceptions.withFirLookupTagEntry
|
||||
import org.jetbrains.kotlin.name.*
|
||||
import org.jetbrains.kotlin.types.TypeCheckerState
|
||||
import org.jetbrains.kotlin.types.TypeCheckerState.SupertypesPolicy.DoCustomTransform
|
||||
import org.jetbrains.kotlin.types.TypeCheckerState.SupertypesPolicy.LowerIfFlexible
|
||||
import org.jetbrains.kotlin.types.TypeSystemCommonBackendContext
|
||||
import org.jetbrains.kotlin.types.model.*
|
||||
import org.jetbrains.kotlin.utils.exceptions.errorWithAttachment
|
||||
import org.jetbrains.kotlin.utils.exceptions.withPsiEntry
|
||||
|
||||
class ErrorTypeConstructor(val reason: String) : TypeConstructorMarker {
|
||||
override fun toString(): String = reason
|
||||
@@ -85,7 +90,9 @@ interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext, Ty
|
||||
is ConeClassLikeType -> fullyExpandedType(session)
|
||||
is ConeSimpleKotlinType -> this
|
||||
is ConeFlexibleType -> null
|
||||
else -> error("Unknown simpleType: $this")
|
||||
else -> errorWithAttachment("Unknown simpleType: ${this::class.java}") {
|
||||
withConeTypeEntry("type", this@asSimpleType as? ConeKotlinType)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,7 +161,9 @@ interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext, Ty
|
||||
is ConeStubType -> constructor
|
||||
is ConeDefinitelyNotNullType -> original.typeConstructor()
|
||||
is ConeIntegerLiteralType -> this
|
||||
else -> error("?: $this")
|
||||
else -> errorWithAttachment("Unknown simpleType: ${this::class.java}") {
|
||||
withConeTypeEntry("type", this@typeConstructor as? ConeKotlinType)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -261,7 +270,9 @@ interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext, Ty
|
||||
is FirAnonymousObjectSymbol -> symbol.fir.typeParameters[index].symbol.toLookupTag()
|
||||
is FirRegularClassSymbol -> symbol.fir.typeParameters[index].symbol.toLookupTag()
|
||||
is FirTypeAliasSymbol -> symbol.fir.typeParameters[index].symbol.toLookupTag()
|
||||
else -> error("Unexpected FirClassLikeSymbol $symbol for ${this::class}, with classId ${(this as? ConeClassLikeLookupTag)?.classId}")
|
||||
else -> errorWithAttachment("Unexpected FirClassLikeSymbol $symbol for ${this::class}") {
|
||||
withFirLookupTagEntry("lookupTag", this@getParameter as? ConeClassLikeLookupTag)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -632,7 +643,10 @@ interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext, Ty
|
||||
}
|
||||
|
||||
private fun TypeConstructorMarker.unknownConstructorError(): Nothing {
|
||||
error("Unknown type constructor: ${this::class}")
|
||||
errorWithAttachment("Unknown type constructor: ${this::class.java}") {
|
||||
withEntry("constructor", this@unknownConstructorError) { it.toString() }
|
||||
withFirLookupTagEntry("constructorAsLookupTag", this@unknownConstructorError as? ConeClassifierLookupTag)
|
||||
}
|
||||
}
|
||||
|
||||
override fun substitutionSupertypePolicy(type: SimpleTypeMarker): TypeCheckerState.SupertypesPolicy {
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
|
||||
import org.jetbrains.kotlin.types.AbstractTypePreparator
|
||||
import org.jetbrains.kotlin.types.model.KotlinTypeMarker
|
||||
import org.jetbrains.kotlin.utils.exceptions.errorWithAttachment
|
||||
|
||||
class ConeTypePreparator(val session: FirSession) : AbstractTypePreparator() {
|
||||
private fun prepareType(type: ConeSimpleKotlinType): ConeSimpleKotlinType {
|
||||
|
||||
@@ -23,10 +23,12 @@ import org.jetbrains.kotlin.fir.scopes.unsubstitutedScope
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
|
||||
import org.jetbrains.kotlin.fir.utils.exceptions.withConeTypeEntry
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.types.AbstractTypeChecker
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.runUnless
|
||||
import org.jetbrains.kotlin.utils.exceptions.errorWithAttachment
|
||||
|
||||
// ---------------------------------------------- is type is a function type ----------------------------------------------
|
||||
|
||||
@@ -46,7 +48,9 @@ private inline fun ConeKotlinType.isFunctionTypeWithPredicate(
|
||||
predicate: (FunctionTypeKind) -> Boolean
|
||||
): Boolean {
|
||||
val kind = functionTypeKind(session)
|
||||
?: if (errorOnNotFunctionType) error("$this is not a function type") else return false
|
||||
?: if (errorOnNotFunctionType) errorWithAttachment("${this::class.java} is not a function type") {
|
||||
withConeTypeEntry("type", this@isFunctionTypeWithPredicate)
|
||||
} else return false
|
||||
return predicate(kind)
|
||||
}
|
||||
|
||||
|
||||
@@ -30,10 +30,12 @@ import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl
|
||||
import org.jetbrains.kotlin.fir.types.impl.ConeTypeParameterTypeImpl
|
||||
import org.jetbrains.kotlin.fir.types.lowerBoundIfFlexible
|
||||
import org.jetbrains.kotlin.fir.utils.exceptions.withConeTypeEntry
|
||||
import org.jetbrains.kotlin.resolve.calls.NewCommonSuperTypeCalculator
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.model.*
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.runIf
|
||||
import org.jetbrains.kotlin.utils.exceptions.errorWithAttachment
|
||||
import org.jetbrains.kotlin.fir.types.lowerBoundIfFlexible as coneLowerBoundIfFlexible
|
||||
import org.jetbrains.kotlin.fir.types.upperBoundIfFlexible as coneUpperBoundIfFlexible
|
||||
|
||||
@@ -122,7 +124,9 @@ fun <T : ConeKotlinType> T.withArguments(arguments: Array<out ConeTypeProjection
|
||||
is ConeErrorType -> ConeErrorType(diagnostic, isUninferredParameter, arguments, attributes) as T
|
||||
is ConeClassLikeTypeImpl -> ConeClassLikeTypeImpl(lookupTag, arguments, nullability.isNullable, attributes) as T
|
||||
is ConeDefinitelyNotNullType -> ConeDefinitelyNotNullType(original.withArguments(arguments)) as T
|
||||
else -> error("Not supported: $this: ${this.renderForDebugging()}")
|
||||
else -> errorWithAttachment("Not supported: ${this::class}") {
|
||||
withConeTypeEntry("type", this@withArguments)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,7 +158,9 @@ fun <T : ConeKotlinType> T.withAttributes(attributes: ConeAttributes): T {
|
||||
// Attributes for stub types are not supported, and it's not obvious if it should
|
||||
is ConeStubType -> this
|
||||
is ConeIntegerLiteralType -> this
|
||||
else -> error("Not supported: $this: ${this.renderForDebugging()}")
|
||||
else -> errorWithAttachment("Not supported: ${this::class}") {
|
||||
withConeTypeEntry("type", this@withAttributes)
|
||||
}
|
||||
} as T
|
||||
}
|
||||
|
||||
@@ -729,7 +735,9 @@ private fun ConeKotlinType.eraseAsUpperBound(
|
||||
original.eraseAsUpperBound(session, cache, mode)
|
||||
.makeConeTypeDefinitelyNotNullOrNotNull(session.typeContext)
|
||||
|
||||
else -> error("unexpected Java type parameter upper bound kind: $this")
|
||||
else -> errorWithAttachment("unexpected Java type parameter upper bound kind: ${this::class}") {
|
||||
withConeTypeEntry("type", this@eraseAsUpperBound)
|
||||
}
|
||||
}
|
||||
|
||||
fun ConeKotlinType.isRaw(): Boolean = lowerBoundIfFlexible().attributes.contains(CompilerConeAttributes.RawType)
|
||||
|
||||
Reference in New Issue
Block a user