[FIR] Fix invalid expression throwing exception when determining type
^KTIJ-25421 fixed Merge-request: KT-MR-10317 Merged-by: Egor Kulikov <Egor.Kulikov@jetbrains.com>
This commit is contained in:
+13
-8
@@ -74,19 +74,24 @@ internal class KtFirExpressionTypeProvider(
|
||||
is FirNamedReference -> fir.getReferencedElementType().asKtType()
|
||||
is FirStatement -> with(analysisSession) { builtinTypes.UNIT }
|
||||
is FirTypeRef, is FirImport, is FirPackageDirective, is FirLabel, is FirTypeParameterRef -> null
|
||||
// For invalid code like the following,
|
||||
|
||||
// `listOf<_>(1)` where `expression` is `_`
|
||||
is FirPlaceholderProjection -> null
|
||||
|
||||
// There are various cases where we have no corresponding fir due to invalid code
|
||||
// Some examples:
|
||||
// ```
|
||||
// when {
|
||||
// true, false -> {}
|
||||
// }
|
||||
// ```
|
||||
// `false` does not have a corresponding elements on the FIR side and hence the containing `FirWhenBranch` is returned. In this
|
||||
// case, we simply report null since FIR does not know about it.
|
||||
is FirWhenBranch -> null
|
||||
|
||||
// `listOf<_>(1)` where `expression` is `_`
|
||||
is FirPlaceholderProjection -> null
|
||||
else -> error("Unexpected ${fir?.let { it::class }} for ${expression::class} with text `${expression.text}`")
|
||||
// `false` does not have a corresponding elements on the FIR side and hence the containing `FirWhenBranch` is returned.
|
||||
// ```
|
||||
// @Volatile
|
||||
// private var
|
||||
// ```
|
||||
// Volatile does not have corresponding element, so `FirFileImpl` is returned
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
@<expr>Volatile</expr>
|
||||
private var
|
||||
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
KT element: KtConstructorCalleeExpression
|
||||
FIR element: FirAnnotationCallImpl
|
||||
FIR source kind: KtRealSourceElementKind
|
||||
|
||||
FIR element rendered:
|
||||
@<ERROR TYPE REF: Symbol not found for Volatile>[Types]()
|
||||
+6
@@ -805,6 +805,12 @@ public class OutOfContentRootGetOrBuildFirTestGenerated extends AbstractOutOfCon
|
||||
runTest("analysis/low-level-api-fir/testdata/getOrBuildFir/invalidCode/delegatedProperty.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("incompletePropertyWithAnnotation.kt")
|
||||
public void testIncompletePropertyWithAnnotation() throws Exception {
|
||||
runTest("analysis/low-level-api-fir/testdata/getOrBuildFir/invalidCode/incompletePropertyWithAnnotation.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("javaClassLiteral.kt")
|
||||
public void testJavaClassLiteral() throws Exception {
|
||||
|
||||
+6
@@ -805,6 +805,12 @@ public class SourceGetOrBuildFirTestGenerated extends AbstractSourceGetOrBuildFi
|
||||
runTest("analysis/low-level-api-fir/testdata/getOrBuildFir/invalidCode/delegatedProperty.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("incompletePropertyWithAnnotation.kt")
|
||||
public void testIncompletePropertyWithAnnotation() throws Exception {
|
||||
runTest("analysis/low-level-api-fir/testdata/getOrBuildFir/invalidCode/incompletePropertyWithAnnotation.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("javaClassLiteral.kt")
|
||||
public void testJavaClassLiteral() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user