FIR: Add ConeDiagnosticWithCandidates and
ConeDiagnosticWithSingleCandidate to ConeDiagnostic type hierarchy.
This commit is contained in:
committed by
Ilya Kirillov
parent
db38cd95da
commit
16eabf0ff1
+1
-1
@@ -14,7 +14,7 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
|
|||||||
object FirDeprecatedQualifierChecker : FirResolvedQualifierChecker() {
|
object FirDeprecatedQualifierChecker : FirResolvedQualifierChecker() {
|
||||||
override fun check(expression: FirResolvedQualifier, context: CheckerContext, reporter: DiagnosticReporter) {
|
override fun check(expression: FirResolvedQualifier, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||||
expression.nonFatalDiagnostics.filterIsInstance<ConeDeprecated>().forEach { diagnostic ->
|
expression.nonFatalDiagnostics.filterIsInstance<ConeDeprecated>().forEach { diagnostic ->
|
||||||
FirDeprecationChecker.reportDeprecation(diagnostic.source, diagnostic.symbol, diagnostic.deprecation, reporter, context)
|
FirDeprecationChecker.reportDeprecation(diagnostic.source, diagnostic.candidateSymbol, diagnostic.deprecation, reporter, context)
|
||||||
}
|
}
|
||||||
if (expression.resolvedToCompanionObject) {
|
if (expression.resolvedToCompanionObject) {
|
||||||
val companionSymbol = (expression.symbol as? FirRegularClassSymbol)?.companionObjectSymbol ?: return
|
val companionSymbol = (expression.symbol as? FirRegularClassSymbol)?.companionObjectSymbol ?: return
|
||||||
|
|||||||
+10
-7
@@ -42,10 +42,10 @@ private fun ConeDiagnostic.toFirDiagnostic(
|
|||||||
is ConeUnresolvedQualifierError -> FirErrors.UNRESOLVED_REFERENCE.createOn(source, this.qualifier)
|
is ConeUnresolvedQualifierError -> FirErrors.UNRESOLVED_REFERENCE.createOn(source, this.qualifier)
|
||||||
is ConeFunctionCallExpectedError -> FirErrors.FUNCTION_CALL_EXPECTED.createOn(source, this.name.asString(), this.hasValueParameters)
|
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 ConeFunctionExpectedError -> FirErrors.FUNCTION_EXPECTED.createOn(source, this.expression, this.type)
|
||||||
is ConeResolutionToClassifierError -> FirErrors.RESOLUTION_TO_CLASSIFIER.createOn(source, this.classSymbol)
|
is ConeResolutionToClassifierError -> FirErrors.RESOLUTION_TO_CLASSIFIER.createOn(source, this.candidateSymbol)
|
||||||
is ConeHiddenCandidateError -> FirErrors.INVISIBLE_REFERENCE.createOn(source, this.candidateSymbol)
|
is ConeHiddenCandidateError -> FirErrors.INVISIBLE_REFERENCE.createOn(source, this.candidateSymbol)
|
||||||
is ConeInapplicableWrongReceiver -> FirErrors.UNRESOLVED_REFERENCE_WRONG_RECEIVER.createOn(source, this.candidates)
|
is ConeInapplicableWrongReceiver -> FirErrors.UNRESOLVED_REFERENCE_WRONG_RECEIVER.createOn(source, this.candidateSymbols)
|
||||||
is ConeNoCompanionObject -> FirErrors.NO_COMPANION_OBJECT.createOn(source, this.symbol)
|
is ConeNoCompanionObject -> FirErrors.NO_COMPANION_OBJECT.createOn(source, this.candidateSymbol)
|
||||||
is ConeAmbiguityError -> when {
|
is ConeAmbiguityError -> when {
|
||||||
applicability.isSuccess -> FirErrors.OVERLOAD_RESOLUTION_AMBIGUITY.createOn(source, this.candidates.map { it.symbol })
|
applicability.isSuccess -> FirErrors.OVERLOAD_RESOLUTION_AMBIGUITY.createOn(source, this.candidates.map { it.symbol })
|
||||||
applicability == CandidateApplicability.UNSAFE_CALL -> {
|
applicability == CandidateApplicability.UNSAFE_CALL -> {
|
||||||
@@ -65,7 +65,7 @@ private fun ConeDiagnostic.toFirDiagnostic(
|
|||||||
}
|
}
|
||||||
else -> FirErrors.NONE_APPLICABLE.createOn(source, this.candidates.map { it.symbol })
|
else -> FirErrors.NONE_APPLICABLE.createOn(source, this.candidates.map { it.symbol })
|
||||||
}
|
}
|
||||||
is ConeOperatorAmbiguityError -> FirErrors.ASSIGN_OPERATOR_AMBIGUITY.createOn(source, this.candidates)
|
is ConeOperatorAmbiguityError -> FirErrors.ASSIGN_OPERATOR_AMBIGUITY.createOn(source, this.candidateSymbols)
|
||||||
is ConeVariableExpectedError -> FirErrors.VARIABLE_EXPECTED.createOn(source)
|
is ConeVariableExpectedError -> FirErrors.VARIABLE_EXPECTED.createOn(source)
|
||||||
is ConeValReassignmentError -> when (val symbol = this.variable) {
|
is ConeValReassignmentError -> when (val symbol = this.variable) {
|
||||||
is FirBackingFieldSymbol -> FirErrors.VAL_REASSIGNMENT_VIA_BACKING_FIELD.errorFactory.createOn(source, symbol)
|
is FirBackingFieldSymbol -> FirErrors.VAL_REASSIGNMENT_VIA_BACKING_FIELD.errorFactory.createOn(source, symbol)
|
||||||
@@ -74,11 +74,11 @@ private fun ConeDiagnostic.toFirDiagnostic(
|
|||||||
is ConeUnexpectedTypeArgumentsError -> FirErrors.TYPE_ARGUMENTS_NOT_ALLOWED.createOn(this.source ?: source)
|
is ConeUnexpectedTypeArgumentsError -> FirErrors.TYPE_ARGUMENTS_NOT_ALLOWED.createOn(this.source ?: source)
|
||||||
is ConeIllegalAnnotationError -> FirErrors.NOT_AN_ANNOTATION_CLASS.createOn(source, this.name.asString())
|
is ConeIllegalAnnotationError -> FirErrors.NOT_AN_ANNOTATION_CLASS.createOn(source, this.name.asString())
|
||||||
is ConeWrongNumberOfTypeArgumentsError ->
|
is ConeWrongNumberOfTypeArgumentsError ->
|
||||||
FirErrors.WRONG_NUMBER_OF_TYPE_ARGUMENTS.createOn(this.source, this.desiredCount, this.symbol)
|
FirErrors.WRONG_NUMBER_OF_TYPE_ARGUMENTS.createOn(this.source, this.desiredCount, this.candidateSymbol)
|
||||||
is ConeOuterClassArgumentsRequired ->
|
is ConeOuterClassArgumentsRequired ->
|
||||||
FirErrors.OUTER_CLASS_ARGUMENTS_REQUIRED.createOn(qualifiedAccessSource ?: source, this.symbol)
|
FirErrors.OUTER_CLASS_ARGUMENTS_REQUIRED.createOn(qualifiedAccessSource ?: source, this.symbol)
|
||||||
is ConeNoTypeArgumentsOnRhsError ->
|
is ConeNoTypeArgumentsOnRhsError ->
|
||||||
FirErrors.NO_TYPE_ARGUMENTS_ON_RHS.createOn(qualifiedAccessSource ?: source, this.desiredCount, this.symbol)
|
FirErrors.NO_TYPE_ARGUMENTS_ON_RHS.createOn(qualifiedAccessSource ?: source, this.desiredCount, this.candidateSymbol)
|
||||||
is ConeSimpleDiagnostic -> when {
|
is ConeSimpleDiagnostic -> when {
|
||||||
source.kind is FirFakeSourceElementKind && source.kind != FirFakeSourceElementKind.ReferenceInAtomicQualifiedAccess -> null
|
source.kind is FirFakeSourceElementKind && source.kind != FirFakeSourceElementKind.ReferenceInAtomicQualifiedAccess -> null
|
||||||
else -> this.getFactory(source).createOn(qualifiedAccessSource ?: source)
|
else -> this.getFactory(source).createOn(qualifiedAccessSource ?: source)
|
||||||
@@ -186,7 +186,10 @@ private fun mapInapplicableCandidateError(
|
|||||||
is NonVarargSpread -> FirErrors.NON_VARARG_SPREAD.createOn(rootCause.argument.source?.getChild(KtTokens.MUL, depth = 1)!!)
|
is NonVarargSpread -> FirErrors.NON_VARARG_SPREAD.createOn(rootCause.argument.source?.getChild(KtTokens.MUL, depth = 1)!!)
|
||||||
is ArgumentPassedTwice -> FirErrors.ARGUMENT_PASSED_TWICE.createOn(rootCause.argument.source)
|
is ArgumentPassedTwice -> FirErrors.ARGUMENT_PASSED_TWICE.createOn(rootCause.argument.source)
|
||||||
is TooManyArguments -> FirErrors.TOO_MANY_ARGUMENTS.createOn(rootCause.argument.source ?: source, rootCause.function.symbol)
|
is TooManyArguments -> FirErrors.TOO_MANY_ARGUMENTS.createOn(rootCause.argument.source ?: source, rootCause.function.symbol)
|
||||||
is NoValueForParameter -> FirErrors.NO_VALUE_FOR_PARAMETER.createOn(qualifiedAccessSource ?: source, rootCause.valueParameter.symbol)
|
is NoValueForParameter -> FirErrors.NO_VALUE_FOR_PARAMETER.createOn(
|
||||||
|
qualifiedAccessSource ?: source,
|
||||||
|
rootCause.valueParameter.symbol
|
||||||
|
)
|
||||||
is NameNotFound -> FirErrors.NAMED_PARAMETER_NOT_FOUND.createOn(
|
is NameNotFound -> FirErrors.NAMED_PARAMETER_NOT_FOUND.createOn(
|
||||||
rootCause.argument.source ?: source,
|
rootCause.argument.source ?: source,
|
||||||
rootCause.argument.name.asString()
|
rootCause.argument.name.asString()
|
||||||
|
|||||||
@@ -5,10 +5,10 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.fir.diagnostics
|
package org.jetbrains.kotlin.fir.diagnostics
|
||||||
|
|
||||||
abstract class ConeDiagnostic {
|
interface ConeDiagnostic {
|
||||||
abstract val reason: String
|
val reason: String
|
||||||
}
|
}
|
||||||
|
|
||||||
class ConeStubDiagnostic(val original: ConeDiagnostic) : ConeDiagnostic() {
|
class ConeStubDiagnostic(val original: ConeDiagnostic) : ConeDiagnostic {
|
||||||
override val reason: String get() = original.reason
|
override val reason: String get() = original.reason
|
||||||
}
|
}
|
||||||
+66
-51
@@ -22,115 +22,127 @@ import org.jetbrains.kotlin.name.ClassId
|
|||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.resolve.calls.tower.CandidateApplicability
|
import org.jetbrains.kotlin.resolve.calls.tower.CandidateApplicability
|
||||||
|
|
||||||
sealed class ConeUnresolvedError : ConeDiagnostic() {
|
sealed interface ConeUnresolvedError : ConeDiagnostic {
|
||||||
abstract val qualifier: String?
|
val qualifier: String?
|
||||||
}
|
}
|
||||||
|
|
||||||
class ConeUnresolvedReferenceError(val name: Name? = null) : ConeUnresolvedError() {
|
interface ConeDiagnosticWithCandidates : ConeDiagnostic {
|
||||||
|
val candidateSymbols: Collection<FirBasedSymbol<*>>
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ConeDiagnosticWithSingleCandidate : ConeDiagnosticWithCandidates {
|
||||||
|
override val candidateSymbols: Collection<FirBasedSymbol<*>> get() = listOf(candidateSymbol)
|
||||||
|
val candidateSymbol: FirBasedSymbol<*>
|
||||||
|
}
|
||||||
|
|
||||||
|
class ConeUnresolvedReferenceError(val name: Name? = null) : ConeUnresolvedError {
|
||||||
override val qualifier: String? get() = name?.asString()
|
override val qualifier: String? get() = name?.asString()
|
||||||
override val reason: String get() = "Unresolved reference" + if (name != null) ": ${name.asString()}" else ""
|
override val reason: String get() = "Unresolved reference" + if (name != null) ": ${name.asString()}" else ""
|
||||||
}
|
}
|
||||||
|
|
||||||
class ConeUnresolvedSymbolError(val classId: ClassId) : ConeUnresolvedError() {
|
class ConeUnresolvedSymbolError(val classId: ClassId) : ConeUnresolvedError {
|
||||||
override val qualifier: String get() = classId.asSingleFqName().asString()
|
override val qualifier: String get() = classId.asSingleFqName().asString()
|
||||||
override val reason: String get() = "Symbol not found for $classId"
|
override val reason: String get() = "Symbol not found for $classId"
|
||||||
}
|
}
|
||||||
|
|
||||||
class ConeUnresolvedQualifierError(override val qualifier: String) : ConeUnresolvedError() {
|
class ConeUnresolvedQualifierError(override val qualifier: String) : ConeUnresolvedError {
|
||||||
override val reason: String get() = "Symbol not found for $qualifier"
|
override val reason: String get() = "Symbol not found for $qualifier"
|
||||||
}
|
}
|
||||||
|
|
||||||
class ConeUnresolvedNameError(val name: Name) : ConeUnresolvedError() {
|
class ConeUnresolvedNameError(val name: Name) : ConeUnresolvedError {
|
||||||
override val qualifier: String get() = name.asString()
|
override val qualifier: String get() = name.asString()
|
||||||
override val reason: String get() = "Unresolved name: $name"
|
override val reason: String get() = "Unresolved name: $name"
|
||||||
}
|
}
|
||||||
|
|
||||||
class ConeFunctionCallExpectedError(val name: Name, val hasValueParameters: Boolean) : ConeDiagnostic() {
|
class ConeFunctionCallExpectedError(val name: Name, val hasValueParameters: Boolean) : ConeDiagnostic {
|
||||||
override val reason: String get() = "Function call expected: $name(${if (hasValueParameters) "..." else ""})"
|
override val reason: String get() = "Function call expected: $name(${if (hasValueParameters) "..." else ""})"
|
||||||
}
|
}
|
||||||
|
|
||||||
class ConeFunctionExpectedError(val expression: String, val type: ConeKotlinType) : ConeDiagnostic() {
|
class ConeFunctionExpectedError(val expression: String, val type: ConeKotlinType) : ConeDiagnostic {
|
||||||
override val reason: String get() = "Expression '$expression' of type '$type' cannot be invoked as a function"
|
override val reason: String get() = "Expression '$expression' of type '$type' cannot be invoked as a function"
|
||||||
}
|
}
|
||||||
|
|
||||||
class ConeResolutionToClassifierError(val classSymbol: FirRegularClassSymbol) : ConeDiagnostic() {
|
class ConeResolutionToClassifierError(override val candidateSymbol: FirRegularClassSymbol) : ConeDiagnosticWithSingleCandidate {
|
||||||
override val reason: String get() = "Resolution to classifier"
|
override val reason: String get() = "Resolution to classifier"
|
||||||
}
|
}
|
||||||
|
|
||||||
class ConeHiddenCandidateError(
|
class ConeHiddenCandidateError(
|
||||||
val candidateSymbol: FirBasedSymbol<*>
|
override val candidateSymbol: FirBasedSymbol<*>
|
||||||
) : ConeDiagnostic() {
|
) : ConeDiagnosticWithSingleCandidate {
|
||||||
override val reason: String get() = "HIDDEN: ${describeSymbol(candidateSymbol)} is invisible"
|
override val reason: String get() = "HIDDEN: ${describeSymbol(candidateSymbol)} is invisible"
|
||||||
}
|
}
|
||||||
|
|
||||||
class ConeInapplicableWrongReceiver(val candidates: Collection<FirBasedSymbol<*>>) : ConeDiagnostic() {
|
class ConeInapplicableWrongReceiver(override val candidateSymbols: Collection<FirBasedSymbol<*>>) : ConeDiagnosticWithCandidates {
|
||||||
override val reason: String
|
override val reason: String
|
||||||
get() = "None of the following candidates is applicable because of receiver type mismatch: ${
|
get() = "None of the following candidates is applicable because of receiver type mismatch: ${
|
||||||
candidates.map {
|
candidateSymbols.map { describeSymbol(it) }
|
||||||
describeSymbol(
|
|
||||||
it
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}"
|
}"
|
||||||
}
|
}
|
||||||
|
|
||||||
class ConeInapplicableCandidateError(
|
class ConeInapplicableCandidateError(
|
||||||
val applicability: CandidateApplicability,
|
val applicability: CandidateApplicability,
|
||||||
val candidate: Candidate,
|
val candidate: Candidate,
|
||||||
) : ConeDiagnostic() {
|
) : ConeDiagnosticWithSingleCandidate {
|
||||||
override val reason: String get() = "Inapplicable($applicability): ${describeSymbol(candidate.symbol)}"
|
override val reason: String get() = "Inapplicable($applicability): ${describeSymbol(candidateSymbol)}"
|
||||||
|
override val candidateSymbol: FirBasedSymbol<*> get() = candidate.symbol
|
||||||
}
|
}
|
||||||
|
|
||||||
class ConeNoCompanionObject(
|
class ConeNoCompanionObject(
|
||||||
val symbol: FirRegularClassSymbol
|
override val candidateSymbol: FirRegularClassSymbol
|
||||||
) : ConeDiagnostic() {
|
) : ConeDiagnosticWithSingleCandidate {
|
||||||
override val reason: String get() = "Classifier ''$symbol'' does not have a companion object, and thus must be initialized here"
|
override val reason: String
|
||||||
|
get() = "Classifier ''$candidateSymbol'' does not have a companion object, and thus must be initialized here"
|
||||||
}
|
}
|
||||||
|
|
||||||
class ConeConstraintSystemHasContradiction(
|
class ConeConstraintSystemHasContradiction(
|
||||||
val candidate: Candidate,
|
val candidate: Candidate,
|
||||||
) : ConeDiagnostic() {
|
) : ConeDiagnosticWithSingleCandidate {
|
||||||
override val reason: String get() = "CS errors: ${describeSymbol(candidate.symbol)}"
|
override val reason: String get() = "CS errors: ${describeSymbol(candidateSymbol)}"
|
||||||
|
override val candidateSymbol: FirBasedSymbol<*> get() = candidate.symbol
|
||||||
}
|
}
|
||||||
|
|
||||||
class ConeArgumentTypeMismatchCandidateError(
|
class ConeArgumentTypeMismatchCandidateError(
|
||||||
val expectedType: ConeKotlinType, val actualType: ConeKotlinType
|
val expectedType: ConeKotlinType, val actualType: ConeKotlinType
|
||||||
) : ConeDiagnostic() {
|
) : ConeDiagnostic {
|
||||||
override val reason: String
|
override val reason: String
|
||||||
get() = "Type mismatch. Expected: $expectedType, Actual: $actualType"
|
get() = "Type mismatch. Expected: $expectedType, Actual: $actualType"
|
||||||
}
|
}
|
||||||
|
|
||||||
class ConeAmbiguityError(val name: Name, val applicability: CandidateApplicability, val candidates: Collection<Candidate>) :
|
class ConeAmbiguityError(
|
||||||
ConeDiagnostic() {
|
val name: Name,
|
||||||
override val reason: String get() = "Ambiguity: $name, ${candidates.map { describeSymbol(it.symbol) }}"
|
val applicability: CandidateApplicability,
|
||||||
|
val candidates: Collection<Candidate>
|
||||||
|
) : ConeDiagnosticWithCandidates {
|
||||||
|
override val reason: String get() = "Ambiguity: $name, ${candidateSymbols.map { describeSymbol(it) }}"
|
||||||
|
override val candidateSymbols: Collection<FirBasedSymbol<*>> get() = candidates.map { it.symbol }
|
||||||
}
|
}
|
||||||
|
|
||||||
class ConeOperatorAmbiguityError(val candidates: Collection<FirBasedSymbol<*>>) : ConeDiagnostic() {
|
class ConeOperatorAmbiguityError(override val candidateSymbols: Collection<FirBasedSymbol<*>>) : ConeDiagnosticWithCandidates {
|
||||||
override val reason: String get() = "Operator overload ambiguity. Compatible candidates: ${candidates.map { describeSymbol(it) }}"
|
override val reason: String get() = "Operator overload ambiguity. Compatible candidates: ${candidateSymbols.map { describeSymbol(it) }}"
|
||||||
}
|
}
|
||||||
|
|
||||||
class ConeVariableExpectedError : ConeDiagnostic() {
|
class ConeVariableExpectedError : ConeDiagnostic {
|
||||||
override val reason: String get() = "Variable expected"
|
override val reason: String get() = "Variable expected"
|
||||||
}
|
}
|
||||||
|
|
||||||
class ConeValReassignmentError(val variable: FirVariableSymbol<*>) : ConeDiagnostic() {
|
class ConeValReassignmentError(val variable: FirVariableSymbol<*>) : ConeDiagnostic {
|
||||||
override val reason: String get() = "Re-assigning a val variable"
|
override val reason: String get() = "Re-assigning a val variable"
|
||||||
}
|
}
|
||||||
|
|
||||||
class ConeContractDescriptionError(override val reason: String) : ConeDiagnostic()
|
class ConeContractDescriptionError(override val reason: String) : ConeDiagnostic
|
||||||
|
|
||||||
class ConeIllegalAnnotationError(val name: Name) : ConeDiagnostic() {
|
class ConeIllegalAnnotationError(val name: Name) : ConeDiagnostic {
|
||||||
override val reason: String get() = "Not a legal annotation: $name"
|
override val reason: String get() = "Not a legal annotation: $name"
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ConeUnmatchedTypeArgumentsError {
|
interface ConeUnmatchedTypeArgumentsError : ConeDiagnosticWithSingleCandidate {
|
||||||
val desiredCount: Int
|
val desiredCount: Int
|
||||||
val symbol: FirClassLikeSymbol<*>
|
override val candidateSymbol: FirClassLikeSymbol<*>
|
||||||
}
|
}
|
||||||
|
|
||||||
class ConeWrongNumberOfTypeArgumentsError(
|
class ConeWrongNumberOfTypeArgumentsError(
|
||||||
override val desiredCount: Int,
|
override val desiredCount: Int,
|
||||||
override val symbol: FirRegularClassSymbol,
|
override val candidateSymbol: FirRegularClassSymbol,
|
||||||
source: FirSourceElement
|
source: FirSourceElement
|
||||||
) : ConeDiagnosticWithSource(source), ConeUnmatchedTypeArgumentsError {
|
) : ConeDiagnosticWithSource(source), ConeUnmatchedTypeArgumentsError {
|
||||||
override val reason: String get() = "Wrong number of type arguments"
|
override val reason: String get() = "Wrong number of type arguments"
|
||||||
@@ -138,52 +150,55 @@ class ConeWrongNumberOfTypeArgumentsError(
|
|||||||
|
|
||||||
class ConeNoTypeArgumentsOnRhsError(
|
class ConeNoTypeArgumentsOnRhsError(
|
||||||
override val desiredCount: Int,
|
override val desiredCount: Int,
|
||||||
override val symbol: FirClassLikeSymbol<*>
|
override val candidateSymbol: FirClassLikeSymbol<*>
|
||||||
) : ConeDiagnostic(), ConeUnmatchedTypeArgumentsError {
|
) : ConeUnmatchedTypeArgumentsError {
|
||||||
override val reason: String get() = "No type arguments on RHS"
|
override val reason: String get() = "No type arguments on RHS"
|
||||||
}
|
}
|
||||||
|
|
||||||
class ConeOuterClassArgumentsRequired(
|
class ConeOuterClassArgumentsRequired(
|
||||||
val symbol: FirRegularClassSymbol,
|
val symbol: FirRegularClassSymbol,
|
||||||
) : ConeDiagnostic() {
|
) : ConeDiagnostic {
|
||||||
override val reason: String = "Type arguments should be specified for an outer class"
|
override val reason: String = "Type arguments should be specified for an outer class"
|
||||||
}
|
}
|
||||||
|
|
||||||
class ConeInstanceAccessBeforeSuperCall(val target: String) : ConeDiagnostic() {
|
class ConeInstanceAccessBeforeSuperCall(val target: String) : ConeDiagnostic {
|
||||||
override val reason: String get() = "Cannot access ''${target}'' before superclass constructor has been called"
|
override val reason: String get() = "Cannot access ''${target}'' before superclass constructor has been called"
|
||||||
}
|
}
|
||||||
|
|
||||||
class ConeUnsupportedCallableReferenceTarget(val fir: FirCallableDeclaration) : ConeDiagnostic() {
|
class ConeUnsupportedCallableReferenceTarget(val fir: FirCallableDeclaration) : ConeDiagnosticWithSingleCandidate {
|
||||||
override val reason: String get() = "Unsupported declaration for callable reference: ${fir.render()}"
|
override val reason: String get() = "Unsupported declaration for callable reference: ${fir.render()}"
|
||||||
|
override val candidateSymbol: FirBasedSymbol<*> get() = fir.symbol
|
||||||
}
|
}
|
||||||
|
|
||||||
class ConeTypeParameterSupertype(val symbol: FirTypeParameterSymbol) : ConeDiagnostic() {
|
class ConeTypeParameterSupertype(val symbol: FirTypeParameterSymbol) : ConeDiagnostic {
|
||||||
override val reason: String get() = "Type parameter ${symbol.fir.name} cannot be a supertype"
|
override val reason: String get() = "Type parameter ${symbol.fir.name} cannot be a supertype"
|
||||||
}
|
}
|
||||||
|
|
||||||
class ConeTypeParameterInQualifiedAccess(val symbol: FirTypeParameterSymbol) : ConeDiagnostic() {
|
class ConeTypeParameterInQualifiedAccess(val symbol: FirTypeParameterSymbol) : ConeDiagnostic {
|
||||||
override val reason: String get() = "Type parameter ${symbol.fir.name} in qualified access"
|
override val reason: String get() = "Type parameter ${symbol.fir.name} in qualified access"
|
||||||
}
|
}
|
||||||
|
|
||||||
class ConeCyclicTypeBound(val symbol: FirTypeParameterSymbol, val bounds: ImmutableList<FirTypeRef>) : ConeDiagnostic() {
|
class ConeCyclicTypeBound(val symbol: FirTypeParameterSymbol, val bounds: ImmutableList<FirTypeRef>) : ConeDiagnostic {
|
||||||
override val reason: String get() = "Type parameter ${symbol.fir.name} has cyclic bounds"
|
override val reason: String get() = "Type parameter ${symbol.fir.name} has cyclic bounds"
|
||||||
}
|
}
|
||||||
|
|
||||||
class ConeImportFromSingleton(val name: Name) : ConeDiagnostic() {
|
class ConeImportFromSingleton(val name: Name) : ConeDiagnostic {
|
||||||
override val reason: String get() = "Import from singleton $name is not allowed"
|
override val reason: String get() = "Import from singleton $name is not allowed"
|
||||||
}
|
}
|
||||||
|
|
||||||
open class ConeUnsupported(val message: String, val source: FirSourceElement? = null) : ConeDiagnostic() {
|
open class ConeUnsupported(override val reason: String, val source: FirSourceElement? = null) : ConeDiagnostic
|
||||||
override val reason: String get() = message
|
|
||||||
}
|
|
||||||
|
|
||||||
class ConeUnsupportedDynamicType : ConeUnsupported("Dynamic types are not supported in this context")
|
class ConeUnsupportedDynamicType : ConeUnsupported("Dynamic types are not supported in this context")
|
||||||
|
|
||||||
class ConeDeprecated(val source: FirSourceElement?, val symbol: FirBasedSymbol<*>, val deprecation: Deprecation) : ConeDiagnostic() {
|
class ConeDeprecated(
|
||||||
|
val source: FirSourceElement?,
|
||||||
|
override val candidateSymbol: FirBasedSymbol<*>,
|
||||||
|
val deprecation: Deprecation
|
||||||
|
) : ConeDiagnosticWithSingleCandidate {
|
||||||
override val reason: String get() = "Deprecated: ${deprecation.message}"
|
override val reason: String get() = "Deprecated: ${deprecation.message}"
|
||||||
}
|
}
|
||||||
|
|
||||||
class ConeLocalVariableNoTypeOrInitializer(val variable: FirVariable) : ConeDiagnostic() {
|
class ConeLocalVariableNoTypeOrInitializer(val variable: FirVariable) : ConeDiagnostic {
|
||||||
override val reason: String get() = "Cannot infer variable type without initializer / getter / delegate"
|
override val reason: String get() = "Cannot infer variable type without initializer / getter / delegate"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,6 @@ package org.jetbrains.kotlin.fir.diagnostics
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.fir.FirSourceElement
|
import org.jetbrains.kotlin.fir.FirSourceElement
|
||||||
|
|
||||||
class ConeUnexpectedTypeArgumentsError(override val reason: String, val source: FirSourceElement? = null) : ConeDiagnostic()
|
class ConeUnexpectedTypeArgumentsError(override val reason: String, val source: FirSourceElement? = null) : ConeDiagnostic
|
||||||
|
|
||||||
class ConeIntermediateDiagnostic(override val reason: String) : ConeDiagnostic()
|
class ConeIntermediateDiagnostic(override val reason: String) : ConeDiagnostic
|
||||||
|
|||||||
@@ -7,13 +7,13 @@ package org.jetbrains.kotlin.fir.diagnostics
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.fir.FirSourceElement
|
import org.jetbrains.kotlin.fir.FirSourceElement
|
||||||
|
|
||||||
class ConeSimpleDiagnostic(override val reason: String, val kind: DiagnosticKind = DiagnosticKind.Other) : ConeDiagnostic()
|
class ConeSimpleDiagnostic(override val reason: String, val kind: DiagnosticKind = DiagnosticKind.Other) : ConeDiagnostic
|
||||||
|
|
||||||
class ConeNotAnnotationContainer(val text: String) : ConeDiagnostic() {
|
class ConeNotAnnotationContainer(val text: String) : ConeDiagnostic {
|
||||||
override val reason: String get() = "Strange annotated expression: $text"
|
override val reason: String get() = "Strange annotated expression: $text"
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class ConeDiagnosticWithSource(val source: FirSourceElement) : ConeDiagnostic()
|
abstract class ConeDiagnosticWithSource(val source: FirSourceElement) : ConeDiagnostic
|
||||||
|
|
||||||
class ConeUnderscoreIsReserved(source: FirSourceElement) : ConeDiagnosticWithSource(source) {
|
class ConeUnderscoreIsReserved(source: FirSourceElement) : ConeDiagnosticWithSource(source) {
|
||||||
override val reason: String get() = "Names _, __, ___, ..., are reserved in Kotlin"
|
override val reason: String get() = "Names _, __, ___, ..., are reserved in Kotlin"
|
||||||
|
|||||||
@@ -47,16 +47,6 @@ internal fun FirNamedReference.getCandidateSymbols(): Collection<FirBasedSymbol<
|
|||||||
|
|
||||||
internal fun ConeDiagnostic.getCandidateSymbols(): Collection<FirBasedSymbol<*>> =
|
internal fun ConeDiagnostic.getCandidateSymbols(): Collection<FirBasedSymbol<*>> =
|
||||||
when (this) {
|
when (this) {
|
||||||
is ConeInapplicableCandidateError -> listOf(candidate.symbol)
|
is ConeDiagnosticWithCandidates -> candidateSymbols
|
||||||
is ConeHiddenCandidateError -> listOf(candidateSymbol)
|
|
||||||
is ConeAmbiguityError -> candidates.map { it.symbol }
|
|
||||||
is ConeOperatorAmbiguityError -> candidates
|
|
||||||
is ConeUnsupportedCallableReferenceTarget -> listOf(fir.symbol)
|
|
||||||
is ConeUnmatchedTypeArgumentsError -> listOf(symbol)
|
|
||||||
is ConeConstraintSystemHasContradiction -> listOf(candidate.symbol)
|
|
||||||
is ConeDeprecated -> listOf(symbol)
|
|
||||||
is ConeNoTypeArgumentsOnRhsError -> listOf(symbol)
|
|
||||||
is ConeResolutionToClassifierError -> listOf(classSymbol)
|
|
||||||
is ConeWrongNumberOfTypeArgumentsError -> listOf(symbol)
|
|
||||||
else -> emptyList()
|
else -> emptyList()
|
||||||
}
|
}
|
||||||
+1
-1
@@ -56,7 +56,7 @@ internal object FirReferenceResolveHelper {
|
|||||||
|
|
||||||
val symbol = resolvedSymbol ?: run {
|
val symbol = resolvedSymbol ?: run {
|
||||||
val diagnostic = (this as? FirErrorTypeRef)?.diagnostic
|
val diagnostic = (this as? FirErrorTypeRef)?.diagnostic
|
||||||
(diagnostic as? ConeUnmatchedTypeArgumentsError)?.symbol
|
(diagnostic as? ConeUnmatchedTypeArgumentsError)?.candidateSymbol
|
||||||
}
|
}
|
||||||
|
|
||||||
return symbol?.fir?.buildSymbol(symbolBuilder)
|
return symbol?.fir?.buildSymbol(symbolBuilder)
|
||||||
|
|||||||
Reference in New Issue
Block a user