From 60195114c1ac3bef3088fdf8e4d6af7751a8be79 Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Wed, 4 Aug 2021 16:02:22 +0300 Subject: [PATCH] [FIR] Properly create class scopes while resolving of annotations arguments --- ...TouchedTilContractsPhaseTestGenerated.java | 5 ++++ .../nestedClassInAnnotationArgument.fir.txt | 26 +++++++++++++++++++ .../nestedClassInAnnotationArgument.kt | 11 ++++++++ .../runners/FirDiagnosticTestGenerated.java | 6 +++++ ...DiagnosticsWithLightTreeTestGenerated.java | 6 +++++ ...irAnnotationArgumentsResolveTransformer.kt | 12 +++++---- ...nosisCompilerFirTestdataTestGenerated.java | 6 +++++ 7 files changed, 67 insertions(+), 5 deletions(-) create mode 100644 compiler/fir/analysis-tests/testData/resolve/arguments/nestedClassInAnnotationArgument.fir.txt create mode 100644 compiler/fir/analysis-tests/testData/resolve/arguments/nestedClassInAnnotationArgument.kt 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 bd7d02a1b0f..d3ae6f1f707 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 @@ -621,6 +621,11 @@ public class LazyBodyIsNotTouchedTilContractsPhaseTestGenerated extends Abstract runTest("compiler/fir/analysis-tests/testData/resolve/arguments/namedArrayInAnnotation.kt"); } + @TestMetadata("nestedClassInAnnotationArgument.kt") + public void testNestedClassInAnnotationArgument() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/arguments/nestedClassInAnnotationArgument.kt"); + } + @TestMetadata("noParameterForName.kt") public void testNoParameterForName() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/arguments/noParameterForName.kt"); diff --git a/compiler/fir/analysis-tests/testData/resolve/arguments/nestedClassInAnnotationArgument.fir.txt b/compiler/fir/analysis-tests/testData/resolve/arguments/nestedClassInAnnotationArgument.fir.txt new file mode 100644 index 00000000000..1dce1127110 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/arguments/nestedClassInAnnotationArgument.fir.txt @@ -0,0 +1,26 @@ +FILE: nestedClassInAnnotationArgument.kt + public final annotation class Ann : R|kotlin/Annotation| { + public constructor(kClass: R|kotlin/reflect/KClass<*>|): R|Ann| { + super() + } + + public final val kClass: R|kotlin/reflect/KClass<*>| = R|/kClass| + public get(): R|kotlin/reflect/KClass<*>| + + } + public final class A : R|kotlin/Any| { + public constructor(): R|A| { + super() + } + + @R|Ann|((Q|A.EmptyList|)) public final fun foo(): R|kotlin/Unit| { + } + + public final object EmptyList : R|kotlin/Any| { + private constructor(): R|A.EmptyList| { + super() + } + + } + + } diff --git a/compiler/fir/analysis-tests/testData/resolve/arguments/nestedClassInAnnotationArgument.kt b/compiler/fir/analysis-tests/testData/resolve/arguments/nestedClassInAnnotationArgument.kt new file mode 100644 index 00000000000..fef016a959f --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/arguments/nestedClassInAnnotationArgument.kt @@ -0,0 +1,11 @@ +// WITH_STDLIB +import kotlin.reflect.KClass + +annotation class Ann(val kClass: KClass<*>) + +class A { + @Ann(EmptyList::class) + fun foo() {} + + object EmptyList +} 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 451e205f86a..baa12cab2d9 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 @@ -731,6 +731,12 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest { runTest("compiler/fir/analysis-tests/testData/resolve/arguments/namedArrayInAnnotation.kt"); } + @Test + @TestMetadata("nestedClassInAnnotationArgument.kt") + public void testNestedClassInAnnotationArgument() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/arguments/nestedClassInAnnotationArgument.kt"); + } + @Test @TestMetadata("noParameterForName.kt") public void testNoParameterForName() 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 915b54cb650..f93d512c92c 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 @@ -731,6 +731,12 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos runTest("compiler/fir/analysis-tests/testData/resolve/arguments/namedArrayInAnnotation.kt"); } + @Test + @TestMetadata("nestedClassInAnnotationArgument.kt") + public void testNestedClassInAnnotationArgument() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/arguments/nestedClassInAnnotationArgument.kt"); + } + @Test @TestMetadata("noParameterForName.kt") public void testNoParameterForName() throws Exception { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/plugin/FirAnnotationArgumentsResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/plugin/FirAnnotationArgumentsResolveTransformer.kt index 0adda066d43..fdef9f92b3f 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/plugin/FirAnnotationArgumentsResolveTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/plugin/FirAnnotationArgumentsResolveTransformer.kt @@ -38,11 +38,13 @@ private class FirDeclarationsResolveTransformerForArgumentAnnotations( override fun transformRegularClass(regularClass: FirRegularClass, data: ResolutionMode): FirStatement { regularClass.transformAnnotations(this, data) context.withContainingClass(regularClass) { - regularClass - .transformTypeParameters(transformer, data) - .transformSuperTypeRefs(transformer, data) - .transformDeclarations(transformer, data) - .transformCompanionObject(transformer, data) + context.withRegularClass(regularClass, components) { + regularClass + .transformTypeParameters(transformer, data) + .transformSuperTypeRefs(transformer, data) + .transformDeclarations(transformer, data) + .transformCompanionObject(transformer, data) + } } return regularClass } diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java b/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java index 7d22a81d5ba..1288ef698fa 100644 --- a/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java @@ -731,6 +731,12 @@ public class DiagnosisCompilerFirTestdataTestGenerated extends AbstractDiagnosis runTest("compiler/fir/analysis-tests/testData/resolve/arguments/namedArrayInAnnotation.kt"); } + @Test + @TestMetadata("nestedClassInAnnotationArgument.kt") + public void testNestedClassInAnnotationArgument() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/arguments/nestedClassInAnnotationArgument.kt"); + } + @Test @TestMetadata("noParameterForName.kt") public void testNoParameterForName() throws Exception {