Skip to content

Commit 6d55c67

Browse files
abelkovSpace Team
authored andcommitted
[FIR] Set fake source kind for invalid expressions with no source
This helps AA ignore such error expressions. ^KT-79143 Fixed KT-75969
1 parent 5d25a68 commit 6d55c67

File tree

6 files changed

+29
-65
lines changed

6 files changed

+29
-65
lines changed

analysis/analysis-api/testData/components/resolver/singleByPsi/withErrors/incompleteBinaryExpression.call.txt

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
KtBinaryExpression(17,24): '"dsd" +'
22
KaSuccessCallInfo:
33
call = KaSimpleFunctionCall:
4-
argumentMapping = {
5-
"dsd" + -> (KaVariableSignature:
6-
name = other
7-
receiverType = null
8-
returnType = kotlin.Any?
9-
symbol = other: kotlin.Any?
10-
contextParameters = []
11-
callableId = null)
12-
}
4+
argumentMapping = {}
135
isImplicitInvoke = false
146
partiallyAppliedSymbol = KaPartiallyAppliedSymbol:
157
contextArguments = []

analysis/analysis-api/testData/components/resolver/singleByPsi/withErrors/incompleteBinaryExpression.candidates.txt

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
KtBinaryExpression(17,24): '"dsd" +'
22
KaApplicableCallCandidateInfo:
33
candidate = KaSimpleFunctionCall:
4-
argumentMapping = {
5-
"dsd" + -> (KaVariableSignature:
6-
name = other
7-
receiverType = null
8-
returnType = kotlin.Any?
9-
symbol = other: kotlin.Any?
10-
contextParameters = []
11-
callableId = null)
12-
}
4+
argumentMapping = {}
135
isImplicitInvoke = false
146
partiallyAppliedSymbol = KaPartiallyAppliedSymbol:
157
contextArguments = []
@@ -38,15 +30,7 @@ KtBinaryExpression(17,24): '"dsd" +'
3830

3931
KaApplicableCallCandidateInfo:
4032
candidate = KaSimpleFunctionCall:
41-
argumentMapping = {
42-
"dsd" + -> (KaVariableSignature:
43-
name = other
44-
receiverType = null
45-
returnType = kotlin.Any?
46-
symbol = other: kotlin.Any?
47-
contextParameters = []
48-
callableId = null)
49-
}
33+
argumentMapping = {}
5034
isImplicitInvoke = false
5135
partiallyAppliedSymbol = KaPartiallyAppliedSymbol:
5236
contextArguments = []
@@ -71,4 +55,4 @@ KtBinaryExpression(17,24): '"dsd" +'
7155
contextParameters = []
7256
callableId = kotlin/plus
7357
typeArgumentsMapping = {}
74-
isInBestCandidates = false
58+
isInBestCandidates = false

analysis/analysis-api/testData/components/resolver/singleByPsi/withErrors/incompleteBinaryExpression.descriptors.call.txt

Lines changed: 0 additions & 28 deletions
This file was deleted.

compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/LightTreeRawFirExpressionBuilder.kt

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,23 @@ class LightTreeRawFirExpressionBuilder(
9595
converted is R -> when {
9696
isValidExpression(converted) -> converted
9797
else -> buildErrorExpression(
98-
converted.source?.realElement() ?: expression?.toFirSourceElement() ?: sourceWhenInvalidExpression.toFirSourceElement(),
99-
ConeSimpleDiagnostic(errorReason, DiagnosticKind.ExpressionExpected),
100-
converted,
98+
source = converted.source?.realElement()
99+
?: expression?.toFirSourceElement()
100+
?: sourceWhenInvalidExpression.toFirSourceElement(kind = KtFakeSourceElementKind.ErrorExpression),
101+
diagnostic = ConeSimpleDiagnostic(errorReason, DiagnosticKind.ExpressionExpected),
102+
element = converted,
101103
)
102104
}
103105
else -> buildErrorExpression(
104-
converted?.source?.realElement() ?: expression?.toFirSourceElement() ?: sourceWhenInvalidExpression.toFirSourceElement(),
105-
if (expression == null) ConeSyntaxDiagnostic(errorReason)
106-
else ConeSimpleDiagnostic(errorReason, DiagnosticKind.ExpressionExpected),
107-
converted,
106+
source = converted?.source?.realElement()
107+
?: expression?.toFirSourceElement()
108+
?: sourceWhenInvalidExpression.toFirSourceElement(kind = KtFakeSourceElementKind.ErrorExpression),
109+
diagnostic = if (expression == null) {
110+
ConeSyntaxDiagnostic(errorReason)
111+
} else {
112+
ConeSimpleDiagnostic(errorReason, DiagnosticKind.ExpressionExpected)
113+
},
114+
element = converted,
108115
)
109116
} as R
110117
}

compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/PsiRawFirBuilder.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,10 @@ open class PsiRawFirBuilder(
346346
diagnosticFn: (missing: Boolean) -> ConeDiagnostic,
347347
): FirExpression {
348348
if (this == null) {
349-
return buildErrorExpression(source = sourceWhenInvalidExpression.toFirSourceElement(), diagnosticFn(true))
349+
return buildErrorExpression(
350+
source = sourceWhenInvalidExpression.toFirSourceElement(kind = KtFakeSourceElementKind.ErrorExpression),
351+
diagnosticFn(true)
352+
)
350353
}
351354

352355
return when (val fir = convertElement(this, null)) {
@@ -355,7 +358,8 @@ open class PsiRawFirBuilder(
355358
else -> buildErrorExpression {
356359
nonExpressionElement = fir
357360
diagnostic = diagnosticFn(false)
358-
source = fir.source?.realElement() ?: sourceWhenInvalidExpression.toFirSourceElement()
361+
source = fir.source?.realElement()
362+
?: sourceWhenInvalidExpression.toFirSourceElement(kind = KtFakeSourceElementKind.ErrorExpression)
359363
}
360364
}
361365
else -> buildErrorExpression {

compiler/frontend.common/src/org/jetbrains/kotlin/KtSourceElement.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,11 @@ sealed class KtFakeSourceElementKind(final override val shouldSkipErrorTypeRepor
557557
*/
558558
object ErrorExpressionForTopLevelLambda : KtFakeSourceElementKind()
559559

560+
/**
561+
* Arbitrary error expression for which we failed to build the real PSI.
562+
*/
563+
object ErrorExpression : KtFakeSourceElementKind()
564+
560565
/**
561566
* When resolving ENTRY as `MyEnum.ENTRY` this is used for the `MyEnum` part
562567
*/

0 commit comments

Comments
 (0)