FIR: rename EXPRESSION_REQUIRED to EXPRESSION_EXPECTED

This commit is contained in:
Mikhail Glukhikh
2021-04-16 10:23:54 +03:00
parent 26ea0be635
commit 9894b97058
17 changed files with 38 additions and 40 deletions
@@ -49,7 +49,7 @@ object DIAGNOSTICS_LIST : DiagnosticList() {
val GENERAL_SYNTAX by object : DiagnosticGroup("General syntax") {
val ILLEGAL_CONST_EXPRESSION by error<PsiElement>()
val ILLEGAL_UNDERSCORE by error<PsiElement>()
val EXPRESSION_REQUIRED by error<PsiElement>(PositioningStrategy.SELECTOR_BY_QUALIFIED)
val EXPRESSION_EXPECTED by error<PsiElement>(PositioningStrategy.SELECTOR_BY_QUALIFIED)
val BREAK_OR_CONTINUE_OUTSIDE_A_LOOP by error<PsiElement>()
val NOT_A_LOOP_LABEL by error<PsiElement>()
val VARIABLE_EXPECTED by error<PsiElement>()
@@ -75,7 +75,7 @@ object FirErrors {
// General syntax
val ILLEGAL_CONST_EXPRESSION by error0<PsiElement>()
val ILLEGAL_UNDERSCORE by error0<PsiElement>()
val EXPRESSION_REQUIRED by error0<PsiElement>(SourceElementPositioningStrategies.SELECTOR_BY_QUALIFIED)
val EXPRESSION_EXPECTED by error0<PsiElement>(SourceElementPositioningStrategies.SELECTOR_BY_QUALIFIED)
val BREAK_OR_CONTINUE_OUTSIDE_A_LOOP by error0<PsiElement>()
val NOT_A_LOOP_LABEL by error0<PsiElement>()
val VARIABLE_EXPECTED by error0<PsiElement>()
@@ -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
@@ -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)
@@ -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))
}
}
@@ -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(
@@ -910,7 +910,7 @@ abstract class BaseFirBuilder<T>(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
@@ -9,7 +9,7 @@ class ConeSimpleDiagnostic(override val reason: String, val kind: DiagnosticKind
enum class DiagnosticKind {
Syntax,
ExpressionRequired,
ExpressionExpected,
NotLoopLabel,
JumpOutsideLoop,
VariableExpected,
@@ -1,5 +1,5 @@
fun foo1() = <!EXPRESSION_REQUIRED!>while (b()) {}<!>
fun foo1() = <!EXPRESSION_EXPECTED!>while (b()) {}<!>
fun foo2() = <!UNRESOLVED_REFERENCE, UNRESOLVED_REFERENCE, UNRESOLVED_REFERENCE!>for (i in 10) {}<!>
@@ -15,7 +15,7 @@ fun main() {
}
//KT-351 Distinguish statement and expression positions
val w = <!EXPRESSION_REQUIRED!>while (true) {}<!>
val w = <!EXPRESSION_EXPECTED!>while (true) {}<!>
fun foo() {
var z = 2
@@ -149,12 +149,12 @@ fun bar(a: Unit) {}
fun testStatementInExpressionContext() {
var z = 34
val a1: Unit = <!EXPRESSION_REQUIRED!>z = 334<!>
val a1: Unit = <!EXPRESSION_EXPECTED!>z = 334<!>
val f = for (i in 1..10) {}
if (true) return <!EXPRESSION_REQUIRED!>z = 34<!>
return <!EXPRESSION_REQUIRED!>while (true) {}<!>
if (true) return <!EXPRESSION_EXPECTED!>z = 34<!>
return <!EXPRESSION_EXPECTED!>while (true) {}<!>
}
fun testStatementInExpressionContext2() {
val a2: Unit = <!EXPRESSION_REQUIRED!>while(true) {}<!>
val a2: Unit = <!EXPRESSION_EXPECTED!>while(true) {}<!>
}
@@ -4,7 +4,7 @@
fun foo(block: () -> (() -> Int)) {}
fun test() {
val x = <!EXPRESSION_REQUIRED!>fun named1(x: Int): Int { return 1 }<!>
val x = <!EXPRESSION_EXPECTED!>fun named1(x: Int): Int { return 1 }<!>
x <!INAPPLICABLE_CANDIDATE!>checkType<!> { <!INAPPLICABLE_CANDIDATE!>_<!><Function1<Int, Int>>() }
foo { fun named2(): Int {return 1} }
@@ -45,12 +45,12 @@ fun test() {
x4 checkType { _<Function1<Int, Unit>>() }
{ y: Int -> fun named14(): Int {return 1} }
val b = (<!EXPRESSION_REQUIRED, UNRESOLVED_REFERENCE!>fun named15(): Boolean { return true }<!>)()
val b = (<!EXPRESSION_EXPECTED, UNRESOLVED_REFERENCE!>fun named15(): Boolean { return true }<!>)()
baz(<!EXPRESSION_REQUIRED!>fun named16(){}<!>)
baz(<!EXPRESSION_EXPECTED!>fun named16(){}<!>)
}
fun bar() = <!EXPRESSION_REQUIRED!>fun named() {}<!>
fun bar() = <!EXPRESSION_EXPECTED!>fun named() {}<!>
fun <T> run(block: () -> T): T = null!!
fun run2(block: () -> Unit): Unit = null!!
@@ -5,5 +5,5 @@ fun foo() {
fun A.foo() {}
(fun A.foo() {})
run(<!EXPRESSION_REQUIRED!>fun foo() {}<!>)
run(<!EXPRESSION_EXPECTED!>fun foo() {}<!>)
}
@@ -13,11 +13,11 @@ fun box() : Boolean {
var c = A()
val d = c;
c %= A();
return (c != d) && <!EXPRESSION_REQUIRED!>(c.p = "yeah")<!>
return (c != d) && <!EXPRESSION_EXPECTED!>(c.p = "yeah")<!>
}
fun box2() : Boolean {
var c = A()
return <!EXPRESSION_REQUIRED!>(c.p = "yeah")<!> && true
return <!EXPRESSION_EXPECTED!>(c.p = "yeah")<!> && true
}
@@ -10,9 +10,9 @@ fun case1() {
val x = <!OVERLOAD_RESOLUTION_AMBIGUITY, UNRESOLVED_REFERENCE!>for (<!SYNTAX!><!>) { }<!>
val y = for (x in 1..2) { }
val a = <!EXPRESSION_REQUIRED!>while (<!SYNTAX!><!>) { }<!>
val b = <!EXPRESSION_REQUIRED!>while (false) { }<!>
val c = <!EXPRESSION_REQUIRED!>while (<!SYNTAX!><!>) <!>;
val a = <!EXPRESSION_EXPECTED!>while (<!SYNTAX!><!>) { }<!>
val b = <!EXPRESSION_EXPECTED!>while (false) { }<!>
val c = <!EXPRESSION_EXPECTED!>while (<!SYNTAX!><!>) <!>;
}
/*
@@ -23,9 +23,9 @@ fun case2() {
var x = <!OVERLOAD_RESOLUTION_AMBIGUITY, UNRESOLVED_REFERENCE!>for (<!SYNTAX!><!>) { }<!>
var y = for (x in 1..2) { }
var a = <!EXPRESSION_REQUIRED!>while (<!SYNTAX!><!>) { }<!>
var b = <!EXPRESSION_REQUIRED!>while (false) { }<!>
var c = <!EXPRESSION_REQUIRED!>while (<!SYNTAX!><!>) <!>;
var a = <!EXPRESSION_EXPECTED!>while (<!SYNTAX!><!>) { }<!>
var b = <!EXPRESSION_EXPECTED!>while (false) { }<!>
var c = <!EXPRESSION_EXPECTED!>while (<!SYNTAX!><!>) <!>;
}
/*
@@ -43,9 +43,9 @@ fun case3() {
x = <!OVERLOAD_RESOLUTION_AMBIGUITY, UNRESOLVED_REFERENCE!>for (<!SYNTAX!><!>) { }<!>
y = for (x in 1..2) { }
a = <!EXPRESSION_REQUIRED!>while (<!SYNTAX!><!>) { }<!>
b = <!EXPRESSION_REQUIRED!>while (false) { }<!>
c = <!EXPRESSION_REQUIRED!>while (<!SYNTAX!><!>) <!>;
a = <!EXPRESSION_EXPECTED!>while (<!SYNTAX!><!>) { }<!>
b = <!EXPRESSION_EXPECTED!>while (false) { }<!>
c = <!EXPRESSION_EXPECTED!>while (<!SYNTAX!><!>) <!>;
}
/*
@@ -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,
)
@@ -83,8 +83,8 @@ sealed class KtFirDiagnostic<PSI: PsiElement> : KtDiagnosticWithPsi<PSI> {
override val diagnosticClass get() = IllegalUnderscore::class
}
abstract class ExpressionRequired : KtFirDiagnostic<PsiElement>() {
override val diagnosticClass get() = ExpressionRequired::class
abstract class ExpressionExpected : KtFirDiagnostic<PsiElement>() {
override val diagnosticClass get() = ExpressionExpected::class
}
abstract class BreakOrContinueOutsideALoop : KtFirDiagnostic<PsiElement>() {
@@ -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<PsiElement> {
) : KtFirDiagnostic.ExpressionExpected(), KtAbstractFirDiagnostic<PsiElement> {
override val firDiagnostic: FirPsiDiagnostic<*> by weakRef(firDiagnostic)
}