Revert "[FIR] Fix error with incorrect destructing declaration"

This reverts commit b47910e86b.
This commit is contained in:
Egor Kulikov
2023-05-23 12:51:43 +02:00
parent b47910e86b
commit f432bbad2e
7 changed files with 13 additions and 58 deletions
@@ -311,12 +311,6 @@ internal class KtSymbolByFirBuilder constructor(
}
}
fun buildErrorVariableSymbol(firSymbol: FirErrorPropertySymbol): KtFirErrorVariableSymbol {
return symbolsCache.cache(firSymbol) {
KtFirErrorVariableSymbol(firSymbol, analysisSession)
}
}
fun buildSyntheticJavaPropertySymbol(firSymbol: FirSyntheticPropertySymbol): KtFirSyntheticJavaPropertySymbol {
return symbolsCache.cache(firSymbol) {
KtFirSyntheticJavaPropertySymbol(firSymbol, analysisSession)
@@ -18,18 +18,18 @@ import org.jetbrains.kotlin.analysis.api.symbols.pointers.CanNotCreateSymbolPoin
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtPsiBasedSymbolPointer
import org.jetbrains.kotlin.analysis.api.symbols.pointers.KtSymbolPointer
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.fir.declarations.FirErrorProperty
import org.jetbrains.kotlin.fir.declarations.FirProperty
import org.jetbrains.kotlin.fir.declarations.FirVariable
import org.jetbrains.kotlin.fir.symbols.impl.FirErrorPropertySymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirVariableSymbol
import org.jetbrains.kotlin.name.Name
internal abstract class KtFirLocalOrErrorVariableSymbol<E: FirVariable, S: FirVariableSymbol<E>>(
override val firSymbol: S,
internal class KtFirLocalVariableSymbol(
override val firSymbol: FirPropertySymbol,
override val analysisSession: KtFirAnalysisSession,
) : KtLocalVariableSymbol(), KtFirSymbol<S> {
) : KtLocalVariableSymbol(),
KtFirSymbol<FirPropertySymbol> {
init {
assert(firSymbol.isLocal)
}
override val psi: PsiElement? = withValidityAssertion { firSymbol.fir.getAllowedPsi() }
override val annotationsList: KtAnnotationsList
@@ -37,6 +37,7 @@ internal abstract class KtFirLocalOrErrorVariableSymbol<E: FirVariable, S: FirVa
KtFirAnnotationListForDeclaration.create(firSymbol, analysisSession.useSiteSession, token)
}
override val isVal: Boolean get() = withValidityAssertion { firSymbol.isVal }
override val name: Name get() = withValidityAssertion { firSymbol.name }
override val returnType: KtType get() = withValidityAssertion { firSymbol.returnType(builder) }
@@ -50,22 +51,4 @@ internal abstract class KtFirLocalOrErrorVariableSymbol<E: FirVariable, S: FirVa
override fun equals(other: Any?): Boolean = symbolEquals(other)
override fun hashCode(): Int = symbolHashCode()
}
internal class KtFirLocalVariableSymbol(firSymbol: FirPropertySymbol, analysisSession: KtFirAnalysisSession) :
KtFirLocalOrErrorVariableSymbol<FirProperty, FirPropertySymbol>(firSymbol, analysisSession) {
init {
assert(firSymbol.isLocal)
}
override val isVal: Boolean get() = withValidityAssertion { firSymbol.isVal }
}
internal class KtFirErrorVariableSymbol(
firSymbol: FirErrorPropertySymbol,
analysisSession: KtFirAnalysisSession,
) : KtFirLocalOrErrorVariableSymbol<FirErrorProperty, FirErrorPropertySymbol>(firSymbol, analysisSession),
KtFirSymbol<FirErrorPropertySymbol> {
override val isVal: Boolean
get() = firSymbol.fir.isVal
}
@@ -11,7 +11,6 @@ import org.jetbrains.kotlin.analysis.api.getModule
import org.jetbrains.kotlin.analysis.api.symbols.*
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.getOrBuildFirFile
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.resolveToFirSymbolOfType
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.throwUnexpectedFirElementError
import org.jetbrains.kotlin.analysis.low.level.api.fir.util.errorWithFirSpecificEntries
import org.jetbrains.kotlin.analysis.low.level.api.fir.util.withFirSymbolEntry
import org.jetbrains.kotlin.analysis.utils.errors.buildErrorWithAttachment
@@ -186,11 +185,9 @@ internal class KtFirSymbolProvider(
override val ROOT_PACKAGE_SYMBOL: KtPackageSymbol = KtFirPackageSymbol(FqName.ROOT, firResolveSession.project, token)
override fun getDestructuringDeclarationEntrySymbol(psi: KtDestructuringDeclarationEntry): KtFirLocalOrErrorVariableSymbol<*, *> {
return when (val firSymbol = psi.resolveToFirSymbolOfType<FirVariableSymbol<*>>(firResolveSession)) {
is FirPropertySymbol -> firSymbolBuilder.variableLikeBuilder.buildLocalVariableSymbol(firSymbol)
is FirErrorPropertySymbol -> firSymbolBuilder.variableLikeBuilder.buildErrorVariableSymbol(firSymbol)
else -> throwUnexpectedFirElementError(firSymbol, psi, FirPropertySymbol::class, FirErrorPropertySymbol::class)
}
override fun getDestructuringDeclarationEntrySymbol(psi: KtDestructuringDeclarationEntry): KtLocalVariableSymbol {
return firSymbolBuilder.variableLikeBuilder.buildLocalVariableSymbol(
psi.resolveToFirSymbolOfType<FirPropertySymbol>(firResolveSession)
)
}
}
@@ -1 +0,0 @@
val (<expr>o</expr>, r)
@@ -1,6 +0,0 @@
KT element: KtDestructuringDeclarationEntry
FIR element: FirErrorPropertyImpl
FIR source kind: KtRealSourceElementKind
FIR element rendered:
<ERROR PROPERTY: Destructuring declarations are only allowed for local variables/values>
@@ -441,12 +441,6 @@ public class OutOfContentRootGetOrBuildFirTestGenerated extends AbstractOutOfCon
runTest("analysis/low-level-api-fir/testdata/getOrBuildFir/declarations/constructorProperty.kt");
}
@Test
@TestMetadata("destructionWithNoRValue.kt")
public void testDestructionWithNoRValue() throws Exception {
runTest("analysis/low-level-api-fir/testdata/getOrBuildFir/declarations/destructionWithNoRValue.kt");
}
@Test
@TestMetadata("destructuring.kt")
public void testDestructuring() throws Exception {
@@ -441,12 +441,6 @@ public class SourceGetOrBuildFirTestGenerated extends AbstractSourceGetOrBuildFi
runTest("analysis/low-level-api-fir/testdata/getOrBuildFir/declarations/constructorProperty.kt");
}
@Test
@TestMetadata("destructionWithNoRValue.kt")
public void testDestructionWithNoRValue() throws Exception {
runTest("analysis/low-level-api-fir/testdata/getOrBuildFir/declarations/destructionWithNoRValue.kt");
}
@Test
@TestMetadata("destructuring.kt")
public void testDestructuring() throws Exception {