[FIR] Rename ConeClassErrorType to ConeErrorType, drop ConeKotlinErrorType alias

This commit is contained in:
Dmitriy Novozhilov
2022-01-28 14:37:03 +03:00
committed by teamcity
parent 9c6292db6f
commit 0bd3e8f418
77 changed files with 138 additions and 140 deletions
@@ -431,7 +431,7 @@ internal class KtSymbolByFirBuilder private constructor(
else KtFirUsualClassType(coneType, token, this@KtSymbolByFirBuilder) else KtFirUsualClassType(coneType, token, this@KtSymbolByFirBuilder)
} }
is ConeTypeParameterType -> KtFirTypeParameterType(coneType, token, this@KtSymbolByFirBuilder) is ConeTypeParameterType -> KtFirTypeParameterType(coneType, token, this@KtSymbolByFirBuilder)
is ConeClassErrorType -> KtFirClassErrorType(coneType, token, this@KtSymbolByFirBuilder) is ConeErrorType -> KtFirClassErrorType(coneType, token, this@KtSymbolByFirBuilder)
is ConeFlexibleType -> KtFirFlexibleType(coneType, token, this@KtSymbolByFirBuilder) is ConeFlexibleType -> KtFirFlexibleType(coneType, token, this@KtSymbolByFirBuilder)
is ConeIntersectionType -> KtFirIntersectionType(coneType, token, this@KtSymbolByFirBuilder) is ConeIntersectionType -> KtFirIntersectionType(coneType, token, this@KtSymbolByFirBuilder)
is ConeDefinitelyNotNullType -> KtFirDefinitelyNotNullType(coneType, token, this@KtSymbolByFirBuilder) is ConeDefinitelyNotNullType -> KtFirDefinitelyNotNullType(coneType, token, this@KtSymbolByFirBuilder)
@@ -179,9 +179,9 @@ internal fun ConeKotlinType.asPsiType(
): PsiType? { ): PsiType? {
val correctedType = simplifyType(session, useSitePosition) val correctedType = simplifyType(session, useSitePosition)
if (correctedType is ConeClassErrorType || correctedType !is SimpleTypeMarker) return null if (correctedType is ConeErrorType || correctedType !is SimpleTypeMarker) return null
if (correctedType.typeArguments.any { it is ConeClassErrorType }) return null if (correctedType.typeArguments.any { it is ConeErrorType }) return null
val signatureWriter = BothSignatureWriter(BothSignatureWriter.Mode.SKIP_CHECKS) val signatureWriter = BothSignatureWriter(BothSignatureWriter.Mode.SKIP_CHECKS)
@@ -355,7 +355,7 @@ private class ElementsToShortenCollector(
val ConeKotlinType.candidateClassId: ClassId? val ConeKotlinType.candidateClassId: ClassId?
get() { get() {
return when (this) { return when (this) {
is ConeClassErrorType -> when (val diagnostic = this.diagnostic) { is ConeErrorType -> when (val diagnostic = this.diagnostic) {
// Tolerate code that misses type parameters while shortening it. // Tolerate code that misses type parameters while shortening it.
is ConeUnmatchedTypeArgumentsError -> diagnostic.symbol.classId is ConeUnmatchedTypeArgumentsError -> diagnostic.symbol.classId
else -> null else -> null
@@ -20,7 +20,7 @@ import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeUnresolvedSymbolError
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
import org.jetbrains.kotlin.fir.scopes.impl.toConeType import org.jetbrains.kotlin.fir.scopes.impl.toConeType
import org.jetbrains.kotlin.fir.symbols.impl.FirClassLikeSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirClassLikeSymbol
import org.jetbrains.kotlin.fir.types.ConeClassErrorType import org.jetbrains.kotlin.fir.types.ConeErrorType
import org.jetbrains.kotlin.fir.types.ConeClassLikeType import org.jetbrains.kotlin.fir.types.ConeClassLikeType
import org.jetbrains.kotlin.fir.types.typeContext import org.jetbrains.kotlin.fir.types.typeContext
@@ -33,7 +33,7 @@ internal class KtFirTypeCreator(
val lookupTag = when (builder) { val lookupTag = when (builder) {
is KtClassTypeBuilder.ByClassId -> { is KtClassTypeBuilder.ByClassId -> {
val classSymbol = rootModuleSession.symbolProvider.getClassLikeSymbolByClassId(builder.classId) val classSymbol = rootModuleSession.symbolProvider.getClassLikeSymbolByClassId(builder.classId)
?: return ConeClassErrorType(ConeUnresolvedSymbolError(builder.classId)).asKtType() as KtClassType ?: return ConeErrorType(ConeUnresolvedSymbolError(builder.classId)).asKtType() as KtClassType
classSymbol.toLookupTag() classSymbol.toLookupTag()
} }
is KtClassTypeBuilder.BySymbol -> { is KtClassTypeBuilder.BySymbol -> {
@@ -139,7 +139,7 @@ internal class KtFirTypeProvider(
ConeDefinitelyNotNullType.create(it, analysisSession.rootModuleSession.typeContext) ?: it ConeDefinitelyNotNullType.create(it, analysisSession.rootModuleSession.typeContext) ?: it
} }
is ConeIntersectionType -> intersectedTypes.asSequence().flatMap { it.getDirectSuperTypes(shouldApproximate) } is ConeIntersectionType -> intersectedTypes.asSequence().flatMap { it.getDirectSuperTypes(shouldApproximate) }
is ConeClassErrorType -> emptySequence() is ConeErrorType -> emptySequence()
is ConeLookupTagBasedType -> getSubstitutedSuperTypes(shouldApproximate) is ConeLookupTagBasedType -> getSubstitutedSuperTypes(shouldApproximate)
else -> emptySequence() else -> emptySequence()
}.distinct() }.distinct()
@@ -164,7 +164,7 @@ internal object FirCompileTimeConstantEvaluator {
private fun ConeKotlinType.toConstantValueKind(): ConstantValueKind<*>? = private fun ConeKotlinType.toConstantValueKind(): ConstantValueKind<*>? =
when (this) { when (this) {
is ConeKotlinErrorType -> null is ConeErrorType -> null
is ConeLookupTagBasedType -> lookupTag.name.asString().toConstantValueKind() is ConeLookupTagBasedType -> lookupTag.name.asString().toConstantValueKind()
is ConeFlexibleType -> upperBound.toConstantValueKind() is ConeFlexibleType -> upperBound.toConstantValueKind()
is ConeCapturedType -> lowerType?.toConstantValueKind() ?: constructor.supertypes!!.first().toConstantValueKind() is ConeCapturedType -> lowerType?.toConstantValueKind() ?: constructor.supertypes!!.first().toConstantValueKind()
@@ -47,7 +47,7 @@ internal class ConeTypeIdeRenderer(
fun renderType(type: ConeTypeProjection): String = buildString { fun renderType(type: ConeTypeProjection): String = buildString {
when (type) { when (type) {
is ConeKotlinErrorType -> { is ConeErrorType -> {
renderErrorType(type) renderErrorType(type)
} }
//is Dynamic??? -> append("dynamic") //is Dynamic??? -> append("dynamic")
@@ -90,7 +90,7 @@ internal class ConeTypeIdeRenderer(
} }
} }
private fun StringBuilder.renderErrorType(type: ConeKotlinErrorType) { private fun StringBuilder.renderErrorType(type: ConeErrorType) {
val diagnostic = type.diagnostic val diagnostic = type.diagnostic
if (options.renderUnresolvedTypeAsResolved && diagnostic is ConeUnresolvedError) { if (options.renderUnresolvedTypeAsResolved && diagnostic is ConeUnresolvedError) {
val qualifierRendered = diagnostic.qualifier?.let { FqName(it).render() }.orEmpty() val qualifierRendered = diagnostic.qualifier?.let { FqName(it).render() }.orEmpty()
@@ -116,7 +116,7 @@ internal class KtFirFunctionalType(
} }
internal class KtFirClassErrorType( internal class KtFirClassErrorType(
override val coneType: ConeClassErrorType, override val coneType: ConeErrorType,
override val token: ValidityToken, override val token: ValidityToken,
private val builder: KtSymbolByFirBuilder, private val builder: KtSymbolByFirBuilder,
) : KtClassErrorType(), KtFirType { ) : KtClassErrorType(), KtFirType {
@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeUnresolvedNameError import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeUnresolvedNameError
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirConstructorSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirConstructorSymbol
import org.jetbrains.kotlin.fir.types.ConeClassErrorType import org.jetbrains.kotlin.fir.types.ConeErrorType
import org.jetbrains.kotlin.fir.types.ConeKotlinType import org.jetbrains.kotlin.fir.types.ConeKotlinType
import org.jetbrains.kotlin.fir.types.ConeNullability import org.jetbrains.kotlin.fir.types.ConeNullability
import org.jetbrains.kotlin.fir.types.coneType import org.jetbrains.kotlin.fir.types.coneType
@@ -56,7 +56,7 @@ internal fun FirNamedReference.getReferencedElementType(): ConeKotlinType {
else -> error("Unexpected ${this::class}") else -> error("Unexpected ${this::class}")
} }
val firCallableDeclaration = symbols.singleOrNull()?.fir as? FirCallableDeclaration val firCallableDeclaration = symbols.singleOrNull()?.fir as? FirCallableDeclaration
?: return ConeClassErrorType(ConeUnresolvedNameError(name)) ?: return ConeErrorType(ConeUnresolvedNameError(name))
return firCallableDeclaration.symbol.resolvedReturnType return firCallableDeclaration.symbol.resolvedReturnType
} }
@@ -95,4 +95,4 @@ internal fun FirExpression.asKtInitializerValue(): KtInitializerValue {
null -> KtNonConstantInitializerValue(ktExpression) null -> KtNonConstantInitializerValue(ktExpression)
else -> KtConstantInitializerValue(evaluated, ktExpression) else -> KtConstantInitializerValue(evaluated, ktExpression)
} }
} }
@@ -242,7 +242,7 @@ object ConeTypeCompatibilityChecker {
private fun ConeKotlinType?.collectUpperBounds(): Set<ConeClassLikeType> { private fun ConeKotlinType?.collectUpperBounds(): Set<ConeClassLikeType> {
if (this == null) return emptySet() if (this == null) return emptySet()
return when (this) { return when (this) {
is ConeClassErrorType -> emptySet() // Ignore error types is ConeErrorType -> emptySet() // Ignore error types
is ConeLookupTagBasedType -> when (this) { is ConeLookupTagBasedType -> when (this) {
is ConeClassLikeType -> setOf(this) is ConeClassLikeType -> setOf(this)
is ConeTypeVariableType -> { is ConeTypeVariableType -> {
@@ -267,7 +267,7 @@ object ConeTypeCompatibilityChecker {
private fun ConeKotlinType?.collectLowerBounds(): Set<ConeClassLikeType> { private fun ConeKotlinType?.collectLowerBounds(): Set<ConeClassLikeType> {
if (this == null) return emptySet() if (this == null) return emptySet()
return when (this) { return when (this) {
is ConeClassErrorType -> emptySet() // Ignore error types is ConeErrorType -> emptySet() // Ignore error types
is ConeLookupTagBasedType -> when (this) { is ConeLookupTagBasedType -> when (this) {
is ConeClassLikeType -> setOf(this) is ConeClassLikeType -> setOf(this)
is ConeTypeVariableType -> emptySet() is ConeTypeVariableType -> emptySet()
@@ -61,7 +61,7 @@ internal fun checkConstantArguments(
?.typeRef ?.typeRef
?.coneType ?.coneType
if (coneType is ConeClassErrorType) if (coneType is ConeErrorType)
return ConstantArgumentKind.NOT_CONST return ConstantArgumentKind.NOT_CONST
while (coneType?.classId == StandardClassIds.Array) while (coneType?.classId == StandardClassIds.Array)
@@ -68,7 +68,7 @@ interface FirDeclarationPresenter {
appendRepresentation(it.original) appendRepresentation(it.original)
append(it.nullability.suffix) append(it.nullability.suffix)
} }
is ConeClassErrorType -> { is ConeErrorType -> {
append("ERROR(") append("ERROR(")
append(it.diagnostic.reason) append(it.diagnostic.reason)
append(')') append(')')
@@ -616,7 +616,7 @@ fun checkTypeMismatch(
internal fun checkCondition(condition: FirExpression, context: CheckerContext, reporter: DiagnosticReporter) { internal fun checkCondition(condition: FirExpression, context: CheckerContext, reporter: DiagnosticReporter) {
val coneType = condition.typeRef.coneTypeSafe<ConeKotlinType>()?.lowerBoundIfFlexible() val coneType = condition.typeRef.coneTypeSafe<ConeKotlinType>()?.lowerBoundIfFlexible()
if (coneType != null && if (coneType != null &&
coneType !is ConeKotlinErrorType && coneType !is ConeErrorType &&
!coneType.isSubtypeOf(context.session.typeContext, context.session.builtinTypes.booleanType.type) !coneType.isSubtypeOf(context.session.typeContext, context.session.builtinTypes.booleanType.type)
) { ) {
reporter.reportOn( reporter.reportOn(
@@ -18,7 +18,7 @@ import org.jetbrains.kotlin.fir.declarations.FirProperty
import org.jetbrains.kotlin.fir.declarations.FirRegularClass import org.jetbrains.kotlin.fir.declarations.FirRegularClass
import org.jetbrains.kotlin.fir.declarations.utils.isConst import org.jetbrains.kotlin.fir.declarations.utils.isConst
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
import org.jetbrains.kotlin.fir.types.ConeClassErrorType import org.jetbrains.kotlin.fir.types.ConeErrorType
import org.jetbrains.kotlin.fir.types.coneType import org.jetbrains.kotlin.fir.types.coneType
import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.lexer.KtTokens
@@ -57,7 +57,7 @@ object FirConstPropertyChecker : FirPropertyChecker() {
} }
val type = declaration.returnTypeRef.coneType.fullyExpandedType(context.session) val type = declaration.returnTypeRef.coneType.fullyExpandedType(context.session)
if ((type !is ConeClassErrorType) && !type.canBeUsedForConstVal()) { if ((type !is ConeErrorType) && !type.canBeUsedForConstVal()) {
reporter.reportOn(declaration.source, FirErrors.TYPE_CANT_BE_USED_FOR_CONST_VAL, declaration.returnTypeRef.coneType, context) reporter.reportOn(declaration.source, FirErrors.TYPE_CANT_BE_USED_FOR_CONST_VAL, declaration.returnTypeRef.coneType, context)
return return
} }
@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeInapplicableCandidateErr
import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeInapplicableWrongReceiver import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeInapplicableWrongReceiver
import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeUnresolvedNameError import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeUnresolvedNameError
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
import org.jetbrains.kotlin.fir.types.ConeKotlinErrorType import org.jetbrains.kotlin.fir.types.ConeErrorType
import org.jetbrains.kotlin.fir.types.coneType import org.jetbrains.kotlin.fir.types.coneType
import org.jetbrains.kotlin.fir.types.render import org.jetbrains.kotlin.fir.types.render
import org.jetbrains.kotlin.fir.types.typeContext import org.jetbrains.kotlin.fir.types.typeContext
@@ -39,7 +39,7 @@ object FirDelegatedPropertyChecker : FirPropertyChecker() {
// TODO: Also suppress delegate issue if type inference failed. For example, in // TODO: Also suppress delegate issue if type inference failed. For example, in
// compiler/testData/diagnostics/tests/delegatedProperty/inference/differentDelegatedExpressions.fir.kt, no delegate issues are // compiler/testData/diagnostics/tests/delegatedProperty/inference/differentDelegatedExpressions.fir.kt, no delegate issues are
// reported due to the inference issue. // reported due to the inference issue.
if (delegateType is ConeKotlinErrorType) { if (delegateType is ConeErrorType) {
val delegateSource = delegate.source val delegateSource = delegate.source
// Implicit recursion type is not reported since the type ref does not have a real source. // Implicit recursion type is not reported since the type ref does not have a real source.
if (delegateSource != null && (delegateType.diagnostic as? ConeSimpleDiagnostic)?.kind == DiagnosticKind.RecursionInImplicitTypes) { if (delegateSource != null && (delegateType.diagnostic as? ConeSimpleDiagnostic)?.kind == DiagnosticKind.RecursionInImplicitTypes) {
@@ -146,7 +146,7 @@ object FirDestructuringDeclarationChecker : FirPropertyChecker() {
} }
is ConeConstraintSystemHasContradiction -> { is ConeConstraintSystemHasContradiction -> {
val componentType = componentCall.typeRef.coneType val componentType = componentCall.typeRef.coneType
if (componentType is ConeKotlinErrorType) { if (componentType is ConeErrorType) {
// There will be other errors on this error type. // There will be other errors on this error type.
return return
} }
@@ -27,7 +27,7 @@ import org.jetbrains.kotlin.fir.scopes.getDirectOverriddenProperties
import org.jetbrains.kotlin.fir.scopes.impl.delegatedWrapperData import org.jetbrains.kotlin.fir.scopes.impl.delegatedWrapperData
import org.jetbrains.kotlin.fir.scopes.impl.toConeType import org.jetbrains.kotlin.fir.scopes.impl.toConeType
import org.jetbrains.kotlin.fir.symbols.impl.* import org.jetbrains.kotlin.fir.symbols.impl.*
import org.jetbrains.kotlin.fir.types.ConeKotlinErrorType import org.jetbrains.kotlin.fir.types.ConeErrorType
import org.jetbrains.kotlin.fir.types.ConeKotlinType import org.jetbrains.kotlin.fir.types.ConeKotlinType
import org.jetbrains.kotlin.fir.types.coneType import org.jetbrains.kotlin.fir.types.coneType
import org.jetbrains.kotlin.fir.types.typeContext import org.jetbrains.kotlin.fir.types.typeContext
@@ -126,7 +126,7 @@ object FirImplementationMismatchChecker : FirClassChecker() {
it to context.returnTypeCalculator.tryCalculateReturnType(it).coneType it to context.returnTypeCalculator.tryCalculateReturnType(it).coneType
} }
if (withTypes.any { it.second is ConeKotlinErrorType }) return if (withTypes.any { it.second is ConeErrorType }) return
var delegation: FirCallableSymbol<*>? = null var delegation: FirCallableSymbol<*>? = null
val implementations = mutableListOf<FirCallableSymbol<*>>() val implementations = mutableListOf<FirCallableSymbol<*>>()
@@ -50,11 +50,11 @@ object FirKClassWithIncorrectTypeArgumentChecker : FirCallableDeclarationChecker
argumentType.typeParameterFromError?.let { typeParameterSymbol -> argumentType.typeParameterFromError?.let { typeParameterSymbol ->
return typeParameterSymbol.toConeType().isNullableType() return typeParameterSymbol.toConeType().isNullableType()
} }
return argumentType is ConeKotlinErrorType || argumentType.isNullableType() return argumentType is ConeErrorType || argumentType.isNullableType()
} }
} }
private val ConeKotlinType.typeParameterFromError: FirTypeParameterSymbol? private val ConeKotlinType.typeParameterFromError: FirTypeParameterSymbol?
get() = ((this as? ConeKotlinErrorType)?.diagnostic as? ConeTypeParameterInQualifiedAccess)?.symbol get() = ((this as? ConeErrorType)?.diagnostic as? ConeTypeParameterInQualifiedAccess)?.symbol
} }
@@ -214,7 +214,7 @@ object FirOverrideChecker : FirClassChecker() {
val overridingReturnType = resolvedReturnTypeRef.coneType val overridingReturnType = resolvedReturnTypeRef.coneType
// Don't report *_ON_OVERRIDE diagnostics according to an error return type. That should be reported separately. // Don't report *_ON_OVERRIDE diagnostics according to an error return type. That should be reported separately.
if (overridingReturnType is ConeKotlinErrorType) { if (overridingReturnType is ConeErrorType) {
return null return null
} }
@@ -20,7 +20,7 @@ import org.jetbrains.kotlin.fir.declarations.utils.canHaveAbstractDeclaration
import org.jetbrains.kotlin.fir.declarations.utils.isAbstract import org.jetbrains.kotlin.fir.declarations.utils.isAbstract
import org.jetbrains.kotlin.fir.declarations.utils.isOpen import org.jetbrains.kotlin.fir.declarations.utils.isOpen
import org.jetbrains.kotlin.fir.declarations.utils.visibility import org.jetbrains.kotlin.fir.declarations.utils.visibility
import org.jetbrains.kotlin.fir.types.ConeClassErrorType import org.jetbrains.kotlin.fir.types.ConeErrorType
import org.jetbrains.kotlin.fir.types.coneType import org.jetbrains.kotlin.fir.types.coneType
import org.jetbrains.kotlin.fir.types.isUnit import org.jetbrains.kotlin.fir.types.isUnit
@@ -49,7 +49,7 @@ object FirPropertyAccessorsTypesChecker : FirPropertyChecker() {
return return
} }
val getterReturnType = getterReturnTypeRef.coneType val getterReturnType = getterReturnTypeRef.coneType
if (propertyType is ConeClassErrorType || getterReturnType is ConeClassErrorType) { if (propertyType is ConeErrorType || getterReturnType is ConeErrorType) {
return return
} }
if (getterReturnType != property.returnTypeRef.coneType) { if (getterReturnType != property.returnTypeRef.coneType) {
@@ -94,7 +94,7 @@ object FirPropertyAccessorsTypesChecker : FirPropertyChecker() {
} }
val valueSetterType = valueSetterParameter.returnTypeRef.coneType val valueSetterType = valueSetterParameter.returnTypeRef.coneType
val valueSetterTypeSource = valueSetterParameter.returnTypeRef.source val valueSetterTypeSource = valueSetterParameter.returnTypeRef.source
if (propertyType is ConeClassErrorType || valueSetterType is ConeClassErrorType) { if (propertyType is ConeErrorType || valueSetterType is ConeErrorType) {
return return
} }
@@ -105,7 +105,7 @@ object FirPropertyAccessorsTypesChecker : FirPropertyChecker() {
} }
val setterReturnType = setter.returnTypeRef.coneType val setterReturnType = setter.returnTypeRef.coneType
if (propertyType is ConeClassErrorType || valueSetterType is ConeClassErrorType) { if (propertyType is ConeErrorType || valueSetterType is ConeErrorType) {
return return
} }
@@ -15,7 +15,7 @@ import org.jetbrains.kotlin.fir.declarations.utils.classId
import org.jetbrains.kotlin.fir.declarations.utils.isInner import org.jetbrains.kotlin.fir.declarations.utils.isInner
import org.jetbrains.kotlin.fir.declarations.utils.isLocal import org.jetbrains.kotlin.fir.declarations.utils.isLocal
import org.jetbrains.kotlin.fir.declarations.utils.superConeTypes import org.jetbrains.kotlin.fir.declarations.utils.superConeTypes
import org.jetbrains.kotlin.fir.types.ConeClassErrorType import org.jetbrains.kotlin.fir.types.ConeErrorType
object FirThrowableSubclassChecker : FirClassChecker() { object FirThrowableSubclassChecker : FirClassChecker() {
override fun check(declaration: FirClass, context: CheckerContext, reporter: DiagnosticReporter) { override fun check(declaration: FirClass, context: CheckerContext, reporter: DiagnosticReporter) {
@@ -37,7 +37,7 @@ object FirThrowableSubclassChecker : FirClassChecker() {
} }
private fun FirClass.hasThrowableSupertype(context: CheckerContext) = private fun FirClass.hasThrowableSupertype(context: CheckerContext) =
superConeTypes.any { it !is ConeClassErrorType && it.isSubtypeOfThrowable(context.session) } superConeTypes.any { it !is ConeErrorType && it.isSubtypeOfThrowable(context.session) }
private fun FirClass.hasGenericOuterDeclaration(context: CheckerContext): Boolean { private fun FirClass.hasGenericOuterDeclaration(context: CheckerContext): Boolean {
if (!classId.isLocal) return false if (!classId.isLocal) return false
@@ -46,7 +46,7 @@ object FirTopLevelTypeAliasChecker : FirTypeAliasChecker() {
val fullyExpandedType = expandedTypeRef.coneType.fullyExpandedType(context.session) val fullyExpandedType = expandedTypeRef.coneType.fullyExpandedType(context.session)
if (containsTypeParameter(fullyExpandedType) || if (containsTypeParameter(fullyExpandedType) ||
fullyExpandedType is ConeClassErrorType && fullyExpandedType.diagnostic is ConeUnsupportedDynamicType fullyExpandedType is ConeErrorType && fullyExpandedType.diagnostic is ConeUnsupportedDynamicType
) { ) {
reporter.reportOn( reporter.reportOn(
declaration.expandedTypeRef.source, declaration.expandedTypeRef.source,
@@ -120,7 +120,7 @@ object FirEqualityCompatibilityChecker : FirEqualityOperatorCallChecker() {
lType.isNullableNothing -> rType lType.isNullableNothing -> rType
else -> return else -> return
} }
if (type is ConeKotlinErrorType) return if (type is ConeErrorType) return
val isPositiveCompare = expression.operation == FirOperation.EQ || expression.operation == FirOperation.IDENTITY val isPositiveCompare = expression.operation == FirOperation.EQ || expression.operation == FirOperation.IDENTITY
val compareResult = with(context.session.typeContext) { val compareResult = with(context.session.typeContext) {
when { when {
@@ -11,7 +11,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
import org.jetbrains.kotlin.diagnostics.reportOn import org.jetbrains.kotlin.diagnostics.reportOn
import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression
import org.jetbrains.kotlin.fir.references.FirSuperReference import org.jetbrains.kotlin.fir.references.FirSuperReference
import org.jetbrains.kotlin.fir.types.ConeKotlinErrorType import org.jetbrains.kotlin.fir.types.ConeErrorType
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
import org.jetbrains.kotlin.fir.types.FirUserTypeRef import org.jetbrains.kotlin.fir.types.FirUserTypeRef
import org.jetbrains.kotlin.fir.types.coneType import org.jetbrains.kotlin.fir.types.coneType
@@ -26,9 +26,9 @@ object FirSuperReferenceChecker : FirQualifiedAccessExpressionChecker() {
val typeArgumentList = delegatedTypeRef.qualifier.firstOrNull()?.typeArgumentList ?: return val typeArgumentList = delegatedTypeRef.qualifier.firstOrNull()?.typeArgumentList ?: return
val superType = superTypeRef.coneType val superType = superTypeRef.coneType
if (superType !is ConeKotlinErrorType && if (superType !is ConeErrorType &&
typeArgumentList.typeArguments.isNotEmpty() && typeArgumentList.typeArguments.isNotEmpty() &&
superType.typeArguments.all { it !is ConeKotlinErrorType } superType.typeArguments.all { it !is ConeErrorType }
) { ) {
reporter.reportOn(typeArgumentList.source, FirErrors.TYPE_ARGUMENTS_REDUNDANT_IN_SUPER_QUALIFIER, context) reporter.reportOn(typeArgumentList.source, FirErrors.TYPE_ARGUMENTS_REDUNDANT_IN_SUPER_QUALIFIER, context)
} }
@@ -10,7 +10,7 @@ import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
import org.jetbrains.kotlin.diagnostics.reportOn import org.jetbrains.kotlin.diagnostics.reportOn
import org.jetbrains.kotlin.fir.expressions.FirElvisExpression import org.jetbrains.kotlin.fir.expressions.FirElvisExpression
import org.jetbrains.kotlin.fir.types.ConeKotlinErrorType import org.jetbrains.kotlin.fir.types.ConeErrorType
import org.jetbrains.kotlin.fir.types.canBeNull import org.jetbrains.kotlin.fir.types.canBeNull
import org.jetbrains.kotlin.fir.types.coneType import org.jetbrains.kotlin.fir.types.coneType
import org.jetbrains.kotlin.fir.types.isNullLiteral import org.jetbrains.kotlin.fir.types.isNullLiteral
@@ -20,10 +20,10 @@ object FirUselessElvisChecker : FirElvisExpressionChecker() {
// If the overall expression is not resolved/completed, the corresponding error will be reported separately. // If the overall expression is not resolved/completed, the corresponding error will be reported separately.
// See [FirControlFlowStatementsResolveTransformer#transformElvisExpression], // See [FirControlFlowStatementsResolveTransformer#transformElvisExpression],
// where an error type is recorded as the expression's return type. // where an error type is recorded as the expression's return type.
if (expression.typeRef.coneType is ConeKotlinErrorType) return if (expression.typeRef.coneType is ConeErrorType) return
val lhsType = expression.lhs.typeRef.coneType val lhsType = expression.lhs.typeRef.coneType
if (lhsType is ConeKotlinErrorType) return if (lhsType is ConeErrorType) return
if (!lhsType.canBeNull) { if (!lhsType.canBeNull) {
reporter.reportOn(expression.source, FirErrors.USELESS_ELVIS, lhsType, context) reporter.reportOn(expression.source, FirErrors.USELESS_ELVIS, lhsType, context)
return return
@@ -22,10 +22,10 @@ object FirUselessTypeOperationCallChecker : FirTypeOperatorCallChecker() {
val arg = expression.argument val arg = expression.argument
val candidateType = arg.typeRef.coneType.upperBoundIfFlexible().fullyExpandedType(context.session) val candidateType = arg.typeRef.coneType.upperBoundIfFlexible().fullyExpandedType(context.session)
if (candidateType is ConeKotlinErrorType) return if (candidateType is ConeErrorType) return
val targetType = expression.conversionTypeRef.coneType.fullyExpandedType(context.session) val targetType = expression.conversionTypeRef.coneType.fullyExpandedType(context.session)
if (targetType is ConeKotlinErrorType) return if (targetType is ConeErrorType) return
// x as? Type <=> x as Type? // x as? Type <=> x as Type?
val refinedTargetType = val refinedTargetType =
@@ -177,7 +177,7 @@ abstract class AbstractDiagnosticCollectorVisitor(
// as children in delegatedTypeRef. We should make sure those elements are only visited once, otherwise diagnostics will be // as children in delegatedTypeRef. We should make sure those elements are only visited once, otherwise diagnostics will be
// collected twice: once through resolvedTypeRef's children and another through resolvedTypeRef.delegatedTypeRef's children. // collected twice: once through resolvedTypeRef's children and another through resolvedTypeRef.delegatedTypeRef's children.
val resolvedTypeRefType = resolvedTypeRef.type val resolvedTypeRefType = resolvedTypeRef.type
if (resolvedTypeRefType is ConeClassErrorType) { if (resolvedTypeRefType is ConeErrorType) {
super.visitResolvedTypeRef(resolvedTypeRef, data) super.visitResolvedTypeRef(resolvedTypeRef, data)
} }
if (resolvedTypeRef.source?.kind is KtFakeSourceElementKind) return if (resolvedTypeRef.source?.kind is KtFakeSourceElementKind) return
@@ -185,7 +185,7 @@ abstract class AbstractDiagnosticCollectorVisitor(
//the note about is just wrong //the note about is just wrong
//if we don't visit resolved type we can't make any diagnostics on them //if we don't visit resolved type we can't make any diagnostics on them
//so here we check resolvedTypeRef //so here we check resolvedTypeRef
if (resolvedTypeRefType !is ConeClassErrorType) { if (resolvedTypeRefType !is ConeErrorType) {
withAnnotationContainer(resolvedTypeRef) { withAnnotationContainer(resolvedTypeRef) {
checkElement(resolvedTypeRef) checkElement(resolvedTypeRef)
} }
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind
import org.jetbrains.kotlin.fir.expressions.* import org.jetbrains.kotlin.fir.expressions.*
import org.jetbrains.kotlin.fir.references.FirErrorNamedReference import org.jetbrains.kotlin.fir.references.FirErrorNamedReference
import org.jetbrains.kotlin.fir.resolve.diagnostics.* import org.jetbrains.kotlin.fir.resolve.diagnostics.*
import org.jetbrains.kotlin.fir.types.ConeKotlinErrorType import org.jetbrains.kotlin.fir.types.ConeErrorType
import org.jetbrains.kotlin.fir.types.FirErrorTypeRef import org.jetbrains.kotlin.fir.types.FirErrorTypeRef
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
import org.jetbrains.kotlin.fir.types.render import org.jetbrains.kotlin.fir.types.render
@@ -41,7 +41,7 @@ class ErrorNodeDiagnosticCollectorComponent(
} }
override fun visitResolvedTypeRef(resolvedTypeRef: FirResolvedTypeRef, data: CheckerContext) { override fun visitResolvedTypeRef(resolvedTypeRef: FirResolvedTypeRef, data: CheckerContext) {
assert(resolvedTypeRef.type !is ConeKotlinErrorType) { assert(resolvedTypeRef.type !is ConeErrorType) {
"Instead use FirErrorTypeRef for ${resolvedTypeRef.type.render()}" "Instead use FirErrorTypeRef for ${resolvedTypeRef.type.render()}"
} }
} }
@@ -28,6 +28,6 @@ private class TypeVariableTypeRemovingSubstitutor(typeContext: ConeTypeContext)
check(originalTypeParameter is ConeTypeParameterLookupTag) check(originalTypeParameter is ConeTypeParameterLookupTag)
return ConeTypeParameterTypeImpl(originalTypeParameter, type.isNullable, type.attributes) return ConeTypeParameterTypeImpl(originalTypeParameter, type.isNullable, type.attributes)
} }
return ConeClassErrorType(ConeUnknownLambdaParameterTypeDiagnostic()) return ConeErrorType(ConeUnknownLambdaParameterTypeDiagnostic())
} }
} }
@@ -54,7 +54,7 @@ private fun ConeKotlinType.contains(predicate: (ConeKotlinType) -> Boolean, visi
fun ConeClassLikeType.withArguments(typeArguments: Array<out ConeTypeProjection>): ConeClassLikeType = when (this) { fun ConeClassLikeType.withArguments(typeArguments: Array<out ConeTypeProjection>): ConeClassLikeType = when (this) {
is ConeClassLikeTypeImpl -> ConeClassLikeTypeImpl(lookupTag, typeArguments, isNullable, attributes) is ConeClassLikeTypeImpl -> ConeClassLikeTypeImpl(lookupTag, typeArguments, isNullable, attributes)
is ConeClassErrorType -> this is ConeErrorType -> this
else -> error("Unknown cone type: ${this::class}") else -> error("Unknown cone type: ${this::class}")
} }
@@ -37,11 +37,9 @@ sealed class ConeKotlinType : ConeKotlinTypeProjection(), KotlinTypeMarker, Type
sealed class ConeSimpleKotlinType : ConeKotlinType(), SimpleTypeMarker sealed class ConeSimpleKotlinType : ConeKotlinType(), SimpleTypeMarker
typealias ConeKotlinErrorType = ConeClassErrorType
class ConeClassLikeErrorLookupTag(override val classId: ClassId) : ConeClassLikeLookupTag() class ConeClassLikeErrorLookupTag(override val classId: ClassId) : ConeClassLikeLookupTag()
class ConeClassErrorType(val diagnostic: ConeDiagnostic, val isUninferredParameter: Boolean = false) : ConeClassLikeType() { class ConeErrorType(val diagnostic: ConeDiagnostic, val isUninferredParameter: Boolean = false) : ConeClassLikeType() {
override val lookupTag: ConeClassLikeLookupTag override val lookupTag: ConeClassLikeLookupTag
get() = ConeClassLikeErrorLookupTag(ClassId.fromString("<error>")) get() = ConeClassLikeErrorLookupTag(ClassId.fromString("<error>"))
@@ -10,11 +10,11 @@ import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.contract import kotlin.contracts.contract
fun ConeKotlinType.render(): String { fun ConeKotlinType.render(): String {
val nullabilitySuffix = if (this !is ConeFlexibleType && this !is ConeClassErrorType) nullability.suffix else "" val nullabilitySuffix = if (this !is ConeFlexibleType && this !is ConeErrorType) nullability.suffix else ""
return when (this) { return when (this) {
is ConeTypeVariableType -> "${renderAttributes()}TypeVariable(${this.lookupTag.name})" is ConeTypeVariableType -> "${renderAttributes()}TypeVariable(${this.lookupTag.name})"
is ConeDefinitelyNotNullType -> "${original.render()} & Any" is ConeDefinitelyNotNullType -> "${original.render()} & Any"
is ConeClassErrorType -> "${renderAttributes()}ERROR CLASS: ${diagnostic.reason}" is ConeErrorType -> "${renderAttributes()}ERROR CLASS: ${diagnostic.reason}"
is ConeCapturedType -> "${renderAttributes()}CapturedType(${constructor.projection.render()})" is ConeCapturedType -> "${renderAttributes()}CapturedType(${constructor.projection.render()})"
is ConeClassLikeType -> { is ConeClassLikeType -> {
buildString { buildString {
@@ -843,7 +843,7 @@ class HtmlFirDump internal constructor(private var linkResolver: FirLinkResolver
private fun FlowContent.generate(type: ConeKotlinType) { private fun FlowContent.generate(type: ConeKotlinType) {
when (type) { when (type) {
is ConeClassErrorType -> error { +type.diagnostic.reason } is ConeErrorType -> error { +type.diagnostic.reason }
is ConeClassLikeType -> return generate(type) is ConeClassLikeType -> return generate(type)
is ConeTypeParameterType -> resolved { is ConeTypeParameterType -> resolved {
symbolRef(type.lookupTag.symbol) { symbolRef(type.lookupTag.symbol) {
@@ -118,7 +118,7 @@ class FirTypeDeserializer(
return ConeFlexibleType(lowerBound!!, upperBound!!) return ConeFlexibleType(lowerBound!!, upperBound!!)
} }
return simpleType(proto, attributes) ?: ConeKotlinErrorType(ConeSimpleDiagnostic("?!id:0", DiagnosticKind.DeserializationError)) return simpleType(proto, attributes) ?: ConeErrorType(ConeSimpleDiagnostic("?!id:0", DiagnosticKind.DeserializationError))
} }
private fun typeParameterSymbol(typeParameterId: Int): ConeTypeParameterLookupTag? = private fun typeParameterSymbol(typeParameterId: Int): ConeTypeParameterLookupTag? =
@@ -211,7 +211,7 @@ class FirTypeDeserializer(
} }
else -> null else -> null
} }
return result ?: ConeClassErrorType( return result ?: ConeErrorType(
ConeSimpleDiagnostic( ConeSimpleDiagnostic(
"Bad suspend function in metadata with constructor: $functionTypeConstructor", "Bad suspend function in metadata with constructor: $functionTypeConstructor",
DiagnosticKind.DeserializationError DiagnosticKind.DeserializationError
@@ -240,7 +240,7 @@ class FirTypeDeserializer(
val variance = ProtoEnumFlags.variance(typeArgumentProto.projection) val variance = ProtoEnumFlags.variance(typeArgumentProto.projection)
val type = typeArgumentProto.type(typeTable) val type = typeArgumentProto.type(typeTable)
?: return ConeKotlinErrorType(ConeSimpleDiagnostic("No type recorded", DiagnosticKind.DeserializationError)) ?: return ConeErrorType(ConeSimpleDiagnostic("No type recorded", DiagnosticKind.DeserializationError))
val coneType = type(type) val coneType = type(type)
return coneType.toTypeProjection(variance) return coneType.toTypeProjection(variance)
} }
@@ -652,7 +652,7 @@ class FirElementSerializer private constructor(
val builder = ProtoBuf.Type.newBuilder() val builder = ProtoBuf.Type.newBuilder()
when (type) { when (type) {
is ConeDefinitelyNotNullType -> return typeProto(type.original, toSuper, correspondingTypeRef, isDefinitelyNotNullType = true) is ConeDefinitelyNotNullType -> return typeProto(type.original, toSuper, correspondingTypeRef, isDefinitelyNotNullType = true)
is ConeKotlinErrorType -> { is ConeErrorType -> {
extension.serializeErrorType(type, builder) extension.serializeErrorType(type, builder)
return builder return builder
} }
@@ -9,7 +9,7 @@ import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.expressions.FirAnnotation import org.jetbrains.kotlin.fir.expressions.FirAnnotation
import org.jetbrains.kotlin.fir.types.ConeFlexibleType import org.jetbrains.kotlin.fir.types.ConeFlexibleType
import org.jetbrains.kotlin.fir.types.ConeKotlinErrorType import org.jetbrains.kotlin.fir.types.ConeErrorType
import org.jetbrains.kotlin.metadata.ProtoBuf import org.jetbrains.kotlin.metadata.ProtoBuf
import org.jetbrains.kotlin.metadata.deserialization.BinaryVersion import org.jetbrains.kotlin.metadata.deserialization.BinaryVersion
import org.jetbrains.kotlin.metadata.serialization.MutableVersionRequirementTable import org.jetbrains.kotlin.metadata.serialization.MutableVersionRequirementTable
@@ -83,7 +83,7 @@ abstract class FirSerializerExtension {
open fun serializeTypeAlias(typeAlias: FirTypeAlias, proto: ProtoBuf.TypeAlias.Builder) { open fun serializeTypeAlias(typeAlias: FirTypeAlias, proto: ProtoBuf.TypeAlias.Builder) {
} }
open fun serializeErrorType(type: ConeKotlinErrorType, builder: ProtoBuf.Type.Builder) { open fun serializeErrorType(type: ConeErrorType, builder: ProtoBuf.Type.Builder) {
throw IllegalStateException("Cannot serialize error type: $type") throw IllegalStateException("Cannot serialize error type: $type")
} }
@@ -152,7 +152,7 @@ internal class KClassValue(value: Value) : ConstantValue<KClassValue.Value>(valu
companion object { companion object {
fun create(argumentType: ConeKotlinType): ConstantValue<*>? { fun create(argumentType: ConeKotlinType): ConstantValue<*>? {
if (argumentType is ConeKotlinErrorType) return null if (argumentType is ConeErrorType) return null
if (argumentType !is ConeClassLikeType) return null if (argumentType !is ConeClassLikeType) return null
var type = argumentType var type = argumentType
var arrayDimensions = 0 var arrayDimensions = 0
@@ -274,7 +274,7 @@ class FirJvmSerializerExtension(
(grandParent.classKind == ClassKind.INTERFACE || grandParent.classKind == ClassKind.ANNOTATION_CLASS) (grandParent.classKind == ClassKind.INTERFACE || grandParent.classKind == ClassKind.ANNOTATION_CLASS)
} }
override fun serializeErrorType(type: ConeKotlinErrorType, builder: ProtoBuf.Type.Builder) { override fun serializeErrorType(type: ConeErrorType, builder: ProtoBuf.Type.Builder) {
if (classBuilderMode === ClassBuilderMode.KAPT3) { if (classBuilderMode === ClassBuilderMode.KAPT3) {
builder.className = stringTable.getStringIndex(NON_EXISTENT_CLASS_NAME) builder.className = stringTable.getStringIndex(NON_EXISTENT_CLASS_NAME)
return return
@@ -47,7 +47,7 @@ class FirMetadataSerializer(
) : MetadataSerializer { ) : MetadataSerializer {
private val approximator = object : AbstractTypeApproximator(session.typeContext, session.languageVersionSettings) { private val approximator = object : AbstractTypeApproximator(session.typeContext, session.languageVersionSettings) {
override fun createErrorType(debugName: String): SimpleTypeMarker { override fun createErrorType(debugName: String): SimpleTypeMarker {
return ConeKotlinErrorType(ConeIntermediateDiagnostic(debugName)) return ConeErrorType(ConeIntermediateDiagnostic(debugName))
} }
} }
@@ -106,7 +106,7 @@ class Fir2IrTypeConverter(
addRawTypeAnnotation: Boolean = false addRawTypeAnnotation: Boolean = false
): IrType { ): IrType {
return when (this) { return when (this) {
is ConeKotlinErrorType -> createErrorType() is ConeErrorType -> createErrorType()
is ConeLookupTagBasedType -> { is ConeLookupTagBasedType -> {
val typeAnnotations = mutableListOf<IrConstructorCall>() val typeAnnotations = mutableListOf<IrConstructorCall>()
typeAnnotations += with(annotationGenerator) { annotations.toIrAnnotations() } typeAnnotations += with(annotationGenerator) { annotations.toIrAnnotations() }
@@ -266,7 +266,7 @@ private fun ConeKotlinType.mapToCanonicalString(session: FirSession): String {
private fun ConeClassLikeType.mapToCanonicalString(session: FirSession): String { private fun ConeClassLikeType.mapToCanonicalString(session: FirSession): String {
return when (this) { return when (this) {
is ConeClassErrorType -> ERROR_TYPE_STUB is ConeErrorType -> ERROR_TYPE_STUB
else -> fullyExpandedType(session).mapToCanonicalNoExpansionString(session) else -> fullyExpandedType(session).mapToCanonicalNoExpansionString(session)
} }
} }
@@ -59,7 +59,7 @@ internal fun FirTypeRef.toConeKotlinTypeProbablyFlexible(
mode: FirJavaTypeConversionMode = FirJavaTypeConversionMode.DEFAULT mode: FirJavaTypeConversionMode = FirJavaTypeConversionMode.DEFAULT
): ConeKotlinType = ): ConeKotlinType =
(resolveIfJavaType(session, javaTypeParameterStack, mode) as? FirResolvedTypeRef)?.type (resolveIfJavaType(session, javaTypeParameterStack, mode) as? FirResolvedTypeRef)?.type
?: ConeKotlinErrorType(ConeSimpleDiagnostic("Type reference in Java not resolved: ${this::class.java}", DiagnosticKind.Java)) ?: ConeErrorType(ConeSimpleDiagnostic("Type reference in Java not resolved: ${this::class.java}", DiagnosticKind.Java))
internal fun JavaType.toFirJavaTypeRef(session: FirSession, javaTypeParameterStack: JavaTypeParameterStack): FirJavaTypeRef { internal fun JavaType.toFirJavaTypeRef(session: FirSession, javaTypeParameterStack: JavaTypeParameterStack): FirJavaTypeRef {
return buildJavaTypeRef { return buildJavaTypeRef {
@@ -202,7 +202,7 @@ private fun JavaClassifierType.toConeKotlinTypeForFlexibleBound(
val classId = ClassId.topLevel(FqName(this.classifierQualifiedName)) val classId = ClassId.topLevel(FqName(this.classifierQualifiedName))
classId.constructClassLikeType(emptyArray(), isNullable = lowerBound != null, attributes) classId.constructClassLikeType(emptyArray(), isNullable = lowerBound != null, attributes)
} }
else -> ConeKotlinErrorType(ConeSimpleDiagnostic("Unexpected classifier: $classifier", DiagnosticKind.Java)) else -> ConeErrorType(ConeSimpleDiagnostic("Unexpected classifier: $classifier", DiagnosticKind.Java))
} }
} }
@@ -233,7 +233,7 @@ private fun List<FirTypeParameterSymbol>.eraseToUpperBounds(session: FirSession)
private fun FirTypeParameter.eraseToUpperBound(session: FirSession, cache: MutableMap<FirTypeParameter, ConeKotlinType>): ConeKotlinType { private fun FirTypeParameter.eraseToUpperBound(session: FirSession, cache: MutableMap<FirTypeParameter, ConeKotlinType>): ConeKotlinType {
return cache.getOrPut(this) { return cache.getOrPut(this) {
// Mark to avoid loops. // Mark to avoid loops.
cache[this] = ConeKotlinErrorType(ConeIntermediateDiagnostic("self-recursive type parameter $name")) cache[this] = ConeErrorType(ConeIntermediateDiagnostic("self-recursive type parameter $name"))
// We can assume that Java type parameter bounds are already converted. // We can assume that Java type parameter bounds are already converted.
symbol.resolvedBounds.first().coneType.eraseAsUpperBound(session, cache) symbol.resolvedBounds.first().coneType.eraseAsUpperBound(session, cache)
} }
@@ -77,7 +77,7 @@ internal fun JavaAnnotationArgument.toFirExpression(
typeRef = it typeRef = it
buildResolvedTypeRef { buildResolvedTypeRef {
type = it.coneTypeSafe<ConeKotlinType>()?.lowerBoundIfFlexible()?.arrayElementType() type = it.coneTypeSafe<ConeKotlinType>()?.lowerBoundIfFlexible()?.arrayElementType()
?: ConeClassErrorType(ConeSimpleDiagnostic("expected type is not array type")) ?: ConeErrorType(ConeSimpleDiagnostic("expected type is not array type"))
} }
} }
argumentList = buildArgumentList { argumentList = buildArgumentList {
@@ -111,7 +111,7 @@ private fun StringBuilder.appendConeType(
} }
when (coneType) { when (coneType) {
is ConeClassErrorType -> Unit // TODO: just skipping it seems wrong is ConeErrorType -> Unit // TODO: just skipping it seems wrong
is ConeClassLikeType -> { is ConeClassLikeType -> {
appendClassLikeType(coneType) appendClassLikeType(coneType)
} }
@@ -42,7 +42,7 @@ inline fun FirFunctionCall.copyAsImplicitInvokeCall(
fun FirTypeRef.resolvedTypeFromPrototype( fun FirTypeRef.resolvedTypeFromPrototype(
type: ConeKotlinType type: ConeKotlinType
): FirResolvedTypeRef { ): FirResolvedTypeRef {
return if (type is ConeKotlinErrorType) { return if (type is ConeErrorType) {
buildErrorTypeRef { buildErrorTypeRef {
source = this@resolvedTypeFromPrototype.source source = this@resolvedTypeFromPrototype.source
this.type = type this.type = type
@@ -58,7 +58,7 @@ fun ConeKotlinType.scope(
private fun ConeKotlinType.scope(useSiteSession: FirSession, scopeSession: ScopeSession, requiredPhase: FirResolvePhase): FirTypeScope? { private fun ConeKotlinType.scope(useSiteSession: FirSession, scopeSession: ScopeSession, requiredPhase: FirResolvePhase): FirTypeScope? {
return when (this) { return when (this) {
is ConeKotlinErrorType -> null is ConeErrorType -> null
is ConeClassLikeType -> { is ConeClassLikeType -> {
val fullyExpandedType = fullyExpandedType(useSiteSession) val fullyExpandedType = fullyExpandedType(useSiteSession)
val fir = fullyExpandedType.lookupTag.toSymbol(useSiteSession)?.fir as? FirClass ?: return null val fir = fullyExpandedType.lookupTag.toSymbol(useSiteSession)?.fir as? FirClass ?: return null
@@ -191,7 +191,7 @@ private fun FirClassifierSymbol<*>.collectSuperTypes(
list += superClassTypes list += superClassTypes
if (deep) if (deep)
superClassTypes.forEach { superClassTypes.forEach {
if (it !is ConeClassErrorType) { if (it !is ConeErrorType) {
if (substituteSuperTypes) { if (substituteSuperTypes) {
val substitutedTypes = SmartList<ConeClassLikeType>() val substitutedTypes = SmartList<ConeClassLikeType>()
it.lookupTag.toSymbol(useSiteSession)?.collectSuperTypes( it.lookupTag.toSymbol(useSiteSession)?.collectSuperTypes(
@@ -234,7 +234,7 @@ private fun FirClassifierSymbol<*>.collectSuperTypes(
private fun ConeClassLikeType?.isClassBasedType( private fun ConeClassLikeType?.isClassBasedType(
useSiteSession: FirSession useSiteSession: FirSession
): Boolean { ): Boolean {
if (this is ConeClassErrorType) return false if (this is ConeErrorType) return false
val symbol = this?.lookupTag?.toSymbol(useSiteSession) as? FirClassSymbol ?: return false val symbol = this?.lookupTag?.toSymbol(useSiteSession) as? FirClassSymbol ?: return false
return when (symbol) { return when (symbol) {
is FirAnonymousObjectSymbol -> true is FirAnonymousObjectSymbol -> true
@@ -245,7 +245,7 @@ private fun ConeClassLikeType?.isClassBasedType(
fun createSubstitutionForSupertype(superType: ConeLookupTagBasedType, session: FirSession): ConeSubstitutor { fun createSubstitutionForSupertype(superType: ConeLookupTagBasedType, session: FirSession): ConeSubstitutor {
val klass = superType.lookupTag.toSymbol(session)?.fir as? FirRegularClass ?: return ConeSubstitutor.Empty val klass = superType.lookupTag.toSymbol(session)?.fir as? FirRegularClass ?: return ConeSubstitutor.Empty
val arguments = superType.typeArguments.map { val arguments = superType.typeArguments.map {
it as? ConeKotlinType ?: ConeClassErrorType(ConeSimpleDiagnostic("illegal projection usage", DiagnosticKind.IllegalProjectionUsage)) it as? ConeKotlinType ?: ConeErrorType(ConeSimpleDiagnostic("illegal projection usage", DiagnosticKind.IllegalProjectionUsage))
} }
val mapping = klass.typeParameters.map { it.symbol }.zip(arguments).toMap() val mapping = klass.typeParameters.map { it.symbol }.zip(arguments).toMap()
return ConeSubstitutorByMap(mapping, session) return ConeSubstitutorByMap(mapping, session)
@@ -129,7 +129,7 @@ private fun mapTypeAliasArguments(
val mappedProjection = typeAliasMap[symbol] ?: return super.substituteArgument(projection, lookupTag, index) val mappedProjection = typeAliasMap[symbol] ?: return super.substituteArgument(projection, lookupTag, index)
var mappedType = (mappedProjection as? ConeKotlinTypeProjection)?.type.updateNullabilityIfNeeded(type) var mappedType = (mappedProjection as? ConeKotlinTypeProjection)?.type.updateNullabilityIfNeeded(type)
mappedType = when (mappedType) { mappedType = when (mappedType) {
is ConeClassErrorType, is ConeErrorType,
is ConeClassLikeTypeImpl, is ConeClassLikeTypeImpl,
is ConeDefinitelyNotNullType, is ConeDefinitelyNotNullType,
is ConeTypeParameterTypeImpl, is ConeTypeParameterTypeImpl,
@@ -46,7 +46,7 @@ abstract class AbstractExplicitReceiverValue<E : FirExpression> : AbstractExplic
override val type: ConeKotlinType override val type: ConeKotlinType
// NB: safe cast is necessary here // NB: safe cast is necessary here
get() = explicitReceiver.typeRef.coneTypeSafe() get() = explicitReceiver.typeRef.coneTypeSafe()
?: ConeKotlinErrorType(ConeIntermediateDiagnostic("No type calculated for: ${explicitReceiver.renderWithType()}")) // TODO: assert here ?: ConeErrorType(ConeIntermediateDiagnostic("No type calculated for: ${explicitReceiver.renderWithType()}")) // TODO: assert here
override val receiverExpression: FirExpression override val receiverExpression: FirExpression
get() = explicitReceiver get() = explicitReceiver
@@ -54,7 +54,7 @@ abstract class AbstractConeSubstitutor(protected val typeContext: ConeTypeContex
private fun ConeKotlinType.substituteRecursive(): ConeKotlinType? { private fun ConeKotlinType.substituteRecursive(): ConeKotlinType? {
return when (this) { return when (this) {
is ConeClassErrorType -> return null is ConeErrorType -> return null
is ConeClassLikeType -> this.substituteArguments() is ConeClassLikeType -> this.substituteArguments()
is ConeLookupTagBasedType -> return null is ConeLookupTagBasedType -> return null
is ConeFlexibleType -> this.substituteBounds()?.let { is ConeFlexibleType -> this.substituteBounds()?.let {
@@ -20,7 +20,7 @@ import org.jetbrains.kotlin.fir.scopes.impl.*
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
import org.jetbrains.kotlin.fir.types.ConeClassErrorType import org.jetbrains.kotlin.fir.types.ConeErrorType
import org.jetbrains.kotlin.fir.types.ConeClassLikeType import org.jetbrains.kotlin.fir.types.ConeClassLikeType
import org.jetbrains.kotlin.fir.types.ConeKotlinType import org.jetbrains.kotlin.fir.types.ConeKotlinType
@@ -124,7 +124,7 @@ fun ConeKotlinType.scopeForSupertype(
subClass: FirClass, subClass: FirClass,
): FirTypeScope? { ): FirTypeScope? {
if (this !is ConeClassLikeType) return null if (this !is ConeClassLikeType) return null
if (this is ConeClassErrorType) return null if (this is ConeErrorType) return null
val symbol = lookupTag.toSymbol(useSiteSession) val symbol = lookupTag.toSymbol(useSiteSession)
return if (symbol is FirRegularClassSymbol) { return if (symbol is FirRegularClassSymbol) {
symbol.fir.scopeForClassImpl( symbol.fir.scopeForClassImpl(
@@ -362,12 +362,12 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo
return isContainedInInvariantOrContravariantPositions return isContainedInInvariantOrContravariantPositions
} }
override fun createErrorType(debugName: String): ConeClassErrorType { override fun createErrorType(debugName: String): ConeErrorType {
return ConeClassErrorType(ConeIntermediateDiagnostic(debugName)) return ConeErrorType(ConeIntermediateDiagnostic(debugName))
} }
override fun createErrorTypeWithCustomConstructor(debugName: String, constructor: TypeConstructorMarker): KotlinTypeMarker { override fun createErrorTypeWithCustomConstructor(debugName: String, constructor: TypeConstructorMarker): KotlinTypeMarker {
return ConeKotlinErrorType(ConeIntermediateDiagnostic("$debugName c: $constructor")) return ConeErrorType(ConeIntermediateDiagnostic("$debugName c: $constructor"))
} }
override fun CapturedTypeMarker.captureStatus(): CaptureStatus { override fun CapturedTypeMarker.captureStatus(): CaptureStatus {
@@ -89,13 +89,13 @@ interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext, Ty
override fun KotlinTypeMarker.isError(): Boolean { override fun KotlinTypeMarker.isError(): Boolean {
assert(this is ConeKotlinType) assert(this is ConeKotlinType)
return this is ConeClassErrorType || this is ConeKotlinErrorType || this.typeConstructor().isError() || return this is ConeErrorType || this is ConeErrorType || this.typeConstructor().isError() ||
(this is ConeClassLikeType && this.lookupTag is ConeClassLikeErrorLookupTag) (this is ConeClassLikeType && this.lookupTag is ConeClassLikeErrorLookupTag)
} }
override fun KotlinTypeMarker.isUninferredParameter(): Boolean { override fun KotlinTypeMarker.isUninferredParameter(): Boolean {
assert(this is ConeKotlinType) assert(this is ConeKotlinType)
return this is ConeClassErrorType && this.isUninferredParameter return this is ConeErrorType && this.isUninferredParameter
} }
override fun FlexibleTypeMarker.asDynamicType(): DynamicTypeMarker? { override fun FlexibleTypeMarker.asDynamicType(): DynamicTypeMarker? {
@@ -96,7 +96,7 @@ fun <T : ConeKotlinType> T.withArguments(arguments: Array<out ConeTypeProjection
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
return when (this) { return when (this) {
is ConeClassErrorType -> this is ConeErrorType -> this
is ConeClassLikeTypeImpl -> ConeClassLikeTypeImpl(lookupTag, arguments, nullability.isNullable) as T is ConeClassLikeTypeImpl -> ConeClassLikeTypeImpl(lookupTag, arguments, nullability.isNullable) as T
is ConeDefinitelyNotNullType -> ConeDefinitelyNotNullType(original.withArguments(arguments)) as T is ConeDefinitelyNotNullType -> ConeDefinitelyNotNullType(original.withArguments(arguments)) as T
else -> error("Not supported: $this: ${this.render()}") else -> error("Not supported: $this: ${this.render()}")
@@ -113,7 +113,7 @@ fun <T : ConeKotlinType> T.withAttributes(attributes: ConeAttributes): T {
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
return when (this) { return when (this) {
is ConeClassErrorType -> this is ConeErrorType -> this
is ConeClassLikeTypeImpl -> ConeClassLikeTypeImpl(lookupTag, typeArguments, nullability.isNullable, attributes) is ConeClassLikeTypeImpl -> ConeClassLikeTypeImpl(lookupTag, typeArguments, nullability.isNullable, attributes)
is ConeDefinitelyNotNullType -> ConeDefinitelyNotNullType(original.withAttributes(attributes)) is ConeDefinitelyNotNullType -> ConeDefinitelyNotNullType(original.withAttributes(attributes))
is ConeTypeParameterTypeImpl -> ConeTypeParameterTypeImpl(lookupTag, nullability.isNullable, attributes) is ConeTypeParameterTypeImpl -> ConeTypeParameterTypeImpl(lookupTag, nullability.isNullable, attributes)
@@ -143,7 +143,7 @@ fun <T : ConeKotlinType> T.withNullability(
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
return when (this) { return when (this) {
is ConeClassErrorType -> this is ConeErrorType -> this
is ConeClassLikeTypeImpl -> ConeClassLikeTypeImpl(lookupTag, typeArguments, nullability.isNullable, attributes) is ConeClassLikeTypeImpl -> ConeClassLikeTypeImpl(lookupTag, typeArguments, nullability.isNullable, attributes)
is ConeTypeParameterTypeImpl -> ConeTypeParameterTypeImpl(lookupTag, nullability.isNullable, attributes) is ConeTypeParameterTypeImpl -> ConeTypeParameterTypeImpl(lookupTag, nullability.isNullable, attributes)
is ConeFlexibleType -> { is ConeFlexibleType -> {
@@ -223,7 +223,7 @@ fun ConeKotlinType.toFirResolvedTypeRef(
source: KtSourceElement? = null, source: KtSourceElement? = null,
delegatedTypeRef: FirTypeRef? = null delegatedTypeRef: FirTypeRef? = null
): FirResolvedTypeRef { ): FirResolvedTypeRef {
return if (this is ConeKotlinErrorType) { return if (this is ConeErrorType) {
buildErrorTypeRef { buildErrorTypeRef {
this.source = source this.source = source
diagnostic = this@toFirResolvedTypeRef.diagnostic diagnostic = this@toFirResolvedTypeRef.diagnostic
@@ -282,7 +282,7 @@ fun FirTypeRef.withReplacedConeType(
else else
this.source this.source
return if (newType is ConeKotlinErrorType) { return if (newType is ConeErrorType) {
buildErrorTypeRef { buildErrorTypeRef {
source = newSource source = newSource
type = newType type = newType
@@ -123,7 +123,7 @@ class FirCallResolver(
resultExpression resultExpression
} }
val typeRef = components.typeFromCallee(resultFunctionCall) val typeRef = components.typeFromCallee(resultFunctionCall)
if (typeRef.type is ConeKotlinErrorType) { if (typeRef.type is ConeErrorType) {
resultFunctionCall.resultType = typeRef resultFunctionCall.resultType = typeRef
} }
@@ -60,7 +60,7 @@ fun FirFunction.constructFunctionalType(isSuspend: Boolean = false): ConeLookupT
else -> null else -> null
} }
val parameters = valueParameters.map { val parameters = valueParameters.map {
it.returnTypeRef.coneTypeSafe<ConeKotlinType>() ?: ConeKotlinErrorType( it.returnTypeRef.coneTypeSafe<ConeKotlinType>() ?: ConeErrorType(
ConeSimpleDiagnostic( ConeSimpleDiagnostic(
"No type for parameter", "No type for parameter",
DiagnosticKind.ValueParameterWithNoTypeAnnotation DiagnosticKind.ValueParameterWithNoTypeAnnotation
@@ -235,7 +235,7 @@ fun <T : FirResolvable> BodyResolveComponents.typeFromCallee(access: T): FirReso
val implicitReceiver = implicitReceiverStack[labelName] val implicitReceiver = implicitReceiverStack[labelName]
buildResolvedTypeRef { buildResolvedTypeRef {
source = null source = null
type = implicitReceiver?.type ?: ConeKotlinErrorType( type = implicitReceiver?.type ?: ConeErrorType(
ConeSimpleDiagnostic( ConeSimpleDiagnostic(
"Unresolved this@$labelName", "Unresolved this@$labelName",
DiagnosticKind.UnresolvedLabel DiagnosticKind.UnresolvedLabel
@@ -61,7 +61,7 @@ class FirSamResolverImpl(
getFunctionTypeForPossibleSamType(type.lowerBound)?.lowerBoundIfFlexible() ?: return null, getFunctionTypeForPossibleSamType(type.lowerBound)?.lowerBoundIfFlexible() ?: return null,
getFunctionTypeForPossibleSamType(type.upperBound)?.upperBoundIfFlexible() ?: return null, getFunctionTypeForPossibleSamType(type.upperBound)?.upperBoundIfFlexible() ?: return null,
) )
is ConeClassErrorType, is ConeStubType -> null is ConeErrorType, is ConeStubType -> null
// TODO: support those types as well // TODO: support those types as well
is ConeTypeParameterType, is ConeTypeVariableType, is ConeTypeParameterType, is ConeTypeVariableType,
is ConeCapturedType, is ConeDefinitelyNotNullType, is ConeIntersectionType, is ConeCapturedType, is ConeDefinitelyNotNullType, is ConeIntersectionType,
@@ -356,7 +356,7 @@ private val PUBLIC_METHOD_NAMES_IN_OBJECT = setOf("equals", "hashCode", "getClas
private fun FirSimpleFunction.getFunctionTypeForAbstractMethod(): ConeLookupTagBasedType { private fun FirSimpleFunction.getFunctionTypeForAbstractMethod(): ConeLookupTagBasedType {
val parameterTypes = valueParameters.map { val parameterTypes = valueParameters.map {
it.returnTypeRef.coneTypeSafe<ConeKotlinType>() ?: ConeKotlinErrorType(ConeIntermediateDiagnostic("No type for parameter $it")) it.returnTypeRef.coneTypeSafe<ConeKotlinType>() ?: ConeErrorType(ConeIntermediateDiagnostic("No type for parameter $it"))
} }
return createFunctionalType( return createFunctionalType(
@@ -138,7 +138,7 @@ private fun buildReflectionType(
) to callableReferenceAdaptation ) to callableReferenceAdaptation
} }
is FirVariable -> createKPropertyType(fir, receiverType, returnTypeRef, candidate) to null is FirVariable -> createKPropertyType(fir, receiverType, returnTypeRef, candidate) to null
else -> ConeClassErrorType(ConeUnsupportedCallableReferenceTarget(candidate)) to null else -> ConeErrorType(ConeUnsupportedCallableReferenceTarget(candidate)) to null
} }
} }
@@ -18,7 +18,7 @@ import org.jetbrains.kotlin.fir.resolve.calls.ResolutionContext
import org.jetbrains.kotlin.fir.resolve.inference.model.ConeFixVariableConstraintPosition import org.jetbrains.kotlin.fir.resolve.inference.model.ConeFixVariableConstraintPosition
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.BodyResolveContext import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.BodyResolveContext
import org.jetbrains.kotlin.fir.returnExpressions import org.jetbrains.kotlin.fir.returnExpressions
import org.jetbrains.kotlin.fir.types.ConeClassErrorType import org.jetbrains.kotlin.fir.types.ConeErrorType
import org.jetbrains.kotlin.fir.types.ConeKotlinType import org.jetbrains.kotlin.fir.types.ConeKotlinType
import org.jetbrains.kotlin.fir.types.ConeTypeVariable import org.jetbrains.kotlin.fir.types.ConeTypeVariable
import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintSystemCompletionContext import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintSystemCompletionContext
@@ -444,7 +444,7 @@ class ConstraintSystemCompleter(components: BodyResolveComponents, private val c
} }
private fun createCannotInferErrorType(message: String, isUninferredParameter: Boolean = false) = private fun createCannotInferErrorType(message: String, isUninferredParameter: Boolean = false) =
ConeClassErrorType( ConeErrorType(
ConeSimpleDiagnostic( ConeSimpleDiagnostic(
message, message,
DiagnosticKind.CannotInferParameterType, DiagnosticKind.CannotInferParameterType,
@@ -78,7 +78,7 @@ fun extractLambdaInfoFromFunctionalType(
argumentValueParameters.mapIndexed { index, parameter -> argumentValueParameters.mapIndexed { index, parameter ->
parameter.returnTypeRef.coneTypeSafe() parameter.returnTypeRef.coneTypeSafe()
?: expectedParameters.getOrNull(index) ?: expectedParameters.getOrNull(index)
?: ConeClassErrorType( ?: ConeErrorType(
ConeSimpleDiagnostic("Cannot infer type for parameter ${parameter.name}", DiagnosticKind.CannotInferParameterType) ConeSimpleDiagnostic("Cannot infer type for parameter ${parameter.name}", DiagnosticKind.CannotInferParameterType)
) )
} }
@@ -226,12 +226,12 @@ class FirTypeResolverImpl(private val session: FirSession) : FirTypeResolver() {
} else { } else {
ConeUnresolvedQualifierError(typeRef.render()) ConeUnresolvedQualifierError(typeRef.render())
} }
return ConeKotlinErrorType(diagnostic) return ConeErrorType(diagnostic)
} }
if (symbol is FirTypeParameterSymbol) { if (symbol is FirTypeParameterSymbol) {
for (part in typeRef.qualifier) { for (part in typeRef.qualifier) {
if (part.typeArgumentList.typeArguments.isNotEmpty()) { if (part.typeArgumentList.typeArguments.isNotEmpty()) {
return ConeClassErrorType( return ConeErrorType(
ConeUnexpectedTypeArgumentsError("Type arguments not allowed", part.typeArgumentList.source) ConeUnexpectedTypeArgumentsError("Type arguments not allowed", part.typeArgumentList.source)
) )
} }
@@ -304,7 +304,7 @@ class FirTypeResolverImpl(private val session: FirSession) : FirTypeResolver() {
allTypeArguments.add(substituted) allTypeArguments.add(substituted)
} }
} else { } else {
return ConeClassErrorType(ConeOuterClassArgumentsRequired(parameterClass.symbol)) return ConeErrorType(ConeOuterClassArgumentsRequired(parameterClass.symbol))
} }
} }
@@ -403,14 +403,14 @@ class FirTypeResolverImpl(private val session: FirSession) : FirTypeResolver() {
symbol: FirClassLikeSymbol<*>, symbol: FirClassLikeSymbol<*>,
userTypeRef: FirUserTypeRef, userTypeRef: FirUserTypeRef,
qualifierPartArgumentsCount: Int? qualifierPartArgumentsCount: Int?
): ConeClassErrorType? { ): ConeErrorType? {
// TODO: It should be TYPE_ARGUMENTS_NOT_ALLOWED diagnostics when parameterClass is null // TODO: It should be TYPE_ARGUMENTS_NOT_ALLOWED diagnostics when parameterClass is null
val actualTypeParametersCount = getActualTypeParametersCount(parameterClass ?: symbol.fir) val actualTypeParametersCount = getActualTypeParametersCount(parameterClass ?: symbol.fir)
if (qualifierPartArgumentsCount == null || actualTypeParametersCount != qualifierPartArgumentsCount) { if (qualifierPartArgumentsCount == null || actualTypeParametersCount != qualifierPartArgumentsCount) {
val source = getTypeArgumentsOrNameSource(userTypeRef, qualifierPartIndex) val source = getTypeArgumentsOrNameSource(userTypeRef, qualifierPartIndex)
if (source != null) { if (source != null) {
return ConeClassErrorType( return ConeErrorType(
ConeWrongNumberOfTypeArgumentsError( ConeWrongNumberOfTypeArgumentsError(
actualTypeParametersCount, actualTypeParametersCount,
parameterClass?.symbol ?: symbol, parameterClass?.symbol ?: symbol,
@@ -484,11 +484,11 @@ class FirTypeResolverImpl(private val session: FirSession) : FirTypeResolver() {
) to diagnostic ) to diagnostic
} }
is FirFunctionTypeRef -> createFunctionalType(typeRef) to null is FirFunctionTypeRef -> createFunctionalType(typeRef) to null
is FirDynamicTypeRef -> ConeKotlinErrorType(ConeUnsupportedDynamicType()) to null is FirDynamicTypeRef -> ConeErrorType(ConeUnsupportedDynamicType()) to null
is FirIntersectionTypeRef -> { is FirIntersectionTypeRef -> {
val (leftType, leftDiagnostic) = resolveType( val (leftType, leftDiagnostic) = resolveType(
typeRef.leftType typeRef.leftType
?: return ConeKotlinErrorType(ConeSimpleDiagnostic("Problem during processing intersection type")) to null, ?: return ConeErrorType(ConeSimpleDiagnostic("Problem during processing intersection type")) to null,
scopeClassDeclaration, scopeClassDeclaration,
areBareTypesAllowed, areBareTypesAllowed,
isOperandOfIsOperator, isOperandOfIsOperator,
@@ -497,7 +497,7 @@ class FirTypeResolverImpl(private val session: FirSession) : FirTypeResolver() {
) )
val (rightType, _) = resolveType( val (rightType, _) = resolveType(
typeRef.rightType typeRef.rightType
?: return ConeKotlinErrorType(ConeSimpleDiagnostic("Problem during processing intersection type")) to null, ?: return ConeErrorType(ConeSimpleDiagnostic("Problem during processing intersection type")) to null,
scopeClassDeclaration, scopeClassDeclaration,
areBareTypesAllowed, areBareTypesAllowed,
isOperandOfIsOperator, isOperandOfIsOperator,
@@ -508,7 +508,7 @@ class FirTypeResolverImpl(private val session: FirSession) : FirTypeResolver() {
if (rightType.isAny && leftType is ConeTypeParameterType) { if (rightType.isAny && leftType is ConeTypeParameterType) {
ConeDefinitelyNotNullType(leftType) to leftDiagnostic //how properly concat (leftDiagnostic + rightDiagnostic)? ConeDefinitelyNotNullType(leftType) to leftDiagnostic //how properly concat (leftDiagnostic + rightDiagnostic)?
} else { } else {
ConeKotlinErrorType(ConeUnsupported("Intersection types are not supported yet", typeRef.source)) to null ConeErrorType(ConeUnsupported("Intersection types are not supported yet", typeRef.source)) to null
} }
} }
@@ -500,7 +500,7 @@ class FirCallCompletionResultsWriterTransformer(
val typeRef = argument.typeRef as FirResolvedTypeRef val typeRef = argument.typeRef as FirResolvedTypeRef
buildTypeProjectionWithVariance { buildTypeProjectionWithVariance {
source = argument.source source = argument.source
this.typeRef = if (typeRef.type is ConeClassErrorType) typeRef else typeRef.withReplacedConeType(type) this.typeRef = if (typeRef.type is ConeErrorType) typeRef else typeRef.withReplacedConeType(type)
variance = argument.variance variance = argument.variance
} }
} }
@@ -107,7 +107,7 @@ class FirSpecificTypeResolverTransformer(
) )
val resolvedType = resolvedTypeWithDiagnostic.first.takeIfAcceptable() val resolvedType = resolvedTypeWithDiagnostic.first.takeIfAcceptable()
val diagnostic = resolvedTypeWithDiagnostic.second val diagnostic = resolvedTypeWithDiagnostic.second
return if (resolvedType != null && resolvedType !is ConeClassErrorType && diagnostic == null) { return if (resolvedType != null && resolvedType !is ConeErrorType && diagnostic == null) {
buildResolvedTypeRef { buildResolvedTypeRef {
source = functionTypeRef.source source = functionTypeRef.source
type = resolvedType type = resolvedType
@@ -120,7 +120,7 @@ class FirSpecificTypeResolverTransformer(
if (resolvedType != null) { if (resolvedType != null) {
type = resolvedType type = resolvedType
} }
this.diagnostic = diagnostic ?: (resolvedType as? ConeClassErrorType)?.diagnostic this.diagnostic = diagnostic ?: (resolvedType as? ConeErrorType)?.diagnostic
?: ConeSimpleDiagnostic("Unresolved functional type: ${functionTypeRef.render()}") ?: ConeSimpleDiagnostic("Unresolved functional type: ${functionTypeRef.render()}")
} }
} }
@@ -128,7 +128,7 @@ class FirSpecificTypeResolverTransformer(
private fun transformType(typeRef: FirTypeRef, resolvedType: ConeKotlinType, diagnostic: ConeDiagnostic?): FirResolvedTypeRef { private fun transformType(typeRef: FirTypeRef, resolvedType: ConeKotlinType, diagnostic: ConeDiagnostic?): FirResolvedTypeRef {
return when { return when {
resolvedType is ConeClassErrorType -> { resolvedType is ConeErrorType -> {
buildErrorTypeRef { buildErrorTypeRef {
val typeRefSourceKind = typeRef.source?.kind val typeRefSourceKind = typeRef.source?.kind
val diagnosticSource = resolvedType.diagnostic.safeAs<ConeUnexpectedTypeArgumentsError>() val diagnosticSource = resolvedType.diagnostic.safeAs<ConeUnexpectedTypeArgumentsError>()
@@ -170,7 +170,7 @@ class FirSpecificTypeResolverTransformer(
} }
private fun ConeKotlinType.takeIfAcceptable(): ConeKotlinType? = this.takeUnless { private fun ConeKotlinType.takeIfAcceptable(): ConeKotlinType? = this.takeUnless {
!errorTypeAsResolved && it is ConeClassErrorType !errorTypeAsResolved && it is ConeErrorType
} }
override fun transformResolvedTypeRef(resolvedTypeRef: FirResolvedTypeRef, data: ScopeClassDeclaration): FirTypeRef { override fun transformResolvedTypeRef(resolvedTypeRef: FirResolvedTypeRef, data: ScopeClassDeclaration): FirTypeRef {
@@ -106,7 +106,7 @@ fun FirBlock.writeResultType(session: FirSession) {
fun ConstantValueKind<*>.expectedConeType(session: FirSession): ConeKotlinType { fun ConstantValueKind<*>.expectedConeType(session: FirSession): ConeKotlinType {
fun constructLiteralType(classId: ClassId, isNullable: Boolean = false): ConeKotlinType { fun constructLiteralType(classId: ClassId, isNullable: Boolean = false): ConeKotlinType {
val symbol = session.symbolProvider.getClassLikeSymbolByClassId(classId) val symbol = session.symbolProvider.getClassLikeSymbolByClassId(classId)
?: return ConeClassErrorType(ConeSimpleDiagnostic("Missing stdlib class: $classId", DiagnosticKind.MissingStdlibClass)) ?: return ConeErrorType(ConeSimpleDiagnostic("Missing stdlib class: $classId", DiagnosticKind.MissingStdlibClass))
return symbol.toLookupTag().constructClassType(emptyArray(), isNullable) return symbol.toLookupTag().constructClassType(emptyArray(), isNullable)
} }
return when (this) { return when (this) {
@@ -1067,7 +1067,7 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor
valueParameter.transformReturnTypeRef( valueParameter.transformReturnTypeRef(
StoreType, StoreType,
valueParameter.returnTypeRef.resolvedTypeFromPrototype( valueParameter.returnTypeRef.resolvedTypeFromPrototype(
ConeKotlinErrorType( ConeErrorType(
ConeSimpleDiagnostic( ConeSimpleDiagnostic(
"No type for parameter", "No type for parameter",
DiagnosticKind.ValueParameterWithNoTypeAnnotation DiagnosticKind.ValueParameterWithNoTypeAnnotation
@@ -998,7 +998,7 @@ open class FirExpressionsResolveTransformer(transformer: FirBodyResolveTransform
is FirSuperReference -> { is FirSuperReference -> {
// TODO: unresolved supertype // TODO: unresolved supertype
val supertype = reference.superTypeRef.coneTypeSafe<ConeClassLikeType>() val supertype = reference.superTypeRef.coneTypeSafe<ConeClassLikeType>()
?.takeIf { it !is ConeClassErrorType } ?: return delegatedConstructorCall ?.takeIf { it !is ConeErrorType } ?: return delegatedConstructorCall
supertype.fullyExpandedType(session) supertype.fullyExpandedType(session)
} }
else -> return delegatedConstructorCall else -> return delegatedConstructorCall
@@ -40,7 +40,7 @@ fun FirLookupTrackerComponent.recordTypeResolveAsLookup(typeRef: FirTypeRef, sou
if (source == null && fileSource == null) return // TODO: investigate all cases if (source == null && fileSource == null) return // TODO: investigate all cases
fun recordIfValid(type: ConeKotlinType) { fun recordIfValid(type: ConeKotlinType) {
if (type is ConeKotlinErrorType) return // TODO: investigate whether some cases should be recorded, e.g. unresolved if (type is ConeErrorType) return // TODO: investigate whether some cases should be recorded, e.g. unresolved
type.classId?.let { type.classId?.let {
if (!it.isLocal) { if (!it.isLocal) {
if (it.shortClassName.asString() != "Companion") { if (it.shortClassName.asString() != "Companion") {
@@ -5,7 +5,7 @@
package org.jetbrains.kotlin.fir.resolve.dfa package org.jetbrains.kotlin.fir.resolve.dfa
import org.jetbrains.kotlin.fir.types.ConeClassErrorType import org.jetbrains.kotlin.fir.types.ConeErrorType
import org.jetbrains.kotlin.fir.types.ConeKotlinType import org.jetbrains.kotlin.fir.types.ConeKotlinType
import kotlin.contracts.ExperimentalContracts import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.contract import kotlin.contracts.contract
@@ -86,14 +86,14 @@ infix fun DataFlowVariable.notEq(constant: Boolean?): OperationStatement {
infix fun OperationStatement.implies(effect: Statement<*>): Implication = Implication(this, effect) infix fun OperationStatement.implies(effect: Statement<*>): Implication = Implication(this, effect)
infix fun RealVariable.typeEq(type: ConeKotlinType): TypeStatement = infix fun RealVariable.typeEq(type: ConeKotlinType): TypeStatement =
if (type !is ConeClassErrorType) { if (type !is ConeErrorType) {
MutableTypeStatement(this, linkedSetOf<ConeKotlinType>().apply { this += type }, HashSet()) MutableTypeStatement(this, linkedSetOf<ConeKotlinType>().apply { this += type }, HashSet())
} else { } else {
MutableTypeStatement(this) MutableTypeStatement(this)
} }
infix fun RealVariable.typeNotEq(type: ConeKotlinType): TypeStatement = infix fun RealVariable.typeNotEq(type: ConeKotlinType): TypeStatement =
if (type !is ConeClassErrorType) { if (type !is ConeErrorType) {
MutableTypeStatement(this, linkedSetOf(), LinkedHashSet<ConeKotlinType>().apply { this += type }) MutableTypeStatement(this, linkedSetOf(), LinkedHashSet<ConeKotlinType>().apply { this += type })
} else { } else {
MutableTypeStatement(this) MutableTypeStatement(this)
@@ -171,7 +171,7 @@ private fun ConeClassLikeType.withNullability(nullability: ConeNullability): Con
if (nullability == this.nullability) return this if (nullability == this.nullability) return this
return when (this) { return when (this) {
is ConeClassErrorType -> this is ConeErrorType -> this
is ConeClassLikeTypeImpl -> ConeClassLikeTypeImpl(lookupTag, typeArguments, nullability.isNullable) is ConeClassLikeTypeImpl -> ConeClassLikeTypeImpl(lookupTag, typeArguments, nullability.isNullable)
else -> error("sealed") else -> error("sealed")
} }
@@ -8,7 +8,7 @@ package org.jetbrains.kotlin.fir.types
object ConeKotlinTypeComparator : Comparator<ConeKotlinType> { object ConeKotlinTypeComparator : Comparator<ConeKotlinType> {
private val ConeKotlinType.priority : Int private val ConeKotlinType.priority : Int
get() = when (this) { get() = when (this) {
is ConeKotlinErrorType -> 8 is ConeErrorType -> 8
is ConeLookupTagBasedType -> 7 is ConeLookupTagBasedType -> 7
is ConeFlexibleType -> 6 is ConeFlexibleType -> 6
is ConeCapturedType -> 5 is ConeCapturedType -> 5
@@ -72,8 +72,8 @@ object ConeKotlinTypeComparator : Comparator<ConeKotlinType> {
} }
when (a) { when (a) {
is ConeKotlinErrorType -> { is ConeErrorType -> {
require(b is ConeKotlinErrorType) { require(b is ConeErrorType) {
"priority is inconsistent: ${a.render()} v.s. ${b.render()}" "priority is inconsistent: ${a.render()} v.s. ${b.render()}"
} }
return a.hashCode() - b.hashCode() return a.hashCode() - b.hashCode()
@@ -11,7 +11,7 @@ import org.jetbrains.kotlin.fir.builder.FirAnnotationContainerBuilder
import org.jetbrains.kotlin.fir.builder.FirBuilderDsl import org.jetbrains.kotlin.fir.builder.FirBuilderDsl
import org.jetbrains.kotlin.fir.diagnostics.ConeDiagnostic import org.jetbrains.kotlin.fir.diagnostics.ConeDiagnostic
import org.jetbrains.kotlin.fir.expressions.FirAnnotation import org.jetbrains.kotlin.fir.expressions.FirAnnotation
import org.jetbrains.kotlin.fir.types.ConeClassErrorType import org.jetbrains.kotlin.fir.types.ConeErrorType
import org.jetbrains.kotlin.fir.types.ConeKotlinType import org.jetbrains.kotlin.fir.types.ConeKotlinType
import org.jetbrains.kotlin.fir.types.FirErrorTypeRef import org.jetbrains.kotlin.fir.types.FirErrorTypeRef
import org.jetbrains.kotlin.fir.types.FirTypeRef import org.jetbrains.kotlin.fir.types.FirTypeRef
@@ -8,7 +8,7 @@ package org.jetbrains.kotlin.fir.types.impl
import org.jetbrains.kotlin.KtSourceElement import org.jetbrains.kotlin.KtSourceElement
import org.jetbrains.kotlin.fir.diagnostics.ConeDiagnostic import org.jetbrains.kotlin.fir.diagnostics.ConeDiagnostic
import org.jetbrains.kotlin.fir.expressions.FirAnnotation import org.jetbrains.kotlin.fir.expressions.FirAnnotation
import org.jetbrains.kotlin.fir.types.ConeClassErrorType import org.jetbrains.kotlin.fir.types.ConeErrorType
import org.jetbrains.kotlin.fir.types.ConeKotlinType import org.jetbrains.kotlin.fir.types.ConeKotlinType
import org.jetbrains.kotlin.fir.types.FirErrorTypeRef import org.jetbrains.kotlin.fir.types.FirErrorTypeRef
import org.jetbrains.kotlin.fir.types.FirTypeRef import org.jetbrains.kotlin.fir.types.FirTypeRef
@@ -22,7 +22,7 @@ internal class FirErrorTypeRefImpl(
) : FirErrorTypeRef() { ) : FirErrorTypeRef() {
constructor(source: KtSourceElement?, delegatedTypeRef: FirTypeRef?, diagnostic: ConeDiagnostic) : this( constructor(source: KtSourceElement?, delegatedTypeRef: FirTypeRef?, diagnostic: ConeDiagnostic) : this(
source, source,
ConeClassErrorType(diagnostic), ConeErrorType(diagnostic),
delegatedTypeRef, diagnostic delegatedTypeRef, diagnostic
) )
@@ -13,7 +13,7 @@ import org.jetbrains.kotlin.descriptors.Visibility
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
import org.jetbrains.kotlin.fir.tree.generator.context.generatedType import org.jetbrains.kotlin.fir.tree.generator.context.generatedType
import org.jetbrains.kotlin.fir.tree.generator.context.type import org.jetbrains.kotlin.fir.tree.generator.context.type
import org.jetbrains.kotlin.fir.types.ConeClassErrorType import org.jetbrains.kotlin.fir.types.ConeErrorType
import org.jetbrains.kotlin.fir.types.ConeKotlinType import org.jetbrains.kotlin.fir.types.ConeKotlinType
import org.jetbrains.kotlin.fir.types.ConeSimpleKotlinType import org.jetbrains.kotlin.fir.types.ConeSimpleKotlinType
import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.ClassId
@@ -55,7 +55,7 @@ val emptyCfgReferenceType = generatedType("references.impl", "FirEmptyControlFlo
val noReceiverExpressionType = generatedType("expressions.impl", "FirNoReceiverExpression") val noReceiverExpressionType = generatedType("expressions.impl", "FirNoReceiverExpression")
val implicitTypeRefType = generatedType("types.impl", "FirImplicitTypeRefImpl") val implicitTypeRefType = generatedType("types.impl", "FirImplicitTypeRefImpl")
val firQualifierPartType = type("fir.types", "FirQualifierPart") val firQualifierPartType = type("fir.types", "FirQualifierPart")
val coneClassErrorTypeType = type(ConeClassErrorType::class) val ConeErrorTypeType = type(ConeErrorType::class)
val simpleNamedReferenceType = generatedType("references.impl", "FirSimpleNamedReference") val simpleNamedReferenceType = generatedType("references.impl", "FirSimpleNamedReference")
val explicitThisReferenceType = generatedType("references.impl", "FirExplicitThisReference") val explicitThisReferenceType = generatedType("references.impl", "FirExplicitThisReference")
val explicitSuperReferenceType = generatedType("references.impl", "FirExplicitSuperReference") val explicitSuperReferenceType = generatedType("references.impl", "FirExplicitSuperReference")
@@ -276,7 +276,7 @@ class FirResolveBench(val withProgress: Boolean, val listener: BenchListener? =
val callee = functionCall.calleeReference val callee = functionCall.calleeReference
if (typeRef is FirResolvedTypeRef) { if (typeRef is FirResolvedTypeRef) {
val type = typeRef.type val type = typeRef.type
if (type is ConeKotlinErrorType) { if (type is ConeErrorType) {
errorFunctionCallTypes++ errorFunctionCallTypes++
val psi = callee.psi val psi = callee.psi
if (callee is FirErrorNamedReference && psi != null) { if (callee is FirErrorNamedReference && psi != null) {
@@ -293,7 +293,7 @@ class FirResolveBench(val withProgress: Boolean, val listener: BenchListener? =
val callee = qualifiedAccessExpression.calleeReference val callee = qualifiedAccessExpression.calleeReference
if (typeRef is FirResolvedTypeRef) { if (typeRef is FirResolvedTypeRef) {
val type = typeRef.type val type = typeRef.type
if (type is ConeKotlinErrorType) { if (type is ConeErrorType) {
errorQualifiedAccessTypes++ errorQualifiedAccessTypes++
val psi = callee.psi val psi = callee.psi
if (callee is FirErrorNamedReference && psi != null) { if (callee is FirErrorNamedReference && psi != null) {
@@ -329,7 +329,7 @@ class FirResolveBench(val withProgress: Boolean, val listener: BenchListener? =
override fun visitResolvedTypeRef(resolvedTypeRef: FirResolvedTypeRef) { override fun visitResolvedTypeRef(resolvedTypeRef: FirResolvedTypeRef) {
resolvedTypes++ resolvedTypes++
val type = resolvedTypeRef.type val type = resolvedTypeRef.type
if (type is ConeKotlinErrorType || type is ConeClassErrorType) { if (type is ConeErrorType || type is ConeErrorType) {
errorTypes++ errorTypes++
if (resolvedTypeRef is FirErrorTypeRef && resolvedTypeRef.diagnostic is ConeStubDiagnostic) { if (resolvedTypeRef is FirErrorTypeRef && resolvedTypeRef.diagnostic is ConeStubDiagnostic) {
return return
@@ -8,11 +8,11 @@ package org.jetbrains.kotlin.fir
import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.fir.types.*
fun ConeKotlinType.renderForDebugInfo(): String { fun ConeKotlinType.renderForDebugInfo(): String {
val nullabilitySuffix = if (this !is ConeKotlinErrorType && this !is ConeClassErrorType) nullability.suffix else "" val nullabilitySuffix = if (this !is ConeErrorType && this !is ConeErrorType) nullability.suffix else ""
return when (this) { return when (this) {
is ConeTypeVariableType -> "TypeVariable(${this.lookupTag.name})" is ConeTypeVariableType -> "TypeVariable(${this.lookupTag.name})"
is ConeDefinitelyNotNullType -> "${original.renderForDebugInfo()}!!" is ConeDefinitelyNotNullType -> "${original.renderForDebugInfo()}!!"
is ConeClassErrorType -> "ERROR CLASS: ${diagnostic.reason}" is ConeErrorType -> "ERROR CLASS: ${diagnostic.reason}"
is ConeCapturedType -> "CapturedType(${constructor.projection.renderForDebugInfo()})" is ConeCapturedType -> "CapturedType(${constructor.projection.renderForDebugInfo()})"
is ConeClassLikeType -> { is ConeClassLikeType -> {
buildString { buildString {
@@ -386,7 +386,7 @@ class FirVisualizer(private val firFile: FirFile) : BaseRenderer() {
private fun ConeTypeProjection.localTypeRenderer(): String { private fun ConeTypeProjection.localTypeRenderer(): String {
val nullabilitySuffix = when { val nullabilitySuffix = when {
this is ConeKotlinType && this !is ConeKotlinErrorType && this !is ConeClassErrorType -> nullability.suffix this is ConeKotlinType && this !is ConeErrorType && this !is ConeErrorType -> nullability.suffix
else -> "" else -> ""
} }
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.fir.expressions.FirAnnotation
import org.jetbrains.kotlin.fir.expressions.classId import org.jetbrains.kotlin.fir.expressions.classId
import org.jetbrains.kotlin.fir.resolve.lookupSuperTypes import org.jetbrains.kotlin.fir.resolve.lookupSuperTypes
import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
import org.jetbrains.kotlin.fir.types.ConeKotlinErrorType import org.jetbrains.kotlin.fir.types.ConeErrorType
import org.jetbrains.kotlin.fir.types.classId import org.jetbrains.kotlin.fir.types.classId
import org.jetbrains.kotlin.fir.types.coneType import org.jetbrains.kotlin.fir.types.coneType
import org.jetbrains.kotlin.parcelize.ParcelizeNames.CREATOR_NAME import org.jetbrains.kotlin.parcelize.ParcelizeNames.CREATOR_NAME
@@ -64,7 +64,7 @@ object FirParcelizePropertyChecker : FirPropertyChecker() {
reporter: DiagnosticReporter reporter: DiagnosticReporter
) { ) {
val type = property.returnTypeRef.coneType val type = property.returnTypeRef.coneType
if (type is ConeKotlinErrorType || containingClassSymbol.hasCustomParceler(context.session)) return if (type is ConeErrorType || containingClassSymbol.hasCustomParceler(context.session)) return
/* /*
* TODO: abstract code from ParcelSerializer or IrParcelSerializerFactory to avoid duplication * TODO: abstract code from ParcelSerializer or IrParcelSerializerFactory to avoid duplication
* of allowed types checking * of allowed types checking