From 8c54b7110a7947ec1694c723499d0b16a9a29ab0 Mon Sep 17 00:00:00 2001 From: Kamil Doległo Date: Fri, 14 Feb 2020 00:31:47 +0100 Subject: Fix descriptor visiting, add test for DRI clash on JS After creating the test reproducing the DRI clash, I found a bug in the DefaultDescriptorToDocumentationTranslator, which this commit fixes. The bug was present when running the tests but not when using dokka on an external project. I have no idea how it worked, as debugging showed that the same code from AbstractClassDescriptor runs in both cases and the code contains an assert, which had to (and did) fail. Probably the error messages are being suppressed somehow. `getMemberScope()` requires a list of type substitutions which size is being compared to the type constructor's parameters count. I suppose we don't want to substitute the type parameters and get the unsubstituted member scope instead --- core/src/test/kotlin/basic/DRITest.kt | 76 ++++++++++++++++++++++++++++++++--- 1 file changed, 71 insertions(+), 5 deletions(-) (limited to 'core/src/test/kotlin/basic/DRITest.kt') diff --git a/core/src/test/kotlin/basic/DRITest.kt b/core/src/test/kotlin/basic/DRITest.kt index 93a874ef..c7dc85fb 100644 --- a/core/src/test/kotlin/basic/DRITest.kt +++ b/core/src/test/kotlin/basic/DRITest.kt @@ -1,11 +1,13 @@ package basic import org.jetbrains.dokka.links.* +import org.jetbrains.dokka.pages.ContentPage +import org.jetbrains.dokka.pages.asSequence import org.junit.Assert.assertEquals import org.junit.Test import testApi.testRunner.AbstractCoreTest -class DRITest: AbstractCoreTest() { +class DRITest : AbstractCoreTest() { @Test fun `#634`() { val configuration = dokkaConfiguration { @@ -28,10 +30,12 @@ class DRITest: AbstractCoreTest() { configuration ) { documentablesMergingStage = { module -> - val expected = TypeConstructor("kotlin.Function1", listOf( - TypeParam(listOf(Nullable(TypeConstructor("kotlin.Any", emptyList())))), - Nullable(TypeParam(listOf(TypeConstructor("kotlin.Comparable", listOf(SelfType))))) - )) + val expected = TypeConstructor( + "kotlin.Function1", listOf( + TypeParam(listOf(Nullable(TypeConstructor("kotlin.Any", emptyList())))), + Nullable(TypeParam(listOf(TypeConstructor("kotlin.Comparable", listOf(SelfType))))) + ) + ) val actual = module.packages.single() .functions.single() .dri.callable?.params?.single() @@ -99,4 +103,66 @@ class DRITest: AbstractCoreTest() { } } } + + @Test + fun `#642 with * and Any?`() { + val configuration = dokkaConfiguration { + passes { + pass { + analysisPlatform = "js" + sourceRoots = listOf("src/") + } + } + } + + testInline( + """ + |/src/main/kotlin/Test.kt + | + |open class Bar + |class ReBarBar : Bar() + |class Foo, R : List>> + | + |fun > Foo.qux(): String = TODO() + |fun > Foo.qux(): String = TODO() + | + """.trimMargin(), + configuration + ) { + pagesGenerationStage = { module -> + // DRI(//qux/Foo[TypeParam(bounds=[kotlin.Comparable[kotlin.Any?]]),kotlin.Any?]#//) + val expectedDRI = DRI( + "", + null, + Callable( + "qux", + TypeConstructor( + "Foo", + listOf( + TypeParam( + listOf( + TypeConstructor( + "kotlin.Comparable", + listOf( + Nullable(TypeConstructor("kotlin.Any", emptyList())) + ) + ) + ) + ), + Nullable(TypeConstructor("kotlin.Any", emptyList())) + ) + ), + emptyList() + ) + ) + + val driCount = module + .asSequence() + .filterIsInstance() + .sumBy { it.dri.count { dri -> dri == expectedDRI } } + + assertEquals(1, driCount) + } + } + } } \ No newline at end of file -- cgit