From 850d76f6bf200cb3e0f70af8e92997bbe66ab3a6 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Thu, 11 Nov 2021 18:10:20 +0100 Subject: [PATCH] Remove error on annotated types as arguments to typeOf Instead, document that `KType.annotations` returns an empty list for types created with `typeOf`. Annotations might be supported in the future. #KT-49573 Fixed #KT-29919 --- .../inline/PsiInlineIntrinsicsSupport.kt | 13 +--- .../codegen/inline/ReifiedTypeInliner.kt | 1 - .../jetbrains/kotlin/codegen/inline/typeOf.kt | 2 - .../FirBlackBoxCodegenTestGenerated.java | 12 ++++ .../diagnostics/DefaultErrorMessagesJvm.java | 4 +- .../resolve/jvm/diagnostics/ErrorsJvm.java | 2 - .../jvm/diagnostics/JvmBackendErrors.kt | 4 -- .../jvm/codegen/IrInlineIntrinsicsSupport.kt | 22 +------ .../box/reflection/typeOf/annotatedType.kt | 61 +++++++++++++++++++ .../typeOf/noReflect/annotatedType.kt | 61 +++++++++++++++++++ .../typeOf/annotatedType.kt | 58 ------------------ .../typeOf/annotatedType.txt | 28 --------- .../testsWithJvmBackend/typeOf/suspendType.kt | 3 + ...gnosticsTestWithJvmIrBackendGenerated.java | 6 -- .../codegen/BlackBoxCodegenTestGenerated.java | 12 ++++ .../IrBlackBoxCodegenTestGenerated.java | 12 ++++ .../LightAnalysisModeTestGenerated.java | 10 +++ libraries/stdlib/src/kotlin/reflect/typeOf.kt | 3 + 18 files changed, 180 insertions(+), 134 deletions(-) create mode 100644 compiler/testData/codegen/box/reflection/typeOf/annotatedType.kt create mode 100644 compiler/testData/codegen/box/reflection/typeOf/noReflect/annotatedType.kt delete mode 100644 compiler/testData/diagnostics/testsWithJvmBackend/typeOf/annotatedType.kt delete mode 100644 compiler/testData/diagnostics/testsWithJvmBackend/typeOf/annotatedType.txt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/PsiInlineIntrinsicsSupport.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/PsiInlineIntrinsicsSupport.kt index 1cd0dbaab50..fa4622ebb5a 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/PsiInlineIntrinsicsSupport.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/PsiInlineIntrinsicsSupport.kt @@ -5,7 +5,6 @@ package org.jetbrains.kotlin.codegen.inline -import org.jetbrains.kotlin.builtins.StandardNames import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMap import org.jetbrains.kotlin.codegen.* import org.jetbrains.kotlin.codegen.state.GenerationState @@ -13,12 +12,12 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.descriptors.PropertyDescriptor import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor -import org.jetbrains.kotlin.load.java.JvmAnnotationNames import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.KtElement import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe import org.jetbrains.kotlin.resolve.jvm.AsmTypes.* -import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm.* +import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm.TYPEOF_NON_REIFIED_TYPE_PARAMETER_WITH_RECURSIVE_BOUND +import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm.TYPEOF_SUSPEND_TYPE import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.model.TypeParameterMarker import org.jetbrains.org.objectweb.asm.Type @@ -73,14 +72,6 @@ class PsiInlineIntrinsicsSupport( override fun toKotlinType(type: KotlinType): KotlinType = type - override fun checkAnnotatedType(type: KotlinType) { - if (type.annotations.hasAnnotation(StandardNames.FqNames.extensionFunctionType)) { - state.diagnostics.report(TYPEOF_EXTENSION_FUNCTION_TYPE.on(reportErrorsOn)) - } else if (type.annotations.any { it.fqName != JvmAnnotationNames.ENHANCED_NULLABILITY_ANNOTATION }) { - state.diagnostics.report(TYPEOF_ANNOTATED_TYPE.on(reportErrorsOn)) - } - } - override fun reportSuspendTypeUnsupported() { state.diagnostics.report(TYPEOF_SUSPEND_TYPE.on(reportErrorsOn)) } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/ReifiedTypeInliner.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/ReifiedTypeInliner.kt index 13f7613fdce..7c3f5c0491a 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/ReifiedTypeInliner.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/ReifiedTypeInliner.kt @@ -73,7 +73,6 @@ class ReifiedTypeInliner( fun toKotlinType(type: KT): KotlinType - fun checkAnnotatedType(type: KT) fun reportSuspendTypeUnsupported() fun reportNonReifiedTypeParameterWithRecursiveBoundUnsupported(typeParameterName: Name) } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/typeOf.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/typeOf.kt index d7dfdd6f65a..47ffb6e100f 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/typeOf.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/typeOf.kt @@ -95,8 +95,6 @@ fun TypeSystemCommonBackendContext.generateTypeOf( intrinsicsSupport.reportSuspendTypeUnsupported() } - intrinsicsSupport.checkAnnotatedType(type) - if (intrinsicsSupport.state.stableTypeOf) { if (intrinsicsSupport.isMutableCollectionType(type)) { v.invokestatic(REFLECTION, "mutableCollectionType", Type.getMethodDescriptor(K_TYPE, K_TYPE), false) diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java index e26c4520346..86f37e5f180 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java @@ -38917,6 +38917,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/reflection/typeOf"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); } + @Test + @TestMetadata("annotatedType.kt") + public void testAnnotatedType() throws Exception { + runTest("compiler/testData/codegen/box/reflection/typeOf/annotatedType.kt"); + } + @Test @TestMetadata("classes.kt") public void testClasses() throws Exception { @@ -39026,6 +39032,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/reflection/typeOf/noReflect"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); } + @Test + @TestMetadata("annotatedType.kt") + public void testAnnotatedType() throws Exception { + runTest("compiler/testData/codegen/box/reflection/typeOf/noReflect/annotatedType.kt"); + } + @Test @TestMetadata("classes.kt") public void testClasses() throws Exception { diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/diagnostics/DefaultErrorMessagesJvm.java b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/diagnostics/DefaultErrorMessagesJvm.java index aa99cd6fbfb..846a2c8cb98 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/diagnostics/DefaultErrorMessagesJvm.java +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/diagnostics/DefaultErrorMessagesJvm.java @@ -14,8 +14,8 @@ import org.jetbrains.kotlin.utils.StringsKt; import java.util.List; import static kotlin.collections.CollectionsKt.*; +import static org.jetbrains.kotlin.diagnostics.rendering.CommonRenderers.STRING; import static org.jetbrains.kotlin.diagnostics.rendering.Renderers.*; -import static org.jetbrains.kotlin.diagnostics.rendering.CommonRenderers.*; import static org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm.*; public class DefaultErrorMessagesJvm implements DefaultErrorMessages.Extension { @@ -221,8 +221,6 @@ public class DefaultErrorMessagesJvm implements DefaultErrorMessages.Extension { MAP.put(SYNCHRONIZED_ON_SUSPEND, "@Synchronized annotation is not applicable to suspend functions and lambdas"); MAP.put(TYPEOF_SUSPEND_TYPE, "Suspend functional types are not supported in typeOf"); - MAP.put(TYPEOF_EXTENSION_FUNCTION_TYPE, "Extension function types are not supported in typeOf"); - MAP.put(TYPEOF_ANNOTATED_TYPE, "Annotated types are not supported in typeOf"); MAP.put(TYPEOF_NON_REIFIED_TYPE_PARAMETER_WITH_RECURSIVE_BOUND, "Non-reified type parameters with recursive bounds are not supported yet: {0}", STRING); } diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/diagnostics/ErrorsJvm.java b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/diagnostics/ErrorsJvm.java index 35748778626..f59f649ef39 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/diagnostics/ErrorsJvm.java +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/diagnostics/ErrorsJvm.java @@ -185,8 +185,6 @@ public interface ErrorsJvm { DiagnosticFactory0 JVM_INLINE_WITHOUT_VALUE_CLASS = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 TYPEOF_SUSPEND_TYPE = DiagnosticFactory0.create(ERROR); - DiagnosticFactory0 TYPEOF_EXTENSION_FUNCTION_TYPE = DiagnosticFactory0.create(ERROR); - DiagnosticFactory0 TYPEOF_ANNOTATED_TYPE = DiagnosticFactory0.create(ERROR); DiagnosticFactory1 TYPEOF_NON_REIFIED_TYPE_PARAMETER_WITH_RECURSIVE_BOUND = DiagnosticFactory1.create(ERROR); @SuppressWarnings("UnusedDeclaration") diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/diagnostics/JvmBackendErrors.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/diagnostics/JvmBackendErrors.kt index 6a53e553457..47b282f8f34 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/diagnostics/JvmBackendErrors.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/diagnostics/JvmBackendErrors.kt @@ -23,8 +23,6 @@ object JvmBackendErrors { val ACCIDENTAL_OVERRIDE by error1(DECLARATION_SIGNATURE_OR_DEFAULT) val TYPEOF_SUSPEND_TYPE by error0() - val TYPEOF_EXTENSION_FUNCTION_TYPE by error0() - val TYPEOF_ANNOTATED_TYPE by error0() val TYPEOF_NON_REIFIED_TYPE_PARAMETER_WITH_RECURSIVE_BOUND by error1() val SUSPENSION_POINT_INSIDE_MONITOR by error1() @@ -60,8 +58,6 @@ object KtDefaultJvmErrorMessages : BaseDiagnosticRendererFactory() { map.put(JvmBackendErrors.ACCIDENTAL_OVERRIDE, "Accidental override: {0}", CONFLICTING_JVM_DECLARATIONS_DATA) map.put(JvmBackendErrors.CONFLICTING_INHERITED_JVM_DECLARATIONS, "Inherited platform declarations clash: {0}", CONFLICTING_JVM_DECLARATIONS_DATA) map.put(JvmBackendErrors.TYPEOF_SUSPEND_TYPE, "Suspend functional types are not supported in typeOf") - map.put(JvmBackendErrors.TYPEOF_EXTENSION_FUNCTION_TYPE, "Extension function types are not supported in typeOf") - map.put(JvmBackendErrors.TYPEOF_ANNOTATED_TYPE, "Annotated types are not supported in typeOf") map.put(JvmBackendErrors.TYPEOF_NON_REIFIED_TYPE_PARAMETER_WITH_RECURSIVE_BOUND, "Non-reified type parameters with recursive bounds are not supported yet: {0}", STRING) map.put(JvmBackendErrors.SUSPENSION_POINT_INSIDE_MONITOR, "A suspension point at {0} is inside a critical section", STRING) } diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/IrInlineIntrinsicsSupport.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/IrInlineIntrinsicsSupport.kt index 381c91ffc0e..fb114eb430c 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/IrInlineIntrinsicsSupport.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/IrInlineIntrinsicsSupport.kt @@ -7,11 +7,9 @@ package org.jetbrains.kotlin.backend.jvm.codegen import org.jetbrains.kotlin.backend.common.ir.allParametersCount import org.jetbrains.kotlin.backend.jvm.JvmBackendContext -import org.jetbrains.kotlin.backend.jvm.JvmSymbols import org.jetbrains.kotlin.backend.jvm.intrinsics.SignatureString import org.jetbrains.kotlin.backend.jvm.ir.getCallableReferenceOwnerKClassType import org.jetbrains.kotlin.backend.jvm.ir.getCallableReferenceTopLevelFlag -import org.jetbrains.kotlin.builtins.StandardNames import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMap import org.jetbrains.kotlin.codegen.AsmUtil import org.jetbrains.kotlin.codegen.inline.ReifiedTypeInliner @@ -22,8 +20,9 @@ import org.jetbrains.kotlin.ir.expressions.IrExpression import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol import org.jetbrains.kotlin.ir.types.IrType import org.jetbrains.kotlin.ir.types.classOrNull -import org.jetbrains.kotlin.ir.util.* -import org.jetbrains.kotlin.load.java.JvmAnnotationNames +import org.jetbrains.kotlin.ir.util.defaultType +import org.jetbrains.kotlin.ir.util.fqNameWhenAvailable +import org.jetbrains.kotlin.ir.util.render import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.jvm.AsmTypes.* import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmBackendErrors @@ -115,21 +114,6 @@ class IrInlineIntrinsicsSupport( override fun toKotlinType(type: IrType): KotlinType = type.toIrBasedKotlinType() - override fun checkAnnotatedType(type: IrType) { - if (type.hasAnnotation(StandardNames.FqNames.extensionFunctionType)) { - context.ktDiagnosticReporter.at(reportErrorsOn, containingFile).report(JvmBackendErrors.TYPEOF_EXTENSION_FUNCTION_TYPE) - } else if (type.annotations.any { !it.symbol.owner.constructedClass.isSpecialAnnotation() }) { - context.ktDiagnosticReporter.at(reportErrorsOn, containingFile).report(JvmBackendErrors.TYPEOF_ANNOTATED_TYPE) - } - } - - // TODO: consider inventing a safer way to do this - private fun IrClass.isSpecialAnnotation(): Boolean = - hasEqualFqName(JvmAnnotationNames.ENHANCED_NULLABILITY_ANNOTATION) || - hasEqualFqName(JvmSymbols.FLEXIBLE_NULLABILITY_ANNOTATION_FQ_NAME) || - hasEqualFqName(JvmSymbols.FLEXIBLE_MUTABILITY_ANNOTATION_FQ_NAME) || - hasEqualFqName(JvmSymbols.RAW_TYPE_ANNOTATION_FQ_NAME) - override fun reportSuspendTypeUnsupported() { context.ktDiagnosticReporter.at(reportErrorsOn, containingFile).report(JvmBackendErrors.TYPEOF_SUSPEND_TYPE) } diff --git a/compiler/testData/codegen/box/reflection/typeOf/annotatedType.kt b/compiler/testData/codegen/box/reflection/typeOf/annotatedType.kt new file mode 100644 index 00000000000..998f036c515 --- /dev/null +++ b/compiler/testData/codegen/box/reflection/typeOf/annotatedType.kt @@ -0,0 +1,61 @@ +// TARGET_BACKEND: JVM +// WITH_REFLECT + +import kotlin.reflect.* + +@Target(AnnotationTarget.TYPE) +@Retention(AnnotationRetention.RUNTIME) +annotation class Runtime + +@Target(AnnotationTarget.TYPE) +@Retention(AnnotationRetention.BINARY) +annotation class Binary + +@Target(AnnotationTarget.TYPE) +@Retention(AnnotationRetention.SOURCE) +annotation class Source + +inline fun f() = g>() +inline fun g() = typeOf() + +inline fun a() = typeOf<@Runtime Z>() + +inline fun test() { + check(typeOf<@Runtime R.() -> Unit>()) + check(typeOf Unit>()) +} + +fun check(type: KType) { + if (type.annotations.isNotEmpty()) { + error("KType.annotations should be empty: ${type.annotations}") + } +} + +fun box(): String { + check(typeOf Int>()) + check(f Unit>()) + + check(typeOf<@Runtime Int.() -> List>()) + check(f<@Runtime Unit.() -> Array<*>>()) + + check(typeOf<@Runtime String>()) + check(f<@Runtime String>()) + check(typeOf<@Binary String>()) + check(f<@Binary String>()) + check(typeOf<@Source String>()) + check(f<@Source String>()) + + @Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") + check(typeOf<@kotlin.internal.Exact String>()) + @Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") + check(f<@kotlin.internal.Exact String>()) + + check(typeOf>>()) + check(f>>()) + + check(a()) + + test() + + return "OK" +} diff --git a/compiler/testData/codegen/box/reflection/typeOf/noReflect/annotatedType.kt b/compiler/testData/codegen/box/reflection/typeOf/noReflect/annotatedType.kt new file mode 100644 index 00000000000..50c58a0ad92 --- /dev/null +++ b/compiler/testData/codegen/box/reflection/typeOf/noReflect/annotatedType.kt @@ -0,0 +1,61 @@ +// TARGET_BACKEND: JVM +// WITH_RUNTIME + +import kotlin.reflect.* + +@Target(AnnotationTarget.TYPE) +@Retention(AnnotationRetention.RUNTIME) +annotation class Runtime + +@Target(AnnotationTarget.TYPE) +@Retention(AnnotationRetention.BINARY) +annotation class Binary + +@Target(AnnotationTarget.TYPE) +@Retention(AnnotationRetention.SOURCE) +annotation class Source + +inline fun f() = g>() +inline fun g() = typeOf() + +inline fun a() = typeOf<@Runtime Z>() + +inline fun test() { + check(typeOf<@Runtime R.() -> Unit>()) + check(typeOf Unit>()) +} + +fun check(type: KType) { + if (type.annotations.isNotEmpty()) { + error("KType.annotations should be empty: ${type.annotations}") + } +} + +fun box(): String { + check(typeOf Int>()) + check(f Unit>()) + + check(typeOf<@Runtime Int.() -> List>()) + check(f<@Runtime Unit.() -> Array<*>>()) + + check(typeOf<@Runtime String>()) + check(f<@Runtime String>()) + check(typeOf<@Binary String>()) + check(f<@Binary String>()) + check(typeOf<@Source String>()) + check(f<@Source String>()) + + @Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") + check(typeOf<@kotlin.internal.Exact String>()) + @Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") + check(f<@kotlin.internal.Exact String>()) + + check(typeOf>>()) + check(f>>()) + + check(a()) + + test() + + return "OK" +} diff --git a/compiler/testData/diagnostics/testsWithJvmBackend/typeOf/annotatedType.kt b/compiler/testData/diagnostics/testsWithJvmBackend/typeOf/annotatedType.kt deleted file mode 100644 index 94b1ad8d792..00000000000 --- a/compiler/testData/diagnostics/testsWithJvmBackend/typeOf/annotatedType.kt +++ /dev/null @@ -1,58 +0,0 @@ -// WITH_RUNTIME -// USE_EXPERIMENTAL: kotlin.ExperimentalStdlibApi -// TARGET_BACKEND: JVM_IR - -import kotlin.reflect.* - -inline fun f() = g>() -inline fun g() = typeOf() - -inline fun a() = typeOf<@Runtime Z>() - -@Target(AnnotationTarget.TYPE) -@Retention(AnnotationRetention.RUNTIME) -annotation class Runtime - -@Target(AnnotationTarget.TYPE) -@Retention(AnnotationRetention.BINARY) -annotation class Binary - -@Target(AnnotationTarget.TYPE) -@Retention(AnnotationRetention.SOURCE) -annotation class Source - -fun test() { - typeOf Int>() - f Unit>() - - typeOf List>() - f Array<*>>() - - typeOf<@Runtime Int.() -> List>() - f<@Runtime Unit.() -> Array<*>>() - - typeOf<@Runtime String>() - f<@Runtime String>() - typeOf<@Binary String>() - f<@Binary String>() - typeOf<@Source String>() - f<@Source String>() - - @Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") - typeOf<@kotlin.internal.Exact String>() - @Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") - f<@kotlin.internal.Exact String>() - - typeOf>>() - f>>() - - // TODO: https://youtrack.jetbrains.com/issue/KT-29919#focus=Comments-27-5065356.0-0 - a() - - test2() -} - -inline fun test2() { - typeOf<@Runtime R.()->Unit>() - typeOfUnit>() -} diff --git a/compiler/testData/diagnostics/testsWithJvmBackend/typeOf/annotatedType.txt b/compiler/testData/diagnostics/testsWithJvmBackend/typeOf/annotatedType.txt deleted file mode 100644 index 5cfd39ae8df..00000000000 --- a/compiler/testData/diagnostics/testsWithJvmBackend/typeOf/annotatedType.txt +++ /dev/null @@ -1,28 +0,0 @@ -package - -public inline fun a(): kotlin.reflect.KType -public inline fun f(): kotlin.reflect.KType -public inline fun g(): kotlin.reflect.KType -public fun test(): kotlin.Unit -public inline fun test2(): kotlin.Unit - -@kotlin.annotation.Target(allowedTargets = {AnnotationTarget.TYPE}) @kotlin.annotation.Retention(value = AnnotationRetention.BINARY) public final annotation class Binary : kotlin.Annotation { - public constructor Binary() - public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean - public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int - public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String -} - -@kotlin.annotation.Target(allowedTargets = {AnnotationTarget.TYPE}) @kotlin.annotation.Retention(value = AnnotationRetention.RUNTIME) public final annotation class Runtime : kotlin.Annotation { - public constructor Runtime() - public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean - public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int - public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String -} - -@kotlin.annotation.Target(allowedTargets = {AnnotationTarget.TYPE}) @kotlin.annotation.Retention(value = AnnotationRetention.SOURCE) public final annotation class Source : kotlin.Annotation { - public constructor Source() - public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean - public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int - public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String -} diff --git a/compiler/testData/diagnostics/testsWithJvmBackend/typeOf/suspendType.kt b/compiler/testData/diagnostics/testsWithJvmBackend/typeOf/suspendType.kt index 234443f86fc..60bafaf2874 100644 --- a/compiler/testData/diagnostics/testsWithJvmBackend/typeOf/suspendType.kt +++ b/compiler/testData/diagnostics/testsWithJvmBackend/typeOf/suspendType.kt @@ -9,4 +9,7 @@ inline fun g() = typeOf() fun test() { typeOf Int>() f Unit>() + + typeOf List>() + f Array<*>>() } diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticsTestWithJvmIrBackendGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticsTestWithJvmIrBackendGenerated.java index 6112b33c7f1..77f23fc3e38 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticsTestWithJvmIrBackendGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticsTestWithJvmIrBackendGenerated.java @@ -672,12 +672,6 @@ public class DiagnosticsTestWithJvmIrBackendGenerated extends AbstractDiagnostic KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithJvmBackend/typeOf"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); } - @Test - @TestMetadata("annotatedType.kt") - public void testAnnotatedType() throws Exception { - runTest("compiler/testData/diagnostics/testsWithJvmBackend/typeOf/annotatedType.kt"); - } - @Test @TestMetadata("nonReifiedTypeParameterWithRecursiveBound.kt") public void testNonReifiedTypeParameterWithRecursiveBound() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java index fb6832d5002..92fc7dc3dc4 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java @@ -38725,6 +38725,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/reflection/typeOf"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); } + @Test + @TestMetadata("annotatedType.kt") + public void testAnnotatedType() throws Exception { + runTest("compiler/testData/codegen/box/reflection/typeOf/annotatedType.kt"); + } + @Test @TestMetadata("classes.kt") public void testClasses() throws Exception { @@ -38834,6 +38840,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/reflection/typeOf/noReflect"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); } + @Test + @TestMetadata("annotatedType.kt") + public void testAnnotatedType() throws Exception { + runTest("compiler/testData/codegen/box/reflection/typeOf/noReflect/annotatedType.kt"); + } + @Test @TestMetadata("classes.kt") public void testClasses() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index 4dc59b89b97..4206cc3fa8e 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java @@ -38917,6 +38917,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/reflection/typeOf"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); } + @Test + @TestMetadata("annotatedType.kt") + public void testAnnotatedType() throws Exception { + runTest("compiler/testData/codegen/box/reflection/typeOf/annotatedType.kt"); + } + @Test @TestMetadata("classes.kt") public void testClasses() throws Exception { @@ -39026,6 +39032,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/reflection/typeOf/noReflect"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); } + @Test + @TestMetadata("annotatedType.kt") + public void testAnnotatedType() throws Exception { + runTest("compiler/testData/codegen/box/reflection/typeOf/noReflect/annotatedType.kt"); + } + @Test @TestMetadata("classes.kt") public void testClasses() throws Exception { diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index eeb2311ab1f..0e516b954e9 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -30925,6 +30925,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/reflection/typeOf"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); } + @TestMetadata("annotatedType.kt") + public void testAnnotatedType() throws Exception { + runTest("compiler/testData/codegen/box/reflection/typeOf/annotatedType.kt"); + } + @TestMetadata("classes.kt") public void testClasses() throws Exception { runTest("compiler/testData/codegen/box/reflection/typeOf/classes.kt"); @@ -31025,6 +31030,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/reflection/typeOf/noReflect"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); } + @TestMetadata("annotatedType.kt") + public void testAnnotatedType() throws Exception { + runTest("compiler/testData/codegen/box/reflection/typeOf/noReflect/annotatedType.kt"); + } + @TestMetadata("classes.kt") public void testClasses() throws Exception { runTest("compiler/testData/codegen/box/reflection/typeOf/noReflect/classes.kt"); diff --git a/libraries/stdlib/src/kotlin/reflect/typeOf.kt b/libraries/stdlib/src/kotlin/reflect/typeOf.kt index dece8790522..13f93fc771a 100644 --- a/libraries/stdlib/src/kotlin/reflect/typeOf.kt +++ b/libraries/stdlib/src/kotlin/reflect/typeOf.kt @@ -7,6 +7,9 @@ package kotlin.reflect /** * Returns a runtime representation of the given reified type [T] as an instance of [KType]. + * + * Note that on JVM, the created type has no annotations ([KType.annotations] returns an empty list) + * even if the type in the source code is annotated. Support for type annotations might be added in a future version. */ @SinceKotlin("1.6") @WasExperimental(ExperimentalStdlibApi::class)