[AA] Handle KtTypeReference children in CompileTimeConstantProvider
CompileTimeConstantProvider could receive a reference expression, whose grandparent is KtTypeReference (seen that in UAST inspection). FIR would not contain anything explicit for this reference, FirResolvedTypeRef would be received as the nearest parent. Of course, in this case, there could be no compile time constant anyway.
This commit is contained in:
+6
@@ -112,6 +112,12 @@ public class Fe10IdeNormalAnalysisSourceModuleCompileTimeConstantEvaluatorTestGe
|
||||
runTest("analysis/analysis-api/testData/components/compileTimeConstantProvider/evaluate/namedReference_const.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("namedReference_userType.kt")
|
||||
public void testNamedReference_userType() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/compileTimeConstantProvider/evaluate/namedReference_userType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("namedReference_val.kt")
|
||||
public void testNamedReference_val() throws Exception {
|
||||
|
||||
+2
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.fir.expressions.FirPropertyAccessExpression
|
||||
import org.jetbrains.kotlin.fir.expressions.FirVariableAssignment
|
||||
import org.jetbrains.kotlin.fir.expressions.FirWhenBranch
|
||||
import org.jetbrains.kotlin.fir.references.FirNamedReference
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||
import org.jetbrains.kotlin.psi
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
|
||||
@@ -67,6 +68,7 @@ internal class KtFirCompileTimeConstantProvider(
|
||||
// case, we simply report null since FIR does not know about it.
|
||||
fir is FirWhenBranch -> null
|
||||
fir is FirVariableAssignment && fir.source?.kind == KtFakeSourceElementKind.DesugaredIncrementOrDecrement -> null
|
||||
fir is FirTypeRef -> null
|
||||
else -> throwUnexpectedFirElementError(fir, sourcePsi)
|
||||
}
|
||||
}
|
||||
|
||||
+6
@@ -112,6 +112,12 @@ public class FirIdeDependentAnalysisSourceModuleCompileTimeConstantEvaluatorTest
|
||||
runTest("analysis/analysis-api/testData/components/compileTimeConstantProvider/evaluate/namedReference_const.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("namedReference_userType.kt")
|
||||
public void testNamedReference_userType() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/compileTimeConstantProvider/evaluate/namedReference_userType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("namedReference_val.kt")
|
||||
public void testNamedReference_val() throws Exception {
|
||||
|
||||
+6
@@ -112,6 +112,12 @@ public class FirIdeNormalAnalysisSourceModuleCompileTimeConstantEvaluatorTestGen
|
||||
runTest("analysis/analysis-api/testData/components/compileTimeConstantProvider/evaluate/namedReference_const.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("namedReference_userType.kt")
|
||||
public void testNamedReference_userType() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/compileTimeConstantProvider/evaluate/namedReference_userType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("namedReference_val.kt")
|
||||
public void testNamedReference_val() throws Exception {
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ import org.jetbrains.kotlin.test.services.assertions
|
||||
|
||||
abstract class AbstractCompileTimeConstantEvaluatorTest : AbstractAnalysisApiSingleFileTest() {
|
||||
override fun doTestByFileStructure(ktFile: KtFile, module: TestModule, testServices: TestServices) {
|
||||
val element = testServices.expressionMarkerProvider.getSelectedElement(ktFile)
|
||||
val element = testServices.expressionMarkerProvider.getSelectedElementOfTypeByDirective(ktFile, module)
|
||||
val expression = when (element) {
|
||||
is KtExpression -> element
|
||||
is KtValueArgument -> element.getArgumentExpression()
|
||||
|
||||
+6
@@ -112,6 +112,12 @@ public class FirStandaloneNormalAnalysisSourceModuleCompileTimeConstantEvaluator
|
||||
runTest("analysis/analysis-api/testData/components/compileTimeConstantProvider/evaluate/namedReference_const.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("namedReference_userType.kt")
|
||||
public void testNamedReference_userType() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/compileTimeConstantProvider/evaluate/namedReference_userType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("namedReference_val.kt")
|
||||
public void testNamedReference_val() throws Exception {
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
// LOOK_UP_FOR_ELEMENT_OF_TYPE: KtNameReferenceExpression
|
||||
class Test {
|
||||
fun box(t : Test?) {
|
||||
val inst = t is <expr>Test</expr>
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
expression: Test
|
||||
|
||||
CONSTANT_EXPRESSION_EVALUATION
|
||||
constant: NOT_EVALUATED
|
||||
constantValueKind: NOT_EVALUATED
|
||||
|
||||
CONSTANT_LIKE_EXPRESSION_EVALUATION
|
||||
constantLike: NOT_EVALUATED
|
||||
constantLikeValueKind: NOT_EVALUATED
|
||||
Reference in New Issue
Block a user