diff --git a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirDesignatedAnnotationsResolveTransformed.kt b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirDesignatedAnnotationsResolveTransformed.kt index 4a862bb5760..74da3fad396 100644 --- a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirDesignatedAnnotationsResolveTransformed.kt +++ b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirDesignatedAnnotationsResolveTransformed.kt @@ -64,7 +64,7 @@ internal class LLFirDesignatedAnnotationsResolveTransformed( when (declaration) { is FirClass, is FirTypeAlias -> declaration.ensurePhase(FirResolvePhase.COMPILER_REQUIRED_ANNOTATIONS) - is FirFunction, is FirProperty, is FirEnumEntry, is FirField, is FirAnonymousInitializer -> + is FirFunction, is FirProperty, is FirEnumEntry, is FirField, is FirAnonymousInitializer, is FirErrorProperty -> Unit else -> error("Unexpected type: ${declaration::class.simpleName}") diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java index acccff19698..6ef310b53e4 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java @@ -512,6 +512,12 @@ public class DiagnosisCompilerFirTestdataTestGenerated extends AbstractDiagnosis runTest("compiler/fir/analysis-tests/testData/resolve/throwableSubclass.kt"); } + @Test + @TestMetadata("topLevelDestruction.kt") + public void testTopLevelDestruction() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/topLevelDestruction.kt"); + } + @Test @TestMetadata("treeSet.kt") public void testTreeSet() throws Exception { diff --git a/compiler/fir/analysis-tests/legacy-fir-tests/tests-gen/org/jetbrains/kotlin/fir/LazyBodyIsNotTouchedTilContractsPhaseTestGenerated.java b/compiler/fir/analysis-tests/legacy-fir-tests/tests-gen/org/jetbrains/kotlin/fir/LazyBodyIsNotTouchedTilContractsPhaseTestGenerated.java index c0385f22929..3f61a020c3c 100644 --- a/compiler/fir/analysis-tests/legacy-fir-tests/tests-gen/org/jetbrains/kotlin/fir/LazyBodyIsNotTouchedTilContractsPhaseTestGenerated.java +++ b/compiler/fir/analysis-tests/legacy-fir-tests/tests-gen/org/jetbrains/kotlin/fir/LazyBodyIsNotTouchedTilContractsPhaseTestGenerated.java @@ -434,6 +434,11 @@ public class LazyBodyIsNotTouchedTilContractsPhaseTestGenerated extends Abstract runTest("compiler/fir/analysis-tests/testData/resolve/throwableSubclass.kt"); } + @TestMetadata("topLevelDestruction.kt") + public void testTopLevelDestruction() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/topLevelDestruction.kt"); + } + @TestMetadata("treeSet.kt") public void testTreeSet() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/treeSet.kt"); diff --git a/compiler/fir/analysis-tests/testData/resolve/topLevelDestruction.fir.txt b/compiler/fir/analysis-tests/testData/resolve/topLevelDestruction.fir.txt new file mode 100644 index 00000000000..d6362e819bf --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/topLevelDestruction.fir.txt @@ -0,0 +1,2 @@ +FILE: topLevelDestruction.kt + diff --git a/compiler/fir/analysis-tests/testData/resolve/topLevelDestruction.kt b/compiler/fir/analysis-tests/testData/resolve/topLevelDestruction.kt new file mode 100644 index 00000000000..d1e6ae1cbbf --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/topLevelDestruction.kt @@ -0,0 +1 @@ +val (x, y) = Pair(1, 2) diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java index 22ead311fbb..4cb56d0d4e6 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java @@ -512,6 +512,12 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest { runTest("compiler/fir/analysis-tests/testData/resolve/throwableSubclass.kt"); } + @Test + @TestMetadata("topLevelDestruction.kt") + public void testTopLevelDestruction() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/topLevelDestruction.kt"); + } + @Test @TestMetadata("treeSet.kt") public void testTreeSet() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java index 3a27a47ae51..2b39884ebac 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java @@ -512,6 +512,12 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos runTest("compiler/fir/analysis-tests/testData/resolve/throwableSubclass.kt"); } + @Test + @TestMetadata("topLevelDestruction.kt") + public void testTopLevelDestruction() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/topLevelDestruction.kt"); + } + @Test @TestMetadata("treeSet.kt") public void testTreeSet() throws Exception { diff --git a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt index 0c9e0d8c796..92168c56e24 100644 --- a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt +++ b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt @@ -8,11 +8,8 @@ package org.jetbrains.kotlin.fir.lightTree.converter import com.intellij.lang.LighterASTNode import com.intellij.psi.TokenType import com.intellij.util.diff.FlyweightCapableTreeStructure +import org.jetbrains.kotlin.* import org.jetbrains.kotlin.ElementTypeUtils.isExpression -import org.jetbrains.kotlin.KtFakeSourceElementKind -import org.jetbrains.kotlin.KtLightSourceElement -import org.jetbrains.kotlin.KtSourceElement -import org.jetbrains.kotlin.KtNodeTypes import org.jetbrains.kotlin.KtNodeTypes.* import org.jetbrains.kotlin.builtins.StandardNames import org.jetbrains.kotlin.builtins.StandardNames.DEFAULT_VALUE_PARAMETER @@ -22,7 +19,6 @@ import org.jetbrains.kotlin.descriptors.Visibilities import org.jetbrains.kotlin.descriptors.Visibility import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget.* -import org.jetbrains.kotlin.fakeElement import org.jetbrains.kotlin.fir.* import org.jetbrains.kotlin.fir.builder.* import org.jetbrains.kotlin.fir.contracts.FirContractDescription @@ -94,18 +90,20 @@ class DeclarationsConverter( val firDeclarationList = mutableListOf() context.packageFqName = FqName.ROOT var packageDirective: FirPackageDirective? = null - file.forEachChildren { - when (it.tokenType) { - FILE_ANNOTATION_LIST -> fileAnnotationList += convertFileAnnotationList(it) + file.forEachChildren { child -> + @Suppress("RemoveRedundantQualifierName") + when (child.tokenType) { + FILE_ANNOTATION_LIST -> fileAnnotationList += convertFileAnnotationList(child) PACKAGE_DIRECTIVE -> { - packageDirective = convertPackageDirective(it).also { context.packageFqName = it.packageFqName } + packageDirective = convertPackageDirective(child).also { context.packageFqName = it.packageFqName } } - IMPORT_LIST -> importList += convertImportDirectives(it) - CLASS -> firDeclarationList += convertClass(it) - FUN -> firDeclarationList += convertFunctionDeclaration(it) as FirDeclaration - KtNodeTypes.PROPERTY -> firDeclarationList += convertPropertyDeclaration(it) - TYPEALIAS -> firDeclarationList += convertTypeAlias(it) - OBJECT_DECLARATION -> firDeclarationList += convertClass(it) + IMPORT_LIST -> importList += convertImportDirectives(child) + CLASS -> firDeclarationList += convertClass(child) + FUN -> firDeclarationList += convertFunctionDeclaration(child) as FirDeclaration + KtNodeTypes.PROPERTY -> firDeclarationList += convertPropertyDeclaration(child) + TYPEALIAS -> firDeclarationList += convertTypeAlias(child) + OBJECT_DECLARATION -> firDeclarationList += convertClass(child) + DESTRUCTURING_DECLARATION -> firDeclarationList += buildErrorTopLevelDestructuringDeclaration(child.toFirSourceElement()) SCRIPT -> { // TODO: scripts aren't supported yet } @@ -134,6 +132,7 @@ class DeclarationsConverter( fun convertBlockExpressionWithoutBuilding(block: LighterASTNode): FirBlockBuilder { val firStatements = block.forEachChildrenReturnList { node, container -> + @Suppress("RemoveRedundantQualifierName") when (node.tokenType) { CLASS, OBJECT_DECLARATION -> container += convertClass(node) as FirStatement FUN -> container += convertFunctionDeclaration(node) @@ -791,6 +790,7 @@ class DeclarationsConverter( */ private fun convertClassBody(classBody: LighterASTNode, classWrapper: ClassWrapper): List { return classBody.forEachChildrenReturnList { node, container -> + @Suppress("RemoveRedundantQualifierName") when (node.tokenType) { ENUM_ENTRY -> container += convertEnumEntry(node, classWrapper) CLASS -> container += convertClass(node) diff --git a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt index 637f3baf57d..93090e20674 100644 --- a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt +++ b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt @@ -929,9 +929,12 @@ open class RawFirBuilder( } } for (declaration in file.declarations) { - // TODO: scripts aren't supported yet - if (declaration is KtScript) continue - declarations += declaration.convert() + declarations += when (declaration) { + // TODO: scripts aren't supported yet + is KtScript -> continue + is KtDestructuringDeclaration -> buildErrorTopLevelDestructuringDeclaration(declaration.toFirSourceElement()) + else -> declaration.convert() + } } } } diff --git a/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/BaseFirBuilder.kt b/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/BaseFirBuilder.kt index 8afaa7c55b8..d339dc8609c 100644 --- a/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/BaseFirBuilder.kt +++ b/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/BaseFirBuilder.kt @@ -1261,6 +1261,17 @@ abstract class BaseFirBuilder(val baseSession: FirSession, val context: Conte } } + protected fun buildErrorTopLevelDestructuringDeclaration(source: KtSourceElement) = buildErrorProperty { + this.source = source + moduleData = baseModuleData + origin = FirDeclarationOrigin.Source + name = Name.special("") + diagnostic = ConeSimpleDiagnostic( + "Destructuring declarations are only allowed for local variables/values", DiagnosticKind.Syntax + ) + symbol = FirErrorPropertySymbol(diagnostic) + } + enum class ValueParameterDeclaration { OTHER, LAMBDA,