[FIR] Introduce FirDiagnostic in FIR instead of errorReason
This commit is contained in:
+10
-9
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.fir.builder.generateComponentFunctions
|
||||
import org.jetbrains.kotlin.fir.builder.generateCopyFunction
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.impl.*
|
||||
import org.jetbrains.kotlin.fir.diagnostics.FirSimpleDiagnostic
|
||||
import org.jetbrains.kotlin.fir.expressions.*
|
||||
import org.jetbrains.kotlin.fir.expressions.impl.*
|
||||
import org.jetbrains.kotlin.fir.lightTree.LightTree2Fir
|
||||
@@ -664,7 +665,7 @@ class DeclarationsConverter(
|
||||
}
|
||||
|
||||
val delegatedSelfTypeRef =
|
||||
if (classWrapper.isObjectLiteral()) FirErrorTypeRefImpl(null, "Constructor in object")
|
||||
if (classWrapper.isObjectLiteral()) FirErrorTypeRefImpl(null, FirSimpleDiagnostic("Constructor in object"))
|
||||
else classWrapper.delegatedSelfTypeRef
|
||||
|
||||
val status = FirDeclarationStatusImpl(modifiers.getVisibility(), Modality.FINAL).apply {
|
||||
@@ -714,8 +715,8 @@ class DeclarationsConverter(
|
||||
val isThis = (isImplicit && classWrapper.hasPrimaryConstructor) || thisKeywordPresent
|
||||
val delegatedType =
|
||||
if (classWrapper.isObjectLiteral() || classWrapper.isInterface()) when {
|
||||
isThis -> FirErrorTypeRefImpl(null, "Constructor in object")
|
||||
else -> FirErrorTypeRefImpl(null, "No super type")
|
||||
isThis -> FirErrorTypeRefImpl(null, FirSimpleDiagnostic("Constructor in object"))
|
||||
else -> FirErrorTypeRefImpl(null, FirSimpleDiagnostic("No super type"))
|
||||
}
|
||||
else when {
|
||||
isThis -> classWrapper.delegatedSelfTypeRef
|
||||
@@ -869,7 +870,7 @@ class DeclarationsConverter(
|
||||
private fun convertDestructingDeclaration(destructingDeclaration: LighterASTNode): DestructuringDeclaration {
|
||||
var isVar = false
|
||||
val entries = mutableListOf<FirVariable<*>>()
|
||||
var firExpression: FirExpression = FirErrorExpressionImpl(null, "Destructuring declaration without initializer")
|
||||
var firExpression: FirExpression = FirErrorExpressionImpl(null, FirSimpleDiagnostic("Destructuring declaration without initializer"))
|
||||
destructingDeclaration.forEachChildren {
|
||||
when (it.tokenType) {
|
||||
VAR_KEYWORD -> isVar = true
|
||||
@@ -1165,7 +1166,7 @@ class DeclarationsConverter(
|
||||
*/
|
||||
private fun convertExplicitDelegation(explicitDelegation: LighterASTNode): FirDelegatedTypeRef {
|
||||
lateinit var firTypeRef: FirTypeRef
|
||||
var firExpression: FirExpression? = FirErrorExpressionImpl(null, "Should have delegate")
|
||||
var firExpression: FirExpression? = FirErrorExpressionImpl(null, FirSimpleDiagnostic("Should have delegate"))
|
||||
explicitDelegation.forEachChildren {
|
||||
when (it.tokenType) {
|
||||
TYPE_REFERENCE -> firTypeRef = convertType(it)
|
||||
@@ -1255,10 +1256,10 @@ class DeclarationsConverter(
|
||||
*/
|
||||
fun convertType(type: LighterASTNode): FirTypeRef {
|
||||
if (type.asText.isEmpty()) {
|
||||
return FirErrorTypeRefImpl(null, "Unwrapped type is null")
|
||||
return FirErrorTypeRefImpl(null, FirSimpleDiagnostic("Unwrapped type is null"))
|
||||
}
|
||||
var typeModifiers = TypeModifier() //TODO what with suspend?
|
||||
var firType: FirTypeRef = FirErrorTypeRefImpl(null, "Incomplete code")
|
||||
var firType: FirTypeRef = FirErrorTypeRefImpl(null, FirSimpleDiagnostic("Incomplete code"))
|
||||
var afterLPar = false
|
||||
type.forEachChildren {
|
||||
when (it.tokenType) {
|
||||
@@ -1269,7 +1270,7 @@ class DeclarationsConverter(
|
||||
NULLABLE_TYPE -> firType = convertNullableType(it)
|
||||
FUNCTION_TYPE -> firType = convertFunctionType(it)
|
||||
DYNAMIC_TYPE -> firType = FirDynamicTypeRefImpl(null, false)
|
||||
TokenType.ERROR_ELEMENT -> firType = FirErrorTypeRefImpl(null, "Unwrapped type is null")
|
||||
TokenType.ERROR_ELEMENT -> firType = FirErrorTypeRefImpl(null, FirSimpleDiagnostic("Unwrapped type is null"))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1324,7 +1325,7 @@ class DeclarationsConverter(
|
||||
}
|
||||
|
||||
if (identifier == null)
|
||||
return FirErrorTypeRefImpl(null, "Incomplete user type")
|
||||
return FirErrorTypeRefImpl(null, FirSimpleDiagnostic("Incomplete user type"))
|
||||
|
||||
val qualifier = FirQualifierPartImpl(
|
||||
identifier.nameAsSafeName()
|
||||
|
||||
+21
-20
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.fir.declarations.impl.FirAnonymousFunctionImpl
|
||||
import org.jetbrains.kotlin.fir.declarations.impl.FirDeclarationStatusImpl
|
||||
import org.jetbrains.kotlin.fir.declarations.impl.FirPropertyImpl
|
||||
import org.jetbrains.kotlin.fir.declarations.impl.FirValueParameterImpl
|
||||
import org.jetbrains.kotlin.fir.diagnostics.FirSimpleDiagnostic
|
||||
import org.jetbrains.kotlin.fir.expressions.*
|
||||
import org.jetbrains.kotlin.fir.expressions.impl.*
|
||||
import org.jetbrains.kotlin.fir.impl.FirAbstractAnnotatedElement
|
||||
@@ -56,7 +57,7 @@ class ExpressionsConverter(
|
||||
) : BaseConverter(session, tree, context) {
|
||||
|
||||
inline fun <reified R : FirElement> getAsFirExpression(expression: LighterASTNode?, errorReason: String = ""): R {
|
||||
return expression?.let { convertExpression(it, errorReason) } as? R ?: (FirErrorExpressionImpl(null, errorReason) as R)
|
||||
return expression?.let { convertExpression(it, errorReason) } as? R ?: (FirErrorExpressionImpl(null, FirSimpleDiagnostic(errorReason)) as R)
|
||||
}
|
||||
|
||||
/***** EXPRESSIONS *****/
|
||||
@@ -104,7 +105,7 @@ class ExpressionsConverter(
|
||||
|
||||
OBJECT_LITERAL -> declarationsConverter.convertObjectLiteral(expression)
|
||||
FUN -> declarationsConverter.convertFunctionDeclaration(expression)
|
||||
else -> FirErrorExpressionImpl(null, errorReason)
|
||||
else -> FirErrorExpressionImpl(null, FirSimpleDiagnostic(errorReason))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,7 +159,7 @@ class ExpressionsConverter(
|
||||
FirLabelImpl(null, it.asString())
|
||||
}
|
||||
val bodyExpression = block?.let { declarationsConverter.convertBlockExpression(it) }
|
||||
?: FirErrorExpressionImpl(null, "Lambda has no body")
|
||||
?: FirErrorExpressionImpl(null, FirSimpleDiagnostic("Lambda has no body"))
|
||||
body = if (bodyExpression is FirBlockImpl) {
|
||||
if (bodyExpression.statements.isEmpty()) {
|
||||
bodyExpression.statements.add(FirUnitExpression(null))
|
||||
@@ -185,7 +186,7 @@ class ExpressionsConverter(
|
||||
var isLeftArgument = true
|
||||
lateinit var operationTokenName: String
|
||||
var leftArgNode: LighterASTNode? = null
|
||||
var rightArgAsFir: FirExpression = FirErrorExpressionImpl(null, "No right operand")
|
||||
var rightArgAsFir: FirExpression = FirErrorExpressionImpl(null, FirSimpleDiagnostic("No right operand"))
|
||||
binaryExpression.forEachChildren {
|
||||
when (it.tokenType) {
|
||||
OPERATION_REFERENCE -> {
|
||||
@@ -249,7 +250,7 @@ class ExpressionsConverter(
|
||||
toFirOperation: String.() -> FirOperation
|
||||
): FirTypeOperatorCall {
|
||||
lateinit var operationTokenName: String
|
||||
var leftArgAsFir: FirExpression = FirErrorExpressionImpl(null, "No left operand")
|
||||
var leftArgAsFir: FirExpression = FirErrorExpressionImpl(null, FirSimpleDiagnostic("No left operand"))
|
||||
lateinit var firType: FirTypeRef
|
||||
binaryExpression.forEachChildren {
|
||||
when (it.tokenType) {
|
||||
@@ -285,7 +286,7 @@ class ExpressionsConverter(
|
||||
context.firLabels.removeLast()
|
||||
//println("Unused label: ${labeledExpression.getAsString()}")
|
||||
}
|
||||
return firExpression ?: FirErrorExpressionImpl(null, "Empty label")
|
||||
return firExpression ?: FirErrorExpressionImpl(null, FirSimpleDiagnostic("Empty label"))
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -347,7 +348,7 @@ class ExpressionsConverter(
|
||||
|
||||
return (firExpression as? FirAbstractAnnotatedElement)?.apply {
|
||||
annotations += firAnnotationList
|
||||
} ?: FirErrorExpressionImpl(null, "Strange annotated expression: ${firExpression?.render()}")
|
||||
} ?: FirErrorExpressionImpl(null, FirSimpleDiagnostic("Strange annotated expression: ${firExpression?.render()}"))
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -355,7 +356,7 @@ class ExpressionsConverter(
|
||||
* @see org.jetbrains.kotlin.fir.builder.RawFirBuilder.Visitor.visitClassLiteralExpression
|
||||
*/
|
||||
private fun convertClassLiteralExpression(classLiteralExpression: LighterASTNode): FirExpression {
|
||||
var firReceiverExpression: FirExpression = FirErrorExpressionImpl(null, "No receiver in class literal")
|
||||
var firReceiverExpression: FirExpression = FirErrorExpressionImpl(null, FirSimpleDiagnostic("No receiver in class literal"))
|
||||
classLiteralExpression.forEachChildren {
|
||||
if (it.isExpression()) firReceiverExpression = getAsFirExpression(it, "No receiver in class literal")
|
||||
}
|
||||
@@ -399,7 +400,7 @@ class ExpressionsConverter(
|
||||
private fun convertQualifiedExpression(dotQualifiedExpression: LighterASTNode): FirExpression {
|
||||
var isSelector = false
|
||||
var isSafe = false
|
||||
var firSelector: FirExpression = FirErrorExpressionImpl(null, "Qualified expression without selector") //after dot
|
||||
var firSelector: FirExpression = FirErrorExpressionImpl(null, FirSimpleDiagnostic("Qualified expression without selector")) //after dot
|
||||
var firReceiver: FirExpression? = null //before dot
|
||||
dotQualifiedExpression.forEachChildren {
|
||||
when (it.tokenType) {
|
||||
@@ -449,7 +450,7 @@ class ExpressionsConverter(
|
||||
arguments += additionalArgument!!
|
||||
FirSimpleNamedReference(null, OperatorNameConventions.INVOKE, null)
|
||||
}
|
||||
else -> FirErrorNamedReferenceImpl(null, "Call has no callee")
|
||||
else -> FirErrorNamedReferenceImpl(null, FirSimpleDiagnostic("Call has no callee"))
|
||||
}
|
||||
|
||||
context.firFunctionCalls += this
|
||||
@@ -467,7 +468,7 @@ class ExpressionsConverter(
|
||||
}
|
||||
|
||||
private fun LighterASTNode?.convertShortOrLongStringTemplate(errorReason: String): FirExpression {
|
||||
var firExpression: FirExpression = FirErrorExpressionImpl(null, errorReason)
|
||||
var firExpression: FirExpression = FirErrorExpressionImpl(null, FirSimpleDiagnostic(errorReason))
|
||||
this?.forEachChildren(LONG_TEMPLATE_ENTRY_START, LONG_TEMPLATE_ENTRY_END) {
|
||||
firExpression = getAsFirExpression(it, errorReason)
|
||||
}
|
||||
@@ -563,7 +564,7 @@ class ExpressionsConverter(
|
||||
}
|
||||
|
||||
private fun convertWhenConditionExpression(whenCondition: LighterASTNode): FirExpression {
|
||||
var firExpression: FirExpression = FirErrorExpressionImpl(null, "No expression in condition with expression")
|
||||
var firExpression: FirExpression = FirErrorExpressionImpl(null, FirSimpleDiagnostic("No expression in condition with expression"))
|
||||
whenCondition.forEachChildren {
|
||||
when (it.tokenType) {
|
||||
else -> if (it.isExpression()) firExpression = getAsFirExpression(it, "No expression in condition with expression")
|
||||
@@ -577,7 +578,7 @@ class ExpressionsConverter(
|
||||
|
||||
private fun convertWhenConditionInRange(whenCondition: LighterASTNode): FirExpression {
|
||||
var isNegate = false
|
||||
var firExpression: FirExpression = FirErrorExpressionImpl(null, "No range in condition with range")
|
||||
var firExpression: FirExpression = FirErrorExpressionImpl(null, FirSimpleDiagnostic("No range in condition with range"))
|
||||
whenCondition.forEachChildren {
|
||||
when (it.tokenType) {
|
||||
NOT_IN -> isNegate = true
|
||||
@@ -611,7 +612,7 @@ class ExpressionsConverter(
|
||||
* @see org.jetbrains.kotlin.fir.builder.RawFirBuilder.Visitor.visitArrayAccessExpression
|
||||
*/
|
||||
private fun convertArrayAccessExpression(arrayAccess: LighterASTNode): FirFunctionCall {
|
||||
var firExpression: FirExpression = FirErrorExpressionImpl(null, "No array expression")
|
||||
var firExpression: FirExpression = FirErrorExpressionImpl(null, FirSimpleDiagnostic("No array expression"))
|
||||
val indices: MutableList<FirExpression> = mutableListOf()
|
||||
arrayAccess.forEachChildren {
|
||||
when (it.tokenType) {
|
||||
@@ -669,7 +670,7 @@ class ExpressionsConverter(
|
||||
*/
|
||||
private fun convertDoWhile(doWhileLoop: LighterASTNode): FirElement {
|
||||
var block: LighterASTNode? = null
|
||||
var firCondition: FirExpression = FirErrorExpressionImpl(null, "No condition in do-while loop")
|
||||
var firCondition: FirExpression = FirErrorExpressionImpl(null, FirSimpleDiagnostic("No condition in do-while loop"))
|
||||
doWhileLoop.forEachChildren {
|
||||
when (it.tokenType) {
|
||||
BODY -> block = it
|
||||
@@ -686,7 +687,7 @@ class ExpressionsConverter(
|
||||
*/
|
||||
private fun convertWhile(whileLoop: LighterASTNode): FirElement {
|
||||
var block: LighterASTNode? = null
|
||||
var firCondition: FirExpression = FirErrorExpressionImpl(null, "No condition in while loop")
|
||||
var firCondition: FirExpression = FirErrorExpressionImpl(null, FirSimpleDiagnostic("No condition in while loop"))
|
||||
whileLoop.forEachChildren {
|
||||
when (it.tokenType) {
|
||||
BODY -> block = it
|
||||
@@ -703,7 +704,7 @@ class ExpressionsConverter(
|
||||
*/
|
||||
private fun convertFor(forLoop: LighterASTNode): FirElement {
|
||||
var parameter: ValueParameter? = null
|
||||
var rangeExpression: FirExpression = FirErrorExpressionImpl(null, "No range in for loop")
|
||||
var rangeExpression: FirExpression = FirErrorExpressionImpl(null, FirSimpleDiagnostic("No range in for loop"))
|
||||
var blockNode: LighterASTNode? = null
|
||||
forLoop.forEachChildren {
|
||||
when (it.tokenType) {
|
||||
@@ -846,7 +847,7 @@ class ExpressionsConverter(
|
||||
* @see org.jetbrains.kotlin.fir.builder.RawFirBuilder.Visitor.visitIfExpression
|
||||
*/
|
||||
private fun convertIfExpression(ifExpression: LighterASTNode): FirExpression {
|
||||
var firCondition: FirExpression = FirErrorExpressionImpl(null, "If statement should have condition")
|
||||
var firCondition: FirExpression = FirErrorExpressionImpl(null, FirSimpleDiagnostic("If statement should have condition"))
|
||||
var thenBlock: LighterASTNode? = null
|
||||
var elseBlock: LighterASTNode? = null
|
||||
ifExpression.forEachChildren {
|
||||
@@ -908,7 +909,7 @@ class ExpressionsConverter(
|
||||
* @see org.jetbrains.kotlin.fir.builder.RawFirBuilder.Visitor.visitThrowExpression
|
||||
*/
|
||||
private fun convertThrow(throwExpression: LighterASTNode): FirExpression {
|
||||
var firExpression: FirExpression = FirErrorExpressionImpl(null, "Nothing to throw")
|
||||
var firExpression: FirExpression = FirErrorExpressionImpl(null, FirSimpleDiagnostic("Nothing to throw"))
|
||||
throwExpression.forEachChildren {
|
||||
if (it.isExpression()) firExpression = getAsFirExpression(it, "Nothing to throw")
|
||||
}
|
||||
@@ -963,7 +964,7 @@ class ExpressionsConverter(
|
||||
private fun convertValueArgument(valueArgument: LighterASTNode): FirExpression {
|
||||
var identifier: String? = null
|
||||
var isSpread = false
|
||||
var firExpression: FirExpression = FirErrorExpressionImpl(null, "Argument is absent")
|
||||
var firExpression: FirExpression = FirErrorExpressionImpl(null, FirSimpleDiagnostic("Argument is absent"))
|
||||
valueArgument.forEachChildren {
|
||||
when (it.tokenType) {
|
||||
VALUE_ARGUMENT_NAME -> identifier = it.asText
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.fir.declarations.impl.FirDeclarationStatusImpl
|
||||
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyGetter
|
||||
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertySetter
|
||||
import org.jetbrains.kotlin.fir.declarations.impl.FirPropertyImpl
|
||||
import org.jetbrains.kotlin.fir.diagnostics.FirSimpleDiagnostic
|
||||
import org.jetbrains.kotlin.fir.expressions.impl.FirQualifiedAccessExpressionImpl
|
||||
import org.jetbrains.kotlin.fir.lightTree.fir.modifier.Modifier
|
||||
import org.jetbrains.kotlin.fir.references.impl.FirPropertyFromParameterResolvedNamedReference
|
||||
@@ -35,7 +36,7 @@ class ValueParameter(
|
||||
val name = this.firValueParameter.name
|
||||
var type = this.firValueParameter.returnTypeRef
|
||||
if (type is FirImplicitTypeRef) {
|
||||
type = FirErrorTypeRefImpl(null, "Incomplete code")
|
||||
type = FirErrorTypeRefImpl(null, FirSimpleDiagnostic("Incomplete code"))
|
||||
}
|
||||
|
||||
val status = FirDeclarationStatusImpl(modifiers.getVisibility(), modifiers.getModality()).apply {
|
||||
|
||||
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.fir.lightTree.fir
|
||||
import org.jetbrains.kotlin.fir.FirWhenSubject
|
||||
import org.jetbrains.kotlin.fir.builder.generateContainsOperation
|
||||
import org.jetbrains.kotlin.fir.builder.generateLazyLogicalOperation
|
||||
import org.jetbrains.kotlin.fir.diagnostics.FirSimpleDiagnostic
|
||||
import org.jetbrains.kotlin.fir.expressions.*
|
||||
import org.jetbrains.kotlin.fir.expressions.impl.FirErrorExpressionImpl
|
||||
import org.jetbrains.kotlin.fir.expressions.impl.FirOperatorCallImpl
|
||||
@@ -51,7 +52,7 @@ data class WhenEntry(
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
FirErrorExpressionImpl(null, "Unsupported when condition: ${this.javaClass}")
|
||||
FirErrorExpressionImpl(null, FirSimpleDiagnostic("Unsupported when condition: ${this.javaClass}"))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -59,7 +60,7 @@ data class WhenEntry(
|
||||
fun toFirWhenConditionWithoutSubject(): FirExpression {
|
||||
return when (val condition = conditions.first()) {
|
||||
is FirOperatorCallImpl -> condition.arguments.first()
|
||||
else -> FirErrorExpressionImpl(null, "No expression in condition with expression")
|
||||
else -> FirErrorExpressionImpl(null, FirSimpleDiagnostic("No expression in condition with expression"))
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user