Kotlin / dokka

API documentation engine for Kotlin
https://kotl.in/dokka
Apache License 2.0
3.45k stars 412 forks source link

Dokka fails with not array: KClass<out Annotation> on Kotlin 2.1.20-dev with @SubclassOptInRequired #3851

Closed sandwwraith closed 1 month ago

sandwwraith commented 1 month ago

Describe the bug

* What went wrong:
Execution failed for task ':kotlinx-serialization-cbor:dokkaHtmlPartial'.
> not array: KClass<out Annotation>

* Try:
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':kotlinx-serialization-cbor:dokkaHtmlPartial'.
... 
Caused by: java.lang.IllegalStateException: not array: KClass<out Annotation>
        at org.jetbrains.kotlin.builtins.KotlinBuiltIns.getArrayElementType(KotlinBuiltIns.java:602)
        at org.jetbrains.kotlin.serialization.deserialization.AnnotationDeserializer.doesValueConformToExpectedType(AnnotationDeserializer.kt:111)
        at org.jetbrains.kotlin.serialization.deserialization.AnnotationDeserializer.resolveValueAndCheckExpectedType(AnnotationDeserializer.kt:66)
        at org.jetbrains.kotlin.serialization.deserialization.AnnotationDeserializer.resolveArgument(AnnotationDeserializer.kt:61)
        at org.jetbrains.kotlin.serialization.deserialization.AnnotationDeserializer.deserializeAnnotation(AnnotationDeserializer.kt:48)
        at org.jetbrains.kotlin.serialization.deserialization.AnnotationAndConstantLoaderImpl.loadAnnotation(AnnotationAndConstantLoaderImpl.kt:38)
        at org.jetbrains.kotlin.serialization.deserialization.AnnotationAndConstantLoaderImpl.loadAnnotation(AnnotationAndConstantLoaderImpl.kt:29)
        at org.jetbrains.kotlin.serialization.deserialization.AbstractAnnotationLoader.loadClassAnnotations(AbstractAnnotationLoader.kt:18)
        at org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedClassDescriptor.annotations$lambda$5(DeserializedClassDescriptor.kt:98)
        at org.jetbrains.kotlin.storage.LockBasedStorageManager$LockBasedLazyValue.invoke(LockBasedStorageManager.java:408)
        at org.jetbrains.kotlin.storage.LockBasedStorageManager$LockBasedNotNullLazyValue.invoke(LockBasedStorageManager.java:527)
        at org.jetbrains.kotlin.storage.StorageKt.getValue(storage.kt:42)
        at org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedAnnotations.getAnnotations(DeserializedAnnotations.kt:28)
        at org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedAnnotations.iterator(DeserializedAnnotations.kt:32)
        at org.jetbrains.kotlin.descriptors.annotations.Annotations$DefaultImpls.findAnnotation(Annotations.kt:124)
        at org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedAnnotations.findAnnotation(DeserializedAnnotations.kt:24)
        at org.jetbrains.kotlin.resolve.SinceKotlinUtilKt.getOwnSinceKotlinVersion$consider(sinceKotlinUtil.kt:75)
        at org.jetbrains.kotlin.resolve.SinceKotlinUtilKt.getOwnSinceKotlinVersion(sinceKotlinUtil.kt:85)
        at org.jetbrains.kotlin.resolve.SinceKotlinUtilKt.checkSinceKotlinVersionAccessibility(sinceKotlinUtil.kt:34)
        at org.jetbrains.kotlin.resolve.deprecation.DeprecationResolver.isHiddenBecauseOfKotlinVersionAccessibility$lambda$3(DeprecationResolver.kt:117)
        at org.jetbrains.kotlin.storage.LockBasedStorageManager$MapBasedMemoizedFunction.invoke(LockBasedStorageManager.java:578)
        at org.jetbrains.kotlin.storage.LockBasedStorageManager$MapBasedMemoizedFunctionToNotNull.invoke(LockBasedStorageManager.java:681)
        at org.jetbrains.kotlin.resolve.deprecation.DeprecationResolver.isHiddenInResolution(DeprecationResolver.kt:159)
        at org.jetbrains.kotlin.resolve.deprecation.DeprecationResolver.isHiddenInResolution(DeprecationResolver.kt:145)
        at org.jetbrains.kotlin.resolve.deprecation.DeprecationResolver.isHiddenInResolution$default(DeprecationResolver.kt:137)
        at org.jetbrains.kotlin.resolve.lazy.LazyImportScope.isClassifierVisible(LazyImportScope.kt:253)
        at org.jetbrains.kotlin.resolve.lazy.LazyImportScope.getClassifier$lambda$0(LazyImportScope.kt:280)
        at org.jetbrains.kotlin.storage.LockBasedStorageManager.compute(LockBasedStorageManager.java:290)
        at org.jetbrains.kotlin.resolve.lazy.LazyImportScope.getClassifier(LazyImportScope.kt:274)
        at org.jetbrains.kotlin.resolve.lazy.LazyImportScope.getContributedClassifier(LazyImportScope.kt:270)
        at org.jetbrains.kotlin.resolve.scopes.ResolutionScope$DefaultImpls.getContributedClassifierIncludeDeprecated(ResolutionScope.kt:40)
        at org.jetbrains.kotlin.resolve.scopes.HierarchicalScope$DefaultImpls.getContributedClassifierIncludeDeprecated(Scopes.kt:27)
        at org.jetbrains.kotlin.resolve.scopes.ImportingScope$DefaultImpls.getContributedClassifierIncludeDeprecated(Scopes.kt:113)
        at org.jetbrains.kotlin.resolve.lazy.LazyImportScope.getContributedClassifierIncludeDeprecated(LazyImportScope.kt:235)
        at org.jetbrains.kotlin.resolve.scopes.utils.ScopeUtilsKt.findFirstClassifierWithDeprecationStatus(ScopeUtils.kt:119)
        at org.jetbrains.kotlin.resolve.QualifiedExpressionResolver.findClassifierAndReportDeprecationIfNeeded(QualifiedExpressionResolver.kt:71)
        at org.jetbrains.kotlin.resolve.QualifiedExpressionResolver.resolveDescriptorForType(QualifiedExpressionResolver.kt:95)
        at org.jetbrains.kotlin.resolve.TypeResolver.resolveDescriptorForType(TypeResolver.kt:1053)
        at org.jetbrains.kotlin.resolve.TypeResolver$resolveTypeElement$1.visitUserType(TypeResolver.kt:259)
        at org.jetbrains.kotlin.psi.KtVisitorVoid.visitUserType(KtVisitorVoid.java:937)
        at org.jetbrains.kotlin.psi.KtVisitorVoid.visitUserType(KtVisitorVoid.java:21)
        at org.jetbrains.kotlin.psi.KtUserType.accept(KtUserType.java:42)
        at org.jetbrains.kotlin.psi.KtElementImplStub.accept(KtElementImplStub.java:49)
        at org.jetbrains.kotlin.resolve.TypeResolver.resolveTypeElement(TypeResolver.kt:257)
        at org.jetbrains.kotlin.resolve.TypeResolver.resolvePossiblyBareType(TypeResolver.kt:136)
        at org.jetbrains.kotlin.resolve.TypeResolver.resolveType(TypeResolver.kt:126)
        at org.jetbrains.kotlin.resolve.TypeResolver.resolveType(TypeResolver.kt:97)
        at org.jetbrains.kotlin.resolve.FunctionDescriptorResolver.initializeFunctionDescriptorAndExplicitReturnType(FunctionDescriptorResolver.kt:197)
        at org.jetbrains.kotlin.resolve.FunctionDescriptorResolver.resolveFunctionDescriptor(FunctionDescriptorResolver.kt:132)
        at org.jetbrains.kotlin.resolve.FunctionDescriptorResolver.resolveFunctionDescriptor(FunctionDescriptorResolver.kt:96)
        at org.jetbrains.kotlin.resolve.lazy.descriptors.AbstractLazyMemberScope.getDeclaredFunctions(AbstractLazyMemberScope.kt:120)
        at org.jetbrains.kotlin.resolve.lazy.descriptors.AbstractLazyMemberScope.declaredFunctionDescriptors$lambda$5(AbstractLazyMemberScope.kt:58)
        at org.jetbrains.kotlin.storage.LockBasedStorageManager$MapBasedMemoizedFunction.invoke(LockBasedStorageManager.java:578)
        at org.jetbrains.kotlin.storage.LockBasedStorageManager$MapBasedMemoizedFunctionToNotNull.invoke(LockBasedStorageManager.java:681)
        at org.jetbrains.kotlin.resolve.lazy.descriptors.AbstractLazyMemberScope.doGetFunctions(AbstractLazyMemberScope.kt:101)
        at org.jetbrains.kotlin.resolve.lazy.descriptors.AbstractLazyMemberScope.functionDescriptors$lambda$1(AbstractLazyMemberScope.kt:51)
        at org.jetbrains.kotlin.storage.LockBasedStorageManager$MapBasedMemoizedFunction.invoke(LockBasedStorageManager.java:578)
        at org.jetbrains.kotlin.storage.LockBasedStorageManager$MapBasedMemoizedFunctionToNotNull.invoke(LockBasedStorageManager.java:681)
        at org.jetbrains.kotlin.resolve.lazy.descriptors.AbstractLazyMemberScope.getContributedFunctions(AbstractLazyMemberScope.kt:97)
        at org.jetbrains.kotlin.resolve.lazy.descriptors.AbstractLazyMemberScope.computeDescriptorsFromDeclaredElements(AbstractLazyMemberScope.kt:242)
        at org.jetbrains.kotlin.resolve.lazy.descriptors.LazyPackageMemberScope.getContributedDescriptors(LazyPackageMemberScope.kt:44)
        at org.jetbrains.kotlin.resolve.scopes.ResolutionScope$DefaultImpls.getContributedDescriptors$default(ResolutionScope.kt:50)
        at org.jetbrains.dokka.analysis.kotlin.descriptors.compiler.translator.DokkaDescriptorVisitor.getDescriptorsWithKind(DefaultDescriptorToDocumentableTranslator.kt:893)
        at org.jetbrains.dokka.analysis.kotlin.descriptors.compiler.translator.DokkaDescriptorVisitor.access$getDescriptorsWithKind(DefaultDescriptorToDocumentableTranslator.kt:159)
        at org.jetbrains.dokka.analysis.kotlin.descriptors.compiler.translator.DokkaDescriptorVisitor$visitPackageFragmentDescriptor$2.invokeSuspend(DefaultDescriptorToDocumentableTranslator.kt:189)

To Reproduce Failed build: https://teamcity.jetbrains.com/buildConfiguration/KotlinTools_KotlinxSerialization_SandboxSerializationXKotlinMasterLinux/4832392?hideTestsFromDependencies=false&hideProblemsFromDependencies=false&expandBuildDeploymentsSection=false&expandBuildChangesSection=true&expandBuildProblemsSection=true

Branch with a reproducer (uses 2.1.20-dev-933): https://github.com/Kotlin/kotlinx.serialization/tree/dokka-2.1-failure

Failure does not happen on dev even when Kotlin 2.1.20-dev is used, likely because dev does not use new @SubclassOptInRequired annotation, while my branch does. Error does not happen on 2.0.20 in any case.

So, it likely is caused by some changes in the Kotlin compiler (or lack thereof, since Dokka still uses the K1 analyzer).

Dokka configuration Configuration of dokka used to reproduce the bug

Dokka 1.9.20 or 2.0.0-Beta both show error. I wasn't able to try new K2 mode (org.jetbrains.dokka.experimental.gradle.pluginMode=V2EnabledWithHelpers) because of https://youtrack.jetbrains.com/issue/KT-72000 — workarounding this would require full migration.

Installation

sandwwraith commented 1 month ago

Workaround: use Dokka K2 analyzer with org.jetbrains.dokka.experimental.tryK2=true