diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirConstructorCallChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirConstructorCallChecker.kt index c2cf03efb5e..bbaf34efc73 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirConstructorCallChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirConstructorCallChecker.kt @@ -5,6 +5,7 @@ package org.jetbrains.kotlin.fir.analysis.checkers.expression +import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.descriptors.ClassKind import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext import org.jetbrains.kotlin.fir.analysis.checkers.toRegularClassSymbol @@ -37,7 +38,13 @@ object FirConstructorCallChecker : FirFunctionCallChecker() { klass !is FirRegularClass || klass.classKind != ClassKind.ANNOTATION_CLASS } ) { - reporter.reportOn(expression.source, FirErrors.ANNOTATION_CLASS_CONSTRUCTOR_CALL, context) + if (!context.languageVersionSettings.supportsFeature(LanguageFeature.InstantiationOfAnnotationClasses) || + declarationClass.typeParameterSymbols.isNotEmpty() + ) reporter.reportOn( + expression.source, + FirErrors.ANNOTATION_CLASS_CONSTRUCTOR_CALL, + context + ) } } } diff --git a/compiler/testData/codegen/box/annotations/instances/annotationEnclosingName.kt b/compiler/testData/codegen/box/annotations/instances/annotationEnclosingName.kt index 4cce7f5dfd4..69e60eda2c1 100644 --- a/compiler/testData/codegen/box/annotations/instances/annotationEnclosingName.kt +++ b/compiler/testData/codegen/box/annotations/instances/annotationEnclosingName.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // TARGET_BACKEND: JVM_IR // WITH_RUNTIME @@ -50,4 +49,4 @@ fun box(): String { test(G().insideClassAgain(), "test.E", "test_A1") test(outsideClass(), "test.TestKt", "test_A2") return "OK" -} \ No newline at end of file +} diff --git a/compiler/testData/codegen/box/annotations/instances/annotationEqHc.kt b/compiler/testData/codegen/box/annotations/instances/annotationEqHc.kt index 82eb64585e1..4a0fecfc116 100644 --- a/compiler/testData/codegen/box/annotations/instances/annotationEqHc.kt +++ b/compiler/testData/codegen/box/annotations/instances/annotationEqHc.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // IGNORE_BACKEND: JVM // IGNORE_BACKEND: WASM // DONT_TARGET_EXACT_BACKEND: JS @@ -29,4 +28,4 @@ fun box(): String { if (barlike != foo1.bar.hashCode()) return "Failed HC1" if (barlike != foo2.bar.hashCode()) return "Failed HC2" return "OK" -} \ No newline at end of file +} diff --git a/compiler/testData/codegen/box/annotations/instances/annotationFromStdlib.kt b/compiler/testData/codegen/box/annotations/instances/annotationFromStdlib.kt index ca06e6f77a8..694715b2d48 100644 --- a/compiler/testData/codegen/box/annotations/instances/annotationFromStdlib.kt +++ b/compiler/testData/codegen/box/annotations/instances/annotationFromStdlib.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // IGNORE_BACKEND: JVM // IGNORE_BACKEND: WASM // DONT_TARGET_EXACT_BACKEND: JS @@ -14,4 +13,4 @@ fun box(): String { val actualToString = ann1.toString() if (actualToString != expectedToString) return "Expected ann1.toString() equals to $expectedToString, but it's $actualToString" return "OK" -} \ No newline at end of file +} diff --git a/compiler/testData/codegen/box/annotations/instances/annotationInstances.kt b/compiler/testData/codegen/box/annotations/instances/annotationInstances.kt index ff3c42c5ce5..58d9edfed58 100644 --- a/compiler/testData/codegen/box/annotations/instances/annotationInstances.kt +++ b/compiler/testData/codegen/box/annotations/instances/annotationInstances.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // IGNORE_BACKEND: JVM // IGNORE_BACKEND: WASM diff --git a/compiler/testData/codegen/box/annotations/instances/annotationInstancesEmptyDefault.kt b/compiler/testData/codegen/box/annotations/instances/annotationInstancesEmptyDefault.kt index 80c8d48c4ba..16ebed37b97 100644 --- a/compiler/testData/codegen/box/annotations/instances/annotationInstancesEmptyDefault.kt +++ b/compiler/testData/codegen/box/annotations/instances/annotationInstancesEmptyDefault.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // IGNORE_BACKEND: JVM // IGNORE_BACKEND: WASM // DONT_TARGET_EXACT_BACKEND: JS @@ -46,4 +45,4 @@ fun box(): String { assertEquals("bar", p.s) assertEquals(E.B, p.e) return "OK" -} \ No newline at end of file +} diff --git a/compiler/testData/codegen/box/annotations/instances/annotationJvmHashCode.kt b/compiler/testData/codegen/box/annotations/instances/annotationJvmHashCode.kt index 47e34f44517..2e8414e52ac 100644 --- a/compiler/testData/codegen/box/annotations/instances/annotationJvmHashCode.kt +++ b/compiler/testData/codegen/box/annotations/instances/annotationJvmHashCode.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // TARGET_BACKEND: JVM_IR // WITH_RUNTIME diff --git a/compiler/testData/codegen/box/annotations/instances/annotationToString.kt b/compiler/testData/codegen/box/annotations/instances/annotationToString.kt index fa0831e7537..b2ebce05fe8 100644 --- a/compiler/testData/codegen/box/annotations/instances/annotationToString.kt +++ b/compiler/testData/codegen/box/annotations/instances/annotationToString.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // IGNORE_BACKEND: JVM // IGNORE_BACKEND: WASM // DONT_TARGET_EXACT_BACKEND: JS @@ -52,4 +51,4 @@ fun box(): String { .replace(" (Kotlin reflection is not available)", "") .replace("interface", "class") return if (s == targetJS || s == targetJVM || s == targetNative) "OK" else "FAILED, got string $s" -} \ No newline at end of file +} diff --git a/compiler/testData/codegen/box/annotations/instances/annotationType.kt b/compiler/testData/codegen/box/annotations/instances/annotationType.kt index 3e06b96bb22..f7417cd4471 100644 --- a/compiler/testData/codegen/box/annotations/instances/annotationType.kt +++ b/compiler/testData/codegen/box/annotations/instances/annotationType.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // TARGET_BACKEND: JVM_IR // WITH_RUNTIME @@ -15,4 +14,4 @@ fun box(): String { if (kClass != Foo::class) return "FAIL $kClass" if (jClass != Foo::class.java) return "FAIL $jClass" return "OK" -} \ No newline at end of file +} diff --git a/compiler/testData/codegen/box/annotations/instances/inInlineFunction.kt b/compiler/testData/codegen/box/annotations/instances/inInlineFunction.kt index 9e79f827daf..7c5a80a68e8 100644 --- a/compiler/testData/codegen/box/annotations/instances/inInlineFunction.kt +++ b/compiler/testData/codegen/box/annotations/instances/inInlineFunction.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // IGNORE_BACKEND: JVM // IGNORE_BACKEND: WASM // DONT_TARGET_EXACT_BACKEND: JS @@ -28,4 +27,4 @@ fun box(): String { assertEquals(A(1), one) assertEquals(A(2), two) return "OK" -} \ No newline at end of file +} diff --git a/compiler/testData/codegen/box/annotations/instances/javaAnnotation.kt b/compiler/testData/codegen/box/annotations/instances/javaAnnotation.kt index dcc61aa3262..aa784d7b177 100644 --- a/compiler/testData/codegen/box/annotations/instances/javaAnnotation.kt +++ b/compiler/testData/codegen/box/annotations/instances/javaAnnotation.kt @@ -1,3 +1,4 @@ +// Fir2IrLazyClass does not handle methods from java dependencies in declarations. // IGNORE_BACKEND_FIR: JVM_IR // TARGET_BACKEND: JVM_IR @@ -41,4 +42,4 @@ fun box(): String { // val d = D() val d = D("OK").value return d -} \ No newline at end of file +} diff --git a/compiler/testData/codegen/box/annotations/instances/kotlinExistingAnnotation.kt b/compiler/testData/codegen/box/annotations/instances/kotlinExistingAnnotation.kt index f75af1eaf8a..893c557df0e 100644 --- a/compiler/testData/codegen/box/annotations/instances/kotlinExistingAnnotation.kt +++ b/compiler/testData/codegen/box/annotations/instances/kotlinExistingAnnotation.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // TARGET_BACKEND: JVM_IR // WITH_RUNTIME @@ -20,4 +19,4 @@ fun box(): String { if (m.toString() == """@kotlin.Metadata(bytecodeVersion=[1, 0, 3], data1=[], data2=[], extraInt=0, extraString=, kind=0, metadataVersion=[], packageName=foo)""") return "OK" return m.toString() -} \ No newline at end of file +} diff --git a/compiler/testData/codegen/box/annotations/instances/multifileEqHc.kt b/compiler/testData/codegen/box/annotations/instances/multifileEqHc.kt index 65ac39af426..ad61b2acd36 100644 --- a/compiler/testData/codegen/box/annotations/instances/multifileEqHc.kt +++ b/compiler/testData/codegen/box/annotations/instances/multifileEqHc.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // IGNORE_BACKEND: JVM // IGNORE_BACKEND: WASM // DONT_TARGET_EXACT_BACKEND: JS @@ -27,4 +26,4 @@ fun box(): String { if (here().hashCode() != createInOtherFile().hashCode()) return "Fail hashCode" if (here().toString() != createInOtherFile().toString()) return "Fail toString" return "OK" -} \ No newline at end of file +} diff --git a/compiler/testData/codegen/box/annotations/instances/multimoduleInlining.kt b/compiler/testData/codegen/box/annotations/instances/multimoduleInlining.kt index 4500a8b9f01..5beb0100d6b 100644 --- a/compiler/testData/codegen/box/annotations/instances/multimoduleInlining.kt +++ b/compiler/testData/codegen/box/annotations/instances/multimoduleInlining.kt @@ -1,7 +1,9 @@ +// With FIR the annotation implementation class is not regenerated as it +// is seen as coming from the same module. +// See IrSourceCompilerForInline.kt:isCallInsideSameModuleAsCallee. // IGNORE_BACKEND_FIR: JVM_IR // TARGET_BACKEND: JVM_IR // IGNORE_DEXING - // WITH_RUNTIME // !LANGUAGE: +InstantiationOfAnnotationClasses @@ -39,4 +41,4 @@ fun box(): String { assert(one.javaClass.getEnclosingClass().getName() == "test.C") assert(two.javaClass.getEnclosingClass().getName() == "test.C") return "OK" -} \ No newline at end of file +} diff --git a/compiler/testData/codegen/box/annotations/instances/multiplatformInstantiation.kt b/compiler/testData/codegen/box/annotations/instances/multiplatformInstantiation.kt index 0aa0665c7e1..93a62e7cde8 100644 --- a/compiler/testData/codegen/box/annotations/instances/multiplatformInstantiation.kt +++ b/compiler/testData/codegen/box/annotations/instances/multiplatformInstantiation.kt @@ -1,3 +1,4 @@ +// Multi-platform not supported with FIR yet. // IGNORE_BACKEND_FIR: JVM_IR // IGNORE_BACKEND: JVM // IGNORE_BACKEND: WASM @@ -30,4 +31,4 @@ fun box(): String { if (createCommon().value != "OK") return "FAIL common" if (createPlatform().value != "OK") return "FAIL platform" return "OK" -} \ No newline at end of file +} diff --git a/compiler/testData/codegen/box/annotations/instances/nestedAnnotationInstances.kt b/compiler/testData/codegen/box/annotations/instances/nestedAnnotationInstances.kt index 256f57f6303..bf3873e9f44 100644 --- a/compiler/testData/codegen/box/annotations/instances/nestedAnnotationInstances.kt +++ b/compiler/testData/codegen/box/annotations/instances/nestedAnnotationInstances.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // IGNORE_BACKEND: JVM // IGNORE_BACKEND: WASM // DONT_TARGET_EXACT_BACKEND: JS diff --git a/compiler/testData/codegen/boxInline/annotations/annotationInstanceInlining.kt b/compiler/testData/codegen/boxInline/annotations/annotationInstanceInlining.kt index 1c7f28edce2..be62d4aecd4 100644 --- a/compiler/testData/codegen/boxInline/annotations/annotationInstanceInlining.kt +++ b/compiler/testData/codegen/boxInline/annotations/annotationInstanceInlining.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // IGNORE_BACKEND: JVM // IGNORE_BACKEND: WASM // IGNORE_BACKEND_MULTI_MODULE: JVM, JVM_MULTI_MODULE_IR_AGAINST_OLD @@ -39,4 +38,4 @@ fun box(): String { val two = two() assert(two.i == 2) return "OK" -} \ No newline at end of file +} diff --git a/compiler/testData/codegen/boxInline/annotations/instanceInAnonymousClass.kt b/compiler/testData/codegen/boxInline/annotations/instanceInAnonymousClass.kt index f05044fe870..8ba65f1b598 100644 --- a/compiler/testData/codegen/boxInline/annotations/instanceInAnonymousClass.kt +++ b/compiler/testData/codegen/boxInline/annotations/instanceInAnonymousClass.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // IGNORE_BACKEND: JVM // IGNORE_BACKEND: WASM // IGNORE_BACKEND_MULTI_MODULE: JVM, JVM_MULTI_MODULE_IR_AGAINST_OLD @@ -34,4 +33,4 @@ class C() { fun box(): String { return C().one().i -} \ No newline at end of file +} diff --git a/compiler/testData/diagnostics/tests/annotations/ConstructorCallAllowed.fir.kt b/compiler/testData/diagnostics/tests/annotations/ConstructorCallAllowed.fir.kt deleted file mode 100644 index 619c82e32d3..00000000000 --- a/compiler/testData/diagnostics/tests/annotations/ConstructorCallAllowed.fir.kt +++ /dev/null @@ -1,18 +0,0 @@ -// WITH_RUNTIME -// SKIP_TXT -// !LANGUAGE: +InstantiationOfAnnotationClasses - -import kotlin.reflect.KClass - -annotation class A -annotation class B(val int: Int) -annotation class C(val int: Int = 42) - -annotation class G(val int: KClass) - -fun box() { - val a = A() - val b = B(4) - val c = C() - val foo = G(Int::class) -} diff --git a/compiler/testData/diagnostics/tests/annotations/ConstructorCallAllowed.kt b/compiler/testData/diagnostics/tests/annotations/ConstructorCallAllowed.kt index d7ce8303e49..cdeda13fb49 100644 --- a/compiler/testData/diagnostics/tests/annotations/ConstructorCallAllowed.kt +++ b/compiler/testData/diagnostics/tests/annotations/ConstructorCallAllowed.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // WITH_RUNTIME // SKIP_TXT // !LANGUAGE: +InstantiationOfAnnotationClasses diff --git a/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorWrongClass.fir.kt b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorWrongClass.fir.kt index c8c05cc8aa8..b0e70e79bc1 100644 --- a/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorWrongClass.fir.kt +++ b/compiler/testData/diagnostics/tests/typealias/typeAliasConstructorWrongClass.fir.kt @@ -7,8 +7,8 @@ val test1a = AbstractClass() annotation class AnnotationClass typealias Test2 = AnnotationClass -val test2 = Test2() -val test2a = AnnotationClass() +val test2 = Test2() +val test2a = AnnotationClass() enum class EnumClass { VALUE1, VALUE2 } typealias Test3 = EnumClass diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameterMustBeConstant/array.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameterMustBeConstant/array.fir.kt index 4f798a8a512..e97514f7769 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameterMustBeConstant/array.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameterMustBeConstant/array.fir.kt @@ -21,4 +21,4 @@ annotation class AnnAnn(val i: Array) @AnnAnn(arrayOf(Ann(intArrayOf(1)))) @AnnAnn(arrayOf(iAnn)) class TestAnn -val iAnn = Ann(intArrayOf(1)) +val iAnn = Ann(intArrayOf(1)) diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameterMustBeConstant/vararg.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameterMustBeConstant/vararg.fir.kt deleted file mode 100644 index 3d3670e3826..00000000000 --- a/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameterMustBeConstant/vararg.fir.kt +++ /dev/null @@ -1,27 +0,0 @@ -@Retention(AnnotationRetention.SOURCE) -@Repeatable -annotation class Ann(vararg val i: Int) - -@Ann(i) -@Ann(i2) -@Ann(i3) -@Ann(i, i2, i3) -@Ann(*intArrayOf(i)) -@Ann(*intArrayOf(i2)) -@Ann(*intArrayOf(i3)) -@Ann(*intArrayOf(i, i2, i3)) -class Test - -var i = 1 -const val i2 = 1 -val i3 = foo() - -fun foo(): Int = 1 - -@Retention(AnnotationRetention.SOURCE) -@Repeatable -annotation class AnnAnn(vararg val i: Ann) -@AnnAnn(*arrayOf(Ann(1))) -@AnnAnn(*arrayOf(iAnn)) -class TestAnn -val iAnn = Ann(1) diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameterMustBeConstant/vararg.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameterMustBeConstant/vararg.kt index ac380240bc3..009bdc60086 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameterMustBeConstant/vararg.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationParameterMustBeConstant/vararg.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL @Retention(AnnotationRetention.SOURCE) @Repeatable annotation class Ann(vararg val i: Int)