From a7276b25ae855920626b1a6a47cc51bcb7c7c1b0 Mon Sep 17 00:00:00 2001 From: Ivan Kochurkin Date: Fri, 25 Jun 2021 14:22:51 +0300 Subject: [PATCH] [FIR] Add `expression` field to FirErrorExpression It is used to report diagnostics even in erroneous code (within ILLEGAL_SELECTOR for instance). --- .../jetbrains/kotlin/fir/expressions/FirErrorExpression.kt | 1 + .../fir/expressions/builder/FirErrorExpressionBuilder.kt | 3 +++ .../kotlin/fir/expressions/impl/FirErrorExpressionImpl.kt | 4 ++++ .../jetbrains/kotlin/fir/expressions/impl/FirErrorLoopImpl.kt | 2 +- .../kotlin/fir/tree/generator/BuilderConfigurator.kt | 4 ++++ .../kotlin/fir/tree/generator/ImplementationConfigurator.kt | 2 +- .../jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt | 4 ++++ 7 files changed, 18 insertions(+), 2 deletions(-) diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/FirErrorExpression.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/FirErrorExpression.kt index af9db58a83e..c9f7f059aef 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/FirErrorExpression.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/FirErrorExpression.kt @@ -22,6 +22,7 @@ abstract class FirErrorExpression : FirExpression(), FirDiagnosticHolder { abstract override val typeRef: FirTypeRef abstract override val annotations: List abstract override val diagnostic: ConeDiagnostic + abstract val expression: FirExpression? override fun accept(visitor: FirVisitor, data: D): R = visitor.visitErrorExpression(this, data) diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/builder/FirErrorExpressionBuilder.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/builder/FirErrorExpressionBuilder.kt index 3fb4a00f289..8cc6bdc2280 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/builder/FirErrorExpressionBuilder.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/builder/FirErrorExpressionBuilder.kt @@ -13,6 +13,7 @@ import org.jetbrains.kotlin.fir.diagnostics.ConeDiagnostic import org.jetbrains.kotlin.fir.diagnostics.ConeStubDiagnostic import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall import org.jetbrains.kotlin.fir.expressions.FirErrorExpression +import org.jetbrains.kotlin.fir.expressions.FirExpression import org.jetbrains.kotlin.fir.expressions.builder.FirExpressionBuilder import org.jetbrains.kotlin.fir.expressions.impl.FirErrorExpressionImpl import org.jetbrains.kotlin.fir.types.FirTypeRef @@ -29,12 +30,14 @@ class FirErrorExpressionBuilder : FirAnnotationContainerBuilder, FirExpressionBu override var source: FirSourceElement? = null override val annotations: MutableList = mutableListOf() lateinit var diagnostic: ConeDiagnostic + var expression: FirExpression? = null override fun build(): FirErrorExpression { return FirErrorExpressionImpl( source, annotations, diagnostic, + expression, ) } diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/impl/FirErrorExpressionImpl.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/impl/FirErrorExpressionImpl.kt index 0ce7f7ea082..13a0b9be147 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/impl/FirErrorExpressionImpl.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/impl/FirErrorExpressionImpl.kt @@ -10,6 +10,7 @@ import org.jetbrains.kotlin.fir.diagnostics.ConeDiagnostic import org.jetbrains.kotlin.fir.diagnostics.ConeStubDiagnostic import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall import org.jetbrains.kotlin.fir.expressions.FirErrorExpression +import org.jetbrains.kotlin.fir.expressions.FirExpression import org.jetbrains.kotlin.fir.types.FirTypeRef import org.jetbrains.kotlin.fir.types.impl.FirErrorTypeRefImpl import org.jetbrains.kotlin.fir.visitors.* @@ -23,17 +24,20 @@ internal class FirErrorExpressionImpl( override val source: FirSourceElement?, override val annotations: MutableList, override val diagnostic: ConeDiagnostic, + override var expression: FirExpression?, ) : FirErrorExpression() { override var typeRef: FirTypeRef = FirErrorTypeRefImpl(source, null, ConeStubDiagnostic(diagnostic)) override fun acceptChildren(visitor: FirVisitor, data: D) { typeRef.accept(visitor, data) annotations.forEach { it.accept(visitor, data) } + expression?.accept(visitor, data) } override fun transformChildren(transformer: FirTransformer, data: D): FirErrorExpressionImpl { typeRef = typeRef.transform(transformer, data) transformAnnotations(transformer, data) + expression = expression?.transform(transformer, data) return this } diff --git a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/impl/FirErrorLoopImpl.kt b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/impl/FirErrorLoopImpl.kt index eea8e6e36ad..eade9129018 100644 --- a/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/impl/FirErrorLoopImpl.kt +++ b/compiler/fir/tree/gen/org/jetbrains/kotlin/fir/expressions/impl/FirErrorLoopImpl.kt @@ -28,7 +28,7 @@ internal class FirErrorLoopImpl( override val diagnostic: ConeDiagnostic, ) : FirErrorLoop() { override var block: FirBlock = FirEmptyExpressionBlock() - override var condition: FirExpression = FirErrorExpressionImpl(source, mutableListOf(), ConeStubDiagnostic(diagnostic)) + override var condition: FirExpression = FirErrorExpressionImpl(source, mutableListOf(), ConeStubDiagnostic(diagnostic), null) override fun acceptChildren(visitor: FirVisitor, data: D) { annotations.forEach { it.accept(visitor, data) } diff --git a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/BuilderConfigurator.kt b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/BuilderConfigurator.kt index 68dec640c75..712efb08de8 100644 --- a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/BuilderConfigurator.kt +++ b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/BuilderConfigurator.kt @@ -152,6 +152,10 @@ object BuilderConfigurator : AbstractBuilderConfigurator(FirTree defaultNull("label") } + builder(errorExpression) { + defaultNull("expression") + } + builder(errorLoop) { defaultNull("label") } diff --git a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/ImplementationConfigurator.kt b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/ImplementationConfigurator.kt index 8c868034295..89f1cccfb9a 100644 --- a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/ImplementationConfigurator.kt +++ b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/ImplementationConfigurator.kt @@ -133,7 +133,7 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator() impl(errorLoop) { default("block", "FirEmptyExpressionBlock()") - default("condition", "FirErrorExpressionImpl(source, mutableListOf(), ConeStubDiagnostic(diagnostic))") + default("condition", "FirErrorExpressionImpl(source, mutableListOf(), ConeStubDiagnostic(diagnostic), null)") useTypes(emptyExpressionBlock, coneStubDiagnosticType) } diff --git a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt index fed593b6f24..a2fa0c79dc1 100644 --- a/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt +++ b/compiler/fir/tree/tree-generator/src/org/jetbrains/kotlin/fir/tree/generator/NodeConfigurator.kt @@ -99,6 +99,10 @@ object NodeConfigurator : AbstractFieldConfigurator(FirTreeBuild +body(nullable = true, withReplace = true).withTransform() } + errorExpression.configure { + +field("expression", expression, nullable = true) + } + errorFunction.configure { +symbol("FirErrorFunctionSymbol") +typeParameters