From 9894b9705894e213fcf221ee9f2f42f6bbdb735d Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Fri, 16 Apr 2021 10:23:54 +0300 Subject: [PATCH] FIR: rename EXPRESSION_REQUIRED to EXPRESSION_EXPECTED --- .../diagnostics/FirDiagnosticsList.kt | 2 +- .../fir/analysis/diagnostics/FirErrors.kt | 2 +- .../coneDiagnosticToFirDiagnostic.kt | 2 +- .../converter/DeclarationsConverter.kt | 2 +- .../converter/ExpressionsConverter.kt | 6 ++---- .../kotlin/fir/builder/RawFirBuilder.kt | 4 ++-- .../kotlin/fir/builder/BaseFirBuilder.kt | 2 +- .../fir/diagnostics/ConeSimpleDiagnostic.kt | 2 +- .../ForbidStatementAsDirectFunctionBody.fir.kt | 2 +- .../kt770.kt351.kt735_StatementType.fir.kt | 10 +++++----- .../namedFunAsLastExpressionInBlock.fir.kt | 8 ++++---- .../NameDeprecation.fir.kt | 2 +- .../diagnostics/tests/regressions/kt629.fir.kt | 4 ++-- .../statements/assignments/p-1/neg/2.1.fir.kt | 18 +++++++++--------- .../diagnostics/KtFirDataClassConverters.kt | 4 ++-- .../api/fir/diagnostics/KtFirDiagnostics.kt | 4 ++-- .../fir/diagnostics/KtFirDiagnosticsImpl.kt | 4 ++-- 17 files changed, 38 insertions(+), 40 deletions(-) diff --git a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt index 5aa079436f4..003cb402df1 100644 --- a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt +++ b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt @@ -49,7 +49,7 @@ object DIAGNOSTICS_LIST : DiagnosticList() { val GENERAL_SYNTAX by object : DiagnosticGroup("General syntax") { val ILLEGAL_CONST_EXPRESSION by error() val ILLEGAL_UNDERSCORE by error() - val EXPRESSION_REQUIRED by error(PositioningStrategy.SELECTOR_BY_QUALIFIED) + val EXPRESSION_EXPECTED by error(PositioningStrategy.SELECTOR_BY_QUALIFIED) val BREAK_OR_CONTINUE_OUTSIDE_A_LOOP by error() val NOT_A_LOOP_LABEL by error() val VARIABLE_EXPECTED by error() diff --git a/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt b/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt index f2e039c4e7e..e1ee81b3540 100644 --- a/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt +++ b/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt @@ -75,7 +75,7 @@ object FirErrors { // General syntax val ILLEGAL_CONST_EXPRESSION by error0() val ILLEGAL_UNDERSCORE by error0() - val EXPRESSION_REQUIRED by error0(SourceElementPositioningStrategies.SELECTOR_BY_QUALIFIED) + val EXPRESSION_EXPECTED by error0(SourceElementPositioningStrategies.SELECTOR_BY_QUALIFIED) val BREAK_OR_CONTINUE_OUTSIDE_A_LOOP by error0() val NOT_A_LOOP_LABEL by error0() val VARIABLE_EXPECTED by error0() diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt index 12e555dba29..c3a3794fe42 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt @@ -174,7 +174,7 @@ private fun ConeSimpleDiagnostic.getFactory(): FirDiagnosticFactory0<*> { DiagnosticKind.RecursionInImplicitTypes -> FirErrors.RECURSION_IN_IMPLICIT_TYPES DiagnosticKind.Java -> FirErrors.ERROR_FROM_JAVA_RESOLUTION DiagnosticKind.SuperNotAllowed -> FirErrors.SUPER_IS_NOT_AN_EXPRESSION - DiagnosticKind.ExpressionRequired -> FirErrors.EXPRESSION_REQUIRED + DiagnosticKind.ExpressionExpected -> FirErrors.EXPRESSION_EXPECTED DiagnosticKind.JumpOutsideLoop -> FirErrors.BREAK_OR_CONTINUE_OUTSIDE_A_LOOP DiagnosticKind.NotLoopLabel -> FirErrors.NOT_A_LOOP_LABEL DiagnosticKind.VariableExpected -> FirErrors.VARIABLE_EXPECTED diff --git a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt index f9690cb3fac..d7153cc0b0c 100644 --- a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt +++ b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt @@ -1245,7 +1245,7 @@ class DeclarationsConverter( CONTRACT_EFFECT -> { val effect = it.getFirstChild() if (effect == null) { - val errorExpression = buildErrorExpression(null, ConeSimpleDiagnostic(errorReason, DiagnosticKind.ExpressionRequired)) + val errorExpression = buildErrorExpression(null, ConeSimpleDiagnostic(errorReason, DiagnosticKind.ExpressionExpected)) destination.add(errorExpression) } else { val expression = expressionConverter.convertExpression(effect, errorReason) diff --git a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/ExpressionsConverter.kt b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/ExpressionsConverter.kt index 9ac5557d8e6..ece52e140d4 100644 --- a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/ExpressionsConverter.kt +++ b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/ExpressionsConverter.kt @@ -8,7 +8,6 @@ package org.jetbrains.kotlin.fir.lightTree.converter import com.intellij.lang.LighterASTNode import com.intellij.psi.TokenType import com.intellij.util.diff.FlyweightCapableTreeStructure -import org.jetbrains.kotlin.KtNodeTypes import org.jetbrains.kotlin.KtNodeTypes.* import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.descriptors.Visibilities @@ -40,7 +39,6 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirVariableSymbol import org.jetbrains.kotlin.fir.types.FirTypeProjection import org.jetbrains.kotlin.fir.types.FirTypeRef import org.jetbrains.kotlin.lexer.KtTokens.* -import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.stubs.elements.KtConstantExpressionElementType import org.jetbrains.kotlin.types.ConstantValueKind import org.jetbrains.kotlin.types.expressions.OperatorConventions @@ -60,7 +58,7 @@ class ExpressionsConverter( return expression?.let { convertExpression(it, errorReason) } as? R ?: buildErrorExpression( - null, ConeSimpleDiagnostic(errorReason, DiagnosticKind.ExpressionRequired) + null, ConeSimpleDiagnostic(errorReason, DiagnosticKind.ExpressionExpected) ) as R } @@ -111,7 +109,7 @@ class ExpressionsConverter( OBJECT_LITERAL -> declarationsConverter.convertObjectLiteral(expression) FUN -> declarationsConverter.convertFunctionDeclaration(expression) - else -> buildErrorExpression(null, ConeSimpleDiagnostic(errorReason, DiagnosticKind.ExpressionRequired)) + else -> buildErrorExpression(null, ConeSimpleDiagnostic(errorReason, DiagnosticKind.ExpressionExpected)) } } diff --git a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt index 803e1444fed..c677db88912 100644 --- a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt +++ b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt @@ -180,13 +180,13 @@ open class RawFirBuilder( if (stubMode) buildExpressionStub() else with(this()) { convertSafe() ?: buildErrorExpression( - this?.toFirSourceElement(), ConeSimpleDiagnostic(errorReason, DiagnosticKind.ExpressionRequired), + this?.toFirSourceElement(), ConeSimpleDiagnostic(errorReason, DiagnosticKind.ExpressionExpected), ) } private fun KtExpression?.toFirExpression( errorReason: String, - kind: DiagnosticKind = DiagnosticKind.ExpressionRequired, + kind: DiagnosticKind = DiagnosticKind.ExpressionExpected, ): FirExpression = if (stubMode) buildExpressionStub() else convertSafe() ?: buildErrorExpression( diff --git a/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/BaseFirBuilder.kt b/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/BaseFirBuilder.kt index 9ccfa3269ce..ee402ae6837 100644 --- a/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/BaseFirBuilder.kt +++ b/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/BaseFirBuilder.kt @@ -910,7 +910,7 @@ abstract class BaseFirBuilder(val baseSession: FirSession, val context: Conte } ?: buildErrorExpression { source = null diagnostic = ConeSimpleDiagnostic( - "Unsupported left value of assignment: ${baseSource?.psi?.text}", DiagnosticKind.ExpressionRequired + "Unsupported left value of assignment: ${baseSource?.psi?.text}", DiagnosticKind.ExpressionExpected ) } rightArgument = value diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/diagnostics/ConeSimpleDiagnostic.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/diagnostics/ConeSimpleDiagnostic.kt index 09984b6c3b8..b28f54636f3 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/diagnostics/ConeSimpleDiagnostic.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/diagnostics/ConeSimpleDiagnostic.kt @@ -9,7 +9,7 @@ class ConeSimpleDiagnostic(override val reason: String, val kind: DiagnosticKind enum class DiagnosticKind { Syntax, - ExpressionRequired, + ExpressionExpected, NotLoopLabel, JumpOutsideLoop, VariableExpected, diff --git a/compiler/testData/diagnostics/tests/controlStructures/ForbidStatementAsDirectFunctionBody.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/ForbidStatementAsDirectFunctionBody.fir.kt index d04af15180f..e992d0c1e90 100644 --- a/compiler/testData/diagnostics/tests/controlStructures/ForbidStatementAsDirectFunctionBody.fir.kt +++ b/compiler/testData/diagnostics/tests/controlStructures/ForbidStatementAsDirectFunctionBody.fir.kt @@ -1,5 +1,5 @@ -fun foo1() = while (b()) {} +fun foo1() = while (b()) {} fun foo2() = for (i in 10) {} diff --git a/compiler/testData/diagnostics/tests/controlStructures/kt770.kt351.kt735_StatementType.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/kt770.kt351.kt735_StatementType.fir.kt index b5a6ce953dc..0f21703676b 100644 --- a/compiler/testData/diagnostics/tests/controlStructures/kt770.kt351.kt735_StatementType.fir.kt +++ b/compiler/testData/diagnostics/tests/controlStructures/kt770.kt351.kt735_StatementType.fir.kt @@ -15,7 +15,7 @@ fun main() { } //KT-351 Distinguish statement and expression positions -val w = while (true) {} +val w = while (true) {} fun foo() { var z = 2 @@ -149,12 +149,12 @@ fun bar(a: Unit) {} fun testStatementInExpressionContext() { var z = 34 - val a1: Unit = z = 334 + val a1: Unit = z = 334 val f = for (i in 1..10) {} - if (true) return z = 34 - return while (true) {} + if (true) return z = 34 + return while (true) {} } fun testStatementInExpressionContext2() { - val a2: Unit = while(true) {} + val a2: Unit = while(true) {} } diff --git a/compiler/testData/diagnostics/tests/declarationChecks/namedFunAsLastExpressionInBlock.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/namedFunAsLastExpressionInBlock.fir.kt index 501a6e79e7c..210d97a29fb 100644 --- a/compiler/testData/diagnostics/tests/declarationChecks/namedFunAsLastExpressionInBlock.fir.kt +++ b/compiler/testData/diagnostics/tests/declarationChecks/namedFunAsLastExpressionInBlock.fir.kt @@ -4,7 +4,7 @@ fun foo(block: () -> (() -> Int)) {} fun test() { - val x = fun named1(x: Int): Int { return 1 } + val x = fun named1(x: Int): Int { return 1 } x checkType { _>() } foo { fun named2(): Int {return 1} } @@ -45,12 +45,12 @@ fun test() { x4 checkType { _>() } { y: Int -> fun named14(): Int {return 1} } - val b = (fun named15(): Boolean { return true })() + val b = (fun named15(): Boolean { return true })() - baz(fun named16(){}) + baz(fun named16(){}) } -fun bar() = fun named() {} +fun bar() = fun named() {} fun run(block: () -> T): T = null!! fun run2(block: () -> Unit): Unit = null!! diff --git a/compiler/testData/diagnostics/tests/functionAsExpression/NameDeprecation.fir.kt b/compiler/testData/diagnostics/tests/functionAsExpression/NameDeprecation.fir.kt index 36981a1a7bb..e271c3c32c7 100644 --- a/compiler/testData/diagnostics/tests/functionAsExpression/NameDeprecation.fir.kt +++ b/compiler/testData/diagnostics/tests/functionAsExpression/NameDeprecation.fir.kt @@ -5,5 +5,5 @@ fun foo() { fun A.foo() {} (fun A.foo() {}) - run(fun foo() {}) + run(fun foo() {}) } diff --git a/compiler/testData/diagnostics/tests/regressions/kt629.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt629.fir.kt index 3133a7bf398..607c074789b 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt629.fir.kt +++ b/compiler/testData/diagnostics/tests/regressions/kt629.fir.kt @@ -13,11 +13,11 @@ fun box() : Boolean { var c = A() val d = c; c %= A(); - return (c != d) && (c.p = "yeah") + return (c != d) && (c.p = "yeah") } fun box2() : Boolean { var c = A() - return (c.p = "yeah") && true + return (c.p = "yeah") && true } diff --git a/compiler/tests-spec/testData/diagnostics/linked/statements/assignments/p-1/neg/2.1.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/statements/assignments/p-1/neg/2.1.fir.kt index ded1370c989..44616393786 100644 --- a/compiler/tests-spec/testData/diagnostics/linked/statements/assignments/p-1/neg/2.1.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/linked/statements/assignments/p-1/neg/2.1.fir.kt @@ -10,9 +10,9 @@ fun case1() { val x = for () { } val y = for (x in 1..2) { } - val a = while () { } - val b = while (false) { } - val c = while () ; + val a = while () { } + val b = while (false) { } + val c = while () ; } /* @@ -23,9 +23,9 @@ fun case2() { var x = for () { } var y = for (x in 1..2) { } - var a = while () { } - var b = while (false) { } - var c = while () ; + var a = while () { } + var b = while (false) { } + var c = while () ; } /* @@ -43,9 +43,9 @@ fun case3() { x = for () { } y = for (x in 1..2) { } - a = while () { } - b = while (false) { } - c = while () ; + a = while () { } + b = while (false) { } + c = while () ; } /* diff --git a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDataClassConverters.kt b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDataClassConverters.kt index 2084245db3c..f10f0c86a2b 100644 --- a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDataClassConverters.kt +++ b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDataClassConverters.kt @@ -88,8 +88,8 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert token, ) } - add(FirErrors.EXPRESSION_REQUIRED) { firDiagnostic -> - ExpressionRequiredImpl( + add(FirErrors.EXPRESSION_EXPECTED) { firDiagnostic -> + ExpressionExpectedImpl( firDiagnostic as FirPsiDiagnostic<*>, token, ) diff --git a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnostics.kt b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnostics.kt index 898af03a93a..afc5a7e0d7b 100644 --- a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnostics.kt +++ b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnostics.kt @@ -83,8 +83,8 @@ sealed class KtFirDiagnostic : KtDiagnosticWithPsi { override val diagnosticClass get() = IllegalUnderscore::class } - abstract class ExpressionRequired : KtFirDiagnostic() { - override val diagnosticClass get() = ExpressionRequired::class + abstract class ExpressionExpected : KtFirDiagnostic() { + override val diagnosticClass get() = ExpressionExpected::class } abstract class BreakOrContinueOutsideALoop : KtFirDiagnostic() { diff --git a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnosticsImpl.kt b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnosticsImpl.kt index 66278e9b576..0c95cc3dd64 100644 --- a/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnosticsImpl.kt +++ b/idea/idea-frontend-fir/src/org/jetbrains/kotlin/idea/frontend/api/fir/diagnostics/KtFirDiagnosticsImpl.kt @@ -102,10 +102,10 @@ internal class IllegalUnderscoreImpl( override val firDiagnostic: FirPsiDiagnostic<*> by weakRef(firDiagnostic) } -internal class ExpressionRequiredImpl( +internal class ExpressionExpectedImpl( firDiagnostic: FirPsiDiagnostic<*>, override val token: ValidityToken, -) : KtFirDiagnostic.ExpressionRequired(), KtAbstractFirDiagnostic { +) : KtFirDiagnostic.ExpressionExpected(), KtAbstractFirDiagnostic { override val firDiagnostic: FirPsiDiagnostic<*> by weakRef(firDiagnostic) }