Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[K1] Handle exception for recursive type aliases #3582

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -840,15 +840,20 @@ private class DokkaDescriptorVisitor(
private suspend fun visitTypeAliasDescriptor(descriptor: TypeAliasDescriptor) =
with(descriptor) {
coroutineScope {
// `defaultType` can throw an exception for a recursive typealias A = A
// for more details see https://github.com/Kotlin/dokka/issues/3565
val defaultType = runCatching { defaultType }.getOrNull()
val generics = async { descriptor.declaredTypeParameters.parallelMap { it.toVariantTypeParameter() } }
val info = buildAncestryInformation(defaultType).copy(
superclass = buildAncestryInformation(underlyingType),
interfaces = emptyList()
)
val info = defaultType?.let {
buildAncestryInformation(it).copy(
superclass = buildAncestryInformation(underlyingType),
interfaces = emptyList()
)
}
DTypeAlias(
dri = DRI.from(this@with),
name = name.asString(),
type = defaultType.toBound(),
type = defaultType?.toBound() ?: UnresolvedBound(name.asString()),
Copy link
Contributor Author

@vmishenev vmishenev Apr 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an alternative way: type = GenericTypeConstructor(dri = dri, projections = generics.await().map { it.variantTypeParameter }) like in K2. I would like to have the old logic in K1 to discover the difference between the two ways.

expectPresentInSet = null,
underlyingType = underlyingType.toBound().toSourceSetDependent(),
visibility = visibility.toDokkaVisibility().toSourceSetDependent(),
Expand All @@ -858,7 +863,7 @@ private class DokkaDescriptorVisitor(
sources = descriptor.createSources(),
extra = PropertyContainer.withAll(
descriptor.getAnnotations().toSourceSetDependent().toAnnotations(),
info.exceptionInSupertypesOrNull(),
info?.exceptionInSupertypesOrNull(),
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
package translators

import org.jetbrains.dokka.DokkaConfiguration
import org.jetbrains.dokka.Platform
import org.jetbrains.dokka.analysis.kotlin.markdown.MARKDOWN_ELEMENT_FILE_NAME
import org.jetbrains.dokka.base.signatures.KotlinSignatureUtils.modifiers
import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest
import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.links.PointingToDeclaration
import org.jetbrains.dokka.model.*
import org.jetbrains.dokka.model.doc.*
import utils.OnlyDescriptors
import utils.text
import kotlin.test.*

Expand Down Expand Up @@ -1076,6 +1078,38 @@ val soapXml = node("soap-env:Envelope", soapAttrs,
}
}
}

@Test
@OnlyDescriptors("In K2 the types of recursive typealias is resolved")
fun `a translator should not fail for a recursive typealias A = A #3565`() {
val configuration = dokkaConfiguration {
sourceSets {
sourceSet {
name = "androidJvm"
analysisPlatform = Platform.common.key // an androidJvm source set has a common platform
sourceRoots = listOf("src/main/kotlin")
classpath = listOf(commonStdlibPath!!)
}
}
}
// `java.io.File` is unavailable in a common platform
// so `typealias File = File` is recursive
testInline(
"""
|/src/main/kotlin/test/typealias.jvmAndAndroid.kt
|package test
|
|import java.io.File
|typealias File = File
""".trimIndent(),
configuration
) {
documentablesMergingStage = { module ->
val ta = module.dfs { it.name == "File" } as DTypeAlias
assertTrue { ta.type is UnresolvedBound }
}
}
}
}

private sealed class TestSuite {
Expand Down
Loading