[Analysis API] separate non-class error types from class error types and add information about type qualifiers
it's needed for type printing in renderer
This commit is contained in:
+2
-2
@@ -46,12 +46,12 @@ private fun ConeDiagnostic.toKtDiagnostic(
|
||||
): KtDiagnostic? = when (this) {
|
||||
is ConeUnresolvedReferenceError -> FirErrors.UNRESOLVED_REFERENCE.createOn(
|
||||
source,
|
||||
(this.name ?: SpecialNames.NO_NAME_PROVIDED).asString()
|
||||
this.name.asString()
|
||||
)
|
||||
|
||||
is ConeUnresolvedSymbolError -> FirErrors.UNRESOLVED_REFERENCE.createOn(source, this.classId.asString())
|
||||
is ConeUnresolvedNameError -> FirErrors.UNRESOLVED_REFERENCE.createOn(source, this.name.asString())
|
||||
is ConeUnresolvedQualifierError -> FirErrors.UNRESOLVED_REFERENCE.createOn(source, this.qualifier)
|
||||
is ConeUnresolvedTypeQualifierError -> FirErrors.UNRESOLVED_REFERENCE.createOn(source, this.qualifier)
|
||||
is ConeFunctionCallExpectedError -> FirErrors.FUNCTION_CALL_EXPECTED.createOn(source, this.name.asString(), this.hasValueParameters)
|
||||
is ConeFunctionExpectedError -> FirErrors.FUNCTION_EXPECTED.createOn(source, this.expression, this.type)
|
||||
is ConeResolutionToClassifierError -> FirErrors.RESOLUTION_TO_CLASSIFIER.createOn(source, this.candidateSymbol)
|
||||
|
||||
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.load.java.structure.*
|
||||
import org.jetbrains.kotlin.load.java.structure.impl.JavaElementImpl
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.name.SpecialNames
|
||||
import org.jetbrains.kotlin.name.StandardClassIds
|
||||
import org.jetbrains.kotlin.toKtPsiSourceElement
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||
@@ -214,7 +215,8 @@ private fun JavaAnnotation.toFirAnnotationCall(
|
||||
type = ConeClassLikeTypeImpl(lookupTag, emptyArray(), isNullable = false)
|
||||
}
|
||||
} else {
|
||||
buildErrorTypeRef { diagnostic = ConeUnresolvedReferenceError() }
|
||||
val unresolvedName = classId?.shortClassName ?: SpecialNames.NO_NAME_PROVIDED
|
||||
buildErrorTypeRef { diagnostic = ConeUnresolvedReferenceError(unresolvedName) }
|
||||
}
|
||||
|
||||
argumentMapping = buildAnnotationArgumentMapping {
|
||||
|
||||
+1
-1
@@ -247,7 +247,7 @@ class FirTypeResolverImpl(private val session: FirSession) : FirTypeResolver() {
|
||||
ConeAmbiguityError(typeRef.qualifier.last().name, result.typeCandidates.first().applicability, result.typeCandidates)
|
||||
}
|
||||
else -> {
|
||||
ConeUnresolvedQualifierError(typeRef.render())
|
||||
ConeUnresolvedTypeQualifierError(typeRef.qualifier, isNullable = typeRef.isMarkedNullable)
|
||||
}
|
||||
}
|
||||
return ConeErrorType(diagnostic, attributes = typeRef.annotations.computeTypeAttributes(session))
|
||||
|
||||
+1
-1
@@ -598,7 +598,7 @@ open class FirExpressionsResolveTransformer(transformer: FirBodyResolveTransform
|
||||
}
|
||||
diagnostic = when {
|
||||
// Use a stub diagnostic to suppress unresolved error here because it would be reported by other logic
|
||||
lhsReference is FirErrorNamedReference -> ConeStubDiagnostic(ConeUnresolvedReferenceError())
|
||||
lhsReference is FirErrorNamedReference -> ConeStubDiagnostic(ConeUnresolvedReferenceError(lhsReference.name))
|
||||
lhsSymbol == null -> ConeVariableExpectedError
|
||||
else -> ConeValReassignmentError(lhsSymbol)
|
||||
}
|
||||
|
||||
+9
-7
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.fir.resolve.calls.AbstractCandidate
|
||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
||||
import org.jetbrains.kotlin.fir.types.FirQualifierPart
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
@@ -22,7 +23,7 @@ import org.jetbrains.kotlin.resolve.calls.tower.CandidateApplicability
|
||||
import org.jetbrains.kotlin.resolve.deprecation.DeprecationInfo
|
||||
|
||||
sealed interface ConeUnresolvedError : ConeDiagnostic {
|
||||
val qualifier: String?
|
||||
val qualifier: String
|
||||
}
|
||||
|
||||
interface ConeDiagnosticWithSymbol<S : FirBasedSymbol<*>> : ConeDiagnostic {
|
||||
@@ -41,9 +42,9 @@ interface ConeDiagnosticWithSingleCandidate : ConeDiagnosticWithCandidates {
|
||||
override val candidateSymbols: Collection<FirBasedSymbol<*>> get() = listOf(candidateSymbol)
|
||||
}
|
||||
|
||||
class ConeUnresolvedReferenceError(val name: Name? = null) : ConeUnresolvedError {
|
||||
override val qualifier: String? get() = name?.asString()
|
||||
override val reason: String get() = "Unresolved reference" + if (name != null) ": ${name.asString()}" else ""
|
||||
class ConeUnresolvedReferenceError(val name: Name) : ConeUnresolvedError {
|
||||
override val qualifier: String get() = if (!name.isSpecial) name.asString() else "NO_NAME"
|
||||
override val reason: String get() = "Unresolved reference: ${name.asString()}"
|
||||
}
|
||||
|
||||
class ConeUnresolvedSymbolError(val classId: ClassId) : ConeUnresolvedError {
|
||||
@@ -51,8 +52,9 @@ class ConeUnresolvedSymbolError(val classId: ClassId) : ConeUnresolvedError {
|
||||
override val reason: String get() = "Symbol not found for $classId"
|
||||
}
|
||||
|
||||
class ConeUnresolvedQualifierError(override val qualifier: String) : ConeUnresolvedError {
|
||||
override val reason: String get() = "Symbol not found for $qualifier"
|
||||
class ConeUnresolvedTypeQualifierError(val qualifiers: List<FirQualifierPart>, val isNullable: Boolean) : ConeUnresolvedError {
|
||||
override val qualifier: String get() = qualifiers.joinToString(separator = ".") { it.name.asString() }
|
||||
override val reason: String get() = "Symbol not found for $qualifier${if (isNullable) "?" else ""}"
|
||||
}
|
||||
|
||||
class ConeUnresolvedNameError(val name: Name) : ConeUnresolvedError {
|
||||
@@ -146,7 +148,7 @@ class ConeIllegalAnnotationError(val name: Name) : ConeDiagnostic {
|
||||
override val reason: String get() = "Not a legal annotation: $name"
|
||||
}
|
||||
|
||||
interface ConeUnmatchedTypeArgumentsError : ConeDiagnosticWithSymbol<FirClassLikeSymbol<*>> {
|
||||
sealed interface ConeUnmatchedTypeArgumentsError : ConeDiagnosticWithSymbol<FirClassLikeSymbol<*>> {
|
||||
val desiredCount: Int
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user