[FIR] Do not throw exception on unexpected FIR for constants

^KTIJ-23263 fixed

Merge-request: KT-MR-10699
Merged-by: Egor Kulikov <Egor.Kulikov@jetbrains.com>
This commit is contained in:
Egor Kulikov
2023-06-19 17:45:31 +00:00
committed by Space Team
parent e4f1c10bc1
commit 5bb4f469ef
6 changed files with 36 additions and 5 deletions
@@ -264,8 +264,8 @@ internal class KtSymbolByFirBuilder constructor(
is FirFieldSymbol -> buildFieldSymbol(firSymbol)
is FirEnumEntrySymbol -> buildEnumEntrySymbol(firSymbol) // TODO enum entry should not be callable
is FirBackingFieldSymbol -> buildBackingFieldSymbol(firSymbol)
is FirErrorPropertySymbol -> buildErrorVariableSymbol(firSymbol)
is FirErrorPropertySymbol -> throwUnexpectedElementError(firSymbol)
is FirDelegateFieldSymbol -> throwUnexpectedElementError(firSymbol)
}
}
@@ -66,10 +66,7 @@ internal class KtFirCompileTimeConstantProvider(
// ```
// `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.
fir is FirWhenBranch -> null
fir is FirVariableAssignment && fir.source?.kind == KtFakeSourceElementKind.DesugaredIncrementOrDecrement -> null
fir is FirTypeRef -> null
else -> throwUnexpectedFirElementError(fir, sourcePsi)
else -> null
}
}
@@ -0,0 +1,4 @@
class InitOrderDemo(name: String) {
val (firstProperty = <expr>"First property"</expr>
}
@@ -0,0 +1,18 @@
KT element: KtStringTemplateExpression
FIR element: FirErrorPropertyImpl
FIR source kind: KtRealSourceElementKind
FIR element rendered:
<ERROR PROPERTY: Destructuring declarations are only allowed for local variables/values>
FIR FILE:
FILE: [ResolvedTo(IMPORTS)] ktij23263.kt
[ResolvedTo(BODY_RESOLVE)] annotations container
public? final? [ResolvedTo(RAW_FIR)] class InitOrderDemo : R|kotlin/Any| {
public? [ResolvedTo(RAW_FIR)] constructor([ResolvedTo(RAW_FIR)] name: String): R|InitOrderDemo| {
LAZY_super<R|kotlin/Any|>
}
<ERROR PROPERTY: Destructuring declarations are only allowed for local variables/values>
}
@@ -501,6 +501,12 @@ public class OutOfContentRootGetOrBuildFirTestGenerated extends AbstractOutOfCon
runTest("analysis/low-level-api-fir/testdata/getOrBuildFir/declarations/destructuringEntry.kt");
}
@Test
@TestMetadata("ktij23263.kt")
public void testKtij23263() throws Exception {
runTest("analysis/low-level-api-fir/testdata/getOrBuildFir/declarations/ktij23263.kt");
}
@Test
@TestMetadata("objectLiteral.kt")
public void testObjectLiteral() throws Exception {
@@ -501,6 +501,12 @@ public class SourceGetOrBuildFirTestGenerated extends AbstractSourceGetOrBuildFi
runTest("analysis/low-level-api-fir/testdata/getOrBuildFir/declarations/destructuringEntry.kt");
}
@Test
@TestMetadata("ktij23263.kt")
public void testKtij23263() throws Exception {
runTest("analysis/low-level-api-fir/testdata/getOrBuildFir/declarations/ktij23263.kt");
}
@Test
@TestMetadata("objectLiteral.kt")
public void testObjectLiteral() throws Exception {