FIR: rename EXPRESSION_REQUIRED to EXPRESSION_EXPECTED
This commit is contained in:
+1
-1
@@ -49,7 +49,7 @@ object DIAGNOSTICS_LIST : DiagnosticList() {
|
|||||||
val GENERAL_SYNTAX by object : DiagnosticGroup("General syntax") {
|
val GENERAL_SYNTAX by object : DiagnosticGroup("General syntax") {
|
||||||
val ILLEGAL_CONST_EXPRESSION by error<PsiElement>()
|
val ILLEGAL_CONST_EXPRESSION by error<PsiElement>()
|
||||||
val ILLEGAL_UNDERSCORE 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 BREAK_OR_CONTINUE_OUTSIDE_A_LOOP by error<PsiElement>()
|
||||||
val NOT_A_LOOP_LABEL by error<PsiElement>()
|
val NOT_A_LOOP_LABEL by error<PsiElement>()
|
||||||
val VARIABLE_EXPECTED by error<PsiElement>()
|
val VARIABLE_EXPECTED by error<PsiElement>()
|
||||||
|
|||||||
+1
-1
@@ -75,7 +75,7 @@ object FirErrors {
|
|||||||
// General syntax
|
// General syntax
|
||||||
val ILLEGAL_CONST_EXPRESSION by error0<PsiElement>()
|
val ILLEGAL_CONST_EXPRESSION by error0<PsiElement>()
|
||||||
val ILLEGAL_UNDERSCORE 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 BREAK_OR_CONTINUE_OUTSIDE_A_LOOP by error0<PsiElement>()
|
||||||
val NOT_A_LOOP_LABEL by error0<PsiElement>()
|
val NOT_A_LOOP_LABEL by error0<PsiElement>()
|
||||||
val VARIABLE_EXPECTED by error0<PsiElement>()
|
val VARIABLE_EXPECTED by error0<PsiElement>()
|
||||||
|
|||||||
+1
-1
@@ -174,7 +174,7 @@ private fun ConeSimpleDiagnostic.getFactory(): FirDiagnosticFactory0<*> {
|
|||||||
DiagnosticKind.RecursionInImplicitTypes -> FirErrors.RECURSION_IN_IMPLICIT_TYPES
|
DiagnosticKind.RecursionInImplicitTypes -> FirErrors.RECURSION_IN_IMPLICIT_TYPES
|
||||||
DiagnosticKind.Java -> FirErrors.ERROR_FROM_JAVA_RESOLUTION
|
DiagnosticKind.Java -> FirErrors.ERROR_FROM_JAVA_RESOLUTION
|
||||||
DiagnosticKind.SuperNotAllowed -> FirErrors.SUPER_IS_NOT_AN_EXPRESSION
|
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.JumpOutsideLoop -> FirErrors.BREAK_OR_CONTINUE_OUTSIDE_A_LOOP
|
||||||
DiagnosticKind.NotLoopLabel -> FirErrors.NOT_A_LOOP_LABEL
|
DiagnosticKind.NotLoopLabel -> FirErrors.NOT_A_LOOP_LABEL
|
||||||
DiagnosticKind.VariableExpected -> FirErrors.VARIABLE_EXPECTED
|
DiagnosticKind.VariableExpected -> FirErrors.VARIABLE_EXPECTED
|
||||||
|
|||||||
+1
-1
@@ -1245,7 +1245,7 @@ class DeclarationsConverter(
|
|||||||
CONTRACT_EFFECT -> {
|
CONTRACT_EFFECT -> {
|
||||||
val effect = it.getFirstChild()
|
val effect = it.getFirstChild()
|
||||||
if (effect == null) {
|
if (effect == null) {
|
||||||
val errorExpression = buildErrorExpression(null, ConeSimpleDiagnostic(errorReason, DiagnosticKind.ExpressionRequired))
|
val errorExpression = buildErrorExpression(null, ConeSimpleDiagnostic(errorReason, DiagnosticKind.ExpressionExpected))
|
||||||
destination.add(errorExpression)
|
destination.add(errorExpression)
|
||||||
} else {
|
} else {
|
||||||
val expression = expressionConverter.convertExpression(effect, errorReason)
|
val expression = expressionConverter.convertExpression(effect, errorReason)
|
||||||
|
|||||||
+2
-4
@@ -8,7 +8,6 @@ package org.jetbrains.kotlin.fir.lightTree.converter
|
|||||||
import com.intellij.lang.LighterASTNode
|
import com.intellij.lang.LighterASTNode
|
||||||
import com.intellij.psi.TokenType
|
import com.intellij.psi.TokenType
|
||||||
import com.intellij.util.diff.FlyweightCapableTreeStructure
|
import com.intellij.util.diff.FlyweightCapableTreeStructure
|
||||||
import org.jetbrains.kotlin.KtNodeTypes
|
|
||||||
import org.jetbrains.kotlin.KtNodeTypes.*
|
import org.jetbrains.kotlin.KtNodeTypes.*
|
||||||
import org.jetbrains.kotlin.descriptors.Modality
|
import org.jetbrains.kotlin.descriptors.Modality
|
||||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
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.FirTypeProjection
|
||||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens.*
|
import org.jetbrains.kotlin.lexer.KtTokens.*
|
||||||
import org.jetbrains.kotlin.name.Name
|
|
||||||
import org.jetbrains.kotlin.psi.stubs.elements.KtConstantExpressionElementType
|
import org.jetbrains.kotlin.psi.stubs.elements.KtConstantExpressionElementType
|
||||||
import org.jetbrains.kotlin.types.ConstantValueKind
|
import org.jetbrains.kotlin.types.ConstantValueKind
|
||||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
||||||
@@ -60,7 +58,7 @@ class ExpressionsConverter(
|
|||||||
return expression?.let {
|
return expression?.let {
|
||||||
convertExpression(it, errorReason)
|
convertExpression(it, errorReason)
|
||||||
} as? R ?: buildErrorExpression(
|
} as? R ?: buildErrorExpression(
|
||||||
null, ConeSimpleDiagnostic(errorReason, DiagnosticKind.ExpressionRequired)
|
null, ConeSimpleDiagnostic(errorReason, DiagnosticKind.ExpressionExpected)
|
||||||
) as R
|
) as R
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,7 +109,7 @@ class ExpressionsConverter(
|
|||||||
|
|
||||||
OBJECT_LITERAL -> declarationsConverter.convertObjectLiteral(expression)
|
OBJECT_LITERAL -> declarationsConverter.convertObjectLiteral(expression)
|
||||||
FUN -> declarationsConverter.convertFunctionDeclaration(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()
|
if (stubMode) buildExpressionStub()
|
||||||
else with(this()) {
|
else with(this()) {
|
||||||
convertSafe() ?: buildErrorExpression(
|
convertSafe() ?: buildErrorExpression(
|
||||||
this?.toFirSourceElement(), ConeSimpleDiagnostic(errorReason, DiagnosticKind.ExpressionRequired),
|
this?.toFirSourceElement(), ConeSimpleDiagnostic(errorReason, DiagnosticKind.ExpressionExpected),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun KtExpression?.toFirExpression(
|
private fun KtExpression?.toFirExpression(
|
||||||
errorReason: String,
|
errorReason: String,
|
||||||
kind: DiagnosticKind = DiagnosticKind.ExpressionRequired,
|
kind: DiagnosticKind = DiagnosticKind.ExpressionExpected,
|
||||||
): FirExpression =
|
): FirExpression =
|
||||||
if (stubMode) buildExpressionStub()
|
if (stubMode) buildExpressionStub()
|
||||||
else convertSafe() ?: buildErrorExpression(
|
else convertSafe() ?: buildErrorExpression(
|
||||||
|
|||||||
+1
-1
@@ -910,7 +910,7 @@ abstract class BaseFirBuilder<T>(val baseSession: FirSession, val context: Conte
|
|||||||
} ?: buildErrorExpression {
|
} ?: buildErrorExpression {
|
||||||
source = null
|
source = null
|
||||||
diagnostic = ConeSimpleDiagnostic(
|
diagnostic = ConeSimpleDiagnostic(
|
||||||
"Unsupported left value of assignment: ${baseSource?.psi?.text}", DiagnosticKind.ExpressionRequired
|
"Unsupported left value of assignment: ${baseSource?.psi?.text}", DiagnosticKind.ExpressionExpected
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
rightArgument = value
|
rightArgument = value
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ class ConeSimpleDiagnostic(override val reason: String, val kind: DiagnosticKind
|
|||||||
|
|
||||||
enum class DiagnosticKind {
|
enum class DiagnosticKind {
|
||||||
Syntax,
|
Syntax,
|
||||||
ExpressionRequired,
|
ExpressionExpected,
|
||||||
NotLoopLabel,
|
NotLoopLabel,
|
||||||
JumpOutsideLoop,
|
JumpOutsideLoop,
|
||||||
VariableExpected,
|
VariableExpected,
|
||||||
|
|||||||
Vendored
+1
-1
@@ -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) {}<!>
|
fun foo2() = <!UNRESOLVED_REFERENCE, UNRESOLVED_REFERENCE, UNRESOLVED_REFERENCE!>for (i in 10) {}<!>
|
||||||
|
|
||||||
|
|||||||
Vendored
+5
-5
@@ -15,7 +15,7 @@ fun main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//KT-351 Distinguish statement and expression positions
|
//KT-351 Distinguish statement and expression positions
|
||||||
val w = <!EXPRESSION_REQUIRED!>while (true) {}<!>
|
val w = <!EXPRESSION_EXPECTED!>while (true) {}<!>
|
||||||
|
|
||||||
fun foo() {
|
fun foo() {
|
||||||
var z = 2
|
var z = 2
|
||||||
@@ -149,12 +149,12 @@ fun bar(a: Unit) {}
|
|||||||
|
|
||||||
fun testStatementInExpressionContext() {
|
fun testStatementInExpressionContext() {
|
||||||
var z = 34
|
var z = 34
|
||||||
val a1: Unit = <!EXPRESSION_REQUIRED!>z = 334<!>
|
val a1: Unit = <!EXPRESSION_EXPECTED!>z = 334<!>
|
||||||
val f = for (i in 1..10) {}
|
val f = for (i in 1..10) {}
|
||||||
if (true) return <!EXPRESSION_REQUIRED!>z = 34<!>
|
if (true) return <!EXPRESSION_EXPECTED!>z = 34<!>
|
||||||
return <!EXPRESSION_REQUIRED!>while (true) {}<!>
|
return <!EXPRESSION_EXPECTED!>while (true) {}<!>
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testStatementInExpressionContext2() {
|
fun testStatementInExpressionContext2() {
|
||||||
val a2: Unit = <!EXPRESSION_REQUIRED!>while(true) {}<!>
|
val a2: Unit = <!EXPRESSION_EXPECTED!>while(true) {}<!>
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+4
-4
@@ -4,7 +4,7 @@
|
|||||||
fun foo(block: () -> (() -> Int)) {}
|
fun foo(block: () -> (() -> Int)) {}
|
||||||
|
|
||||||
fun test() {
|
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>>() }
|
x <!INAPPLICABLE_CANDIDATE!>checkType<!> { <!INAPPLICABLE_CANDIDATE!>_<!><Function1<Int, Int>>() }
|
||||||
|
|
||||||
foo { fun named2(): Int {return 1} }
|
foo { fun named2(): Int {return 1} }
|
||||||
@@ -45,12 +45,12 @@ fun test() {
|
|||||||
x4 checkType { _<Function1<Int, Unit>>() }
|
x4 checkType { _<Function1<Int, Unit>>() }
|
||||||
|
|
||||||
{ y: Int -> fun named14(): Int {return 1} }
|
{ 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 <T> run(block: () -> T): T = null!!
|
||||||
fun run2(block: () -> Unit): Unit = null!!
|
fun run2(block: () -> Unit): Unit = null!!
|
||||||
|
|||||||
+1
-1
@@ -5,5 +5,5 @@ fun foo() {
|
|||||||
fun A.foo() {}
|
fun A.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()
|
var c = A()
|
||||||
val d = c;
|
val d = c;
|
||||||
c %= A();
|
c %= A();
|
||||||
return (c != d) && <!EXPRESSION_REQUIRED!>(c.p = "yeah")<!>
|
return (c != d) && <!EXPRESSION_EXPECTED!>(c.p = "yeah")<!>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun box2() : Boolean {
|
fun box2() : Boolean {
|
||||||
var c = A()
|
var c = A()
|
||||||
return <!EXPRESSION_REQUIRED!>(c.p = "yeah")<!> && true
|
return <!EXPRESSION_EXPECTED!>(c.p = "yeah")<!> && true
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-9
@@ -10,9 +10,9 @@ fun case1() {
|
|||||||
val x = <!OVERLOAD_RESOLUTION_AMBIGUITY, UNRESOLVED_REFERENCE!>for (<!SYNTAX!><!>) { }<!>
|
val x = <!OVERLOAD_RESOLUTION_AMBIGUITY, UNRESOLVED_REFERENCE!>for (<!SYNTAX!><!>) { }<!>
|
||||||
val y = for (x in 1..2) { }
|
val y = for (x in 1..2) { }
|
||||||
|
|
||||||
val a = <!EXPRESSION_REQUIRED!>while (<!SYNTAX!><!>) { }<!>
|
val a = <!EXPRESSION_EXPECTED!>while (<!SYNTAX!><!>) { }<!>
|
||||||
val b = <!EXPRESSION_REQUIRED!>while (false) { }<!>
|
val b = <!EXPRESSION_EXPECTED!>while (false) { }<!>
|
||||||
val c = <!EXPRESSION_REQUIRED!>while (<!SYNTAX!><!>) <!>;
|
val c = <!EXPRESSION_EXPECTED!>while (<!SYNTAX!><!>) <!>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -23,9 +23,9 @@ fun case2() {
|
|||||||
var x = <!OVERLOAD_RESOLUTION_AMBIGUITY, UNRESOLVED_REFERENCE!>for (<!SYNTAX!><!>) { }<!>
|
var x = <!OVERLOAD_RESOLUTION_AMBIGUITY, UNRESOLVED_REFERENCE!>for (<!SYNTAX!><!>) { }<!>
|
||||||
var y = for (x in 1..2) { }
|
var y = for (x in 1..2) { }
|
||||||
|
|
||||||
var a = <!EXPRESSION_REQUIRED!>while (<!SYNTAX!><!>) { }<!>
|
var a = <!EXPRESSION_EXPECTED!>while (<!SYNTAX!><!>) { }<!>
|
||||||
var b = <!EXPRESSION_REQUIRED!>while (false) { }<!>
|
var b = <!EXPRESSION_EXPECTED!>while (false) { }<!>
|
||||||
var c = <!EXPRESSION_REQUIRED!>while (<!SYNTAX!><!>) <!>;
|
var c = <!EXPRESSION_EXPECTED!>while (<!SYNTAX!><!>) <!>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -43,9 +43,9 @@ fun case3() {
|
|||||||
x = <!OVERLOAD_RESOLUTION_AMBIGUITY, UNRESOLVED_REFERENCE!>for (<!SYNTAX!><!>) { }<!>
|
x = <!OVERLOAD_RESOLUTION_AMBIGUITY, UNRESOLVED_REFERENCE!>for (<!SYNTAX!><!>) { }<!>
|
||||||
y = for (x in 1..2) { }
|
y = for (x in 1..2) { }
|
||||||
|
|
||||||
a = <!EXPRESSION_REQUIRED!>while (<!SYNTAX!><!>) { }<!>
|
a = <!EXPRESSION_EXPECTED!>while (<!SYNTAX!><!>) { }<!>
|
||||||
b = <!EXPRESSION_REQUIRED!>while (false) { }<!>
|
b = <!EXPRESSION_EXPECTED!>while (false) { }<!>
|
||||||
c = <!EXPRESSION_REQUIRED!>while (<!SYNTAX!><!>) <!>;
|
c = <!EXPRESSION_EXPECTED!>while (<!SYNTAX!><!>) <!>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
+2
-2
@@ -88,8 +88,8 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
|
|||||||
token,
|
token,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
add(FirErrors.EXPRESSION_REQUIRED) { firDiagnostic ->
|
add(FirErrors.EXPRESSION_EXPECTED) { firDiagnostic ->
|
||||||
ExpressionRequiredImpl(
|
ExpressionExpectedImpl(
|
||||||
firDiagnostic as FirPsiDiagnostic<*>,
|
firDiagnostic as FirPsiDiagnostic<*>,
|
||||||
token,
|
token,
|
||||||
)
|
)
|
||||||
|
|||||||
+2
-2
@@ -83,8 +83,8 @@ sealed class KtFirDiagnostic<PSI: PsiElement> : KtDiagnosticWithPsi<PSI> {
|
|||||||
override val diagnosticClass get() = IllegalUnderscore::class
|
override val diagnosticClass get() = IllegalUnderscore::class
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class ExpressionRequired : KtFirDiagnostic<PsiElement>() {
|
abstract class ExpressionExpected : KtFirDiagnostic<PsiElement>() {
|
||||||
override val diagnosticClass get() = ExpressionRequired::class
|
override val diagnosticClass get() = ExpressionExpected::class
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class BreakOrContinueOutsideALoop : KtFirDiagnostic<PsiElement>() {
|
abstract class BreakOrContinueOutsideALoop : KtFirDiagnostic<PsiElement>() {
|
||||||
|
|||||||
+2
-2
@@ -102,10 +102,10 @@ internal class IllegalUnderscoreImpl(
|
|||||||
override val firDiagnostic: FirPsiDiagnostic<*> by weakRef(firDiagnostic)
|
override val firDiagnostic: FirPsiDiagnostic<*> by weakRef(firDiagnostic)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class ExpressionRequiredImpl(
|
internal class ExpressionExpectedImpl(
|
||||||
firDiagnostic: FirPsiDiagnostic<*>,
|
firDiagnostic: FirPsiDiagnostic<*>,
|
||||||
override val token: ValidityToken,
|
override val token: ValidityToken,
|
||||||
) : KtFirDiagnostic.ExpressionRequired(), KtAbstractFirDiagnostic<PsiElement> {
|
) : KtFirDiagnostic.ExpressionExpected(), KtAbstractFirDiagnostic<PsiElement> {
|
||||||
override val firDiagnostic: FirPsiDiagnostic<*> by weakRef(firDiagnostic)
|
override val firDiagnostic: FirPsiDiagnostic<*> by weakRef(firDiagnostic)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user