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

Fix merging expect-actual declarations #3875

Merged
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 @@ -116,9 +116,12 @@ public class DefaultDocumentableMerger(context: DokkaContext) : DocumentableMerg
listOf(actuals to actuals.flatMap { it.sourceSets }.toSet())
} else expects.map { expect ->
val actualsForGivenExpect = actuals.filter { actual ->
dependencyInfo[actual.sourceSets.single()]
// [actual.sourceSets] can already be partially merged and contain more than one source set
actual.sourceSets.all {
whyoleg marked this conversation as resolved.
Show resolved Hide resolved
dependencyInfo[it]
?.contains(expect.expectPresentInSet!!)
?: throw IllegalStateException("Cannot resolve expect/actual relation for ${actual.name}")
}
}
(listOf(expect) + actualsForGivenExpect) to actualsForGivenExpect.flatMap { it.sourceSets }.toSet()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package expectActuals

import org.jetbrains.dokka.DokkaSourceSetID
import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest
import org.jetbrains.dokka.model.withDescendants
import org.jetbrains.dokka.pages.ClasslikePageNode
Expand Down Expand Up @@ -380,4 +381,58 @@ class ExpectActualsTest : BaseAbstractTest() {
)
}
}


@Test
fun `should work with the reversed order of source sets #3798`() {
whyoleg marked this conversation as resolved.
Show resolved Hide resolved
val configuration = dokkaConfiguration {
sourceSets {
val commonId = DokkaSourceSetID("root", "common")
sourceSet {
sourceRoots = listOf("src/jvm/")
analysisPlatform = "jvm"
name = "jvm"
displayName = "jvm"
dependentSourceSets = setOf(commonId)
}
sourceSet {
sourceRoots = listOf("src/native/")
analysisPlatform = "native"
name = "native"
displayName = "native"
dependentSourceSets = setOf(commonId)
}
sourceSet {
sourceRoots = listOf("src/common/")
analysisPlatform = "common"
name = "common"
displayName = "common"
}
}
}

testInline(
"""
/src/common/test.kt
expect fun shared()

/src/native/test.kt
actual fun shared(){}

/src/jvm/test.kt
actual fun shared(){}
""".trimMargin(), configuration
) {
documentablesTransformationStage = { module ->
val function = module.packages.single().functions.single { it.name == "shared" }
assertTrue(function.isExpectActual)
assertEquals(
"common", function.expectPresentInSet?.sourceSetID?.sourceSetName
)
assertEquals(
setOf("common", "jvm", "native"), function.sourceSets.map { it.sourceSetID.sourceSetName }.toSet()
)
}
}
}
}
Loading