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

Correctly handle case when we have internal expect but public actual declarations #3662

Merged
merged 2 commits into from
Jul 9, 2024
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 @@ -109,7 +109,12 @@ public class DefaultDocumentableMerger(context: DokkaContext) : DocumentableMerg

fun analyzeExpectActual(sameDriElements: List<T>): List<T> {
val (expects, actuals) = sameDriElements.partition { it.expectPresentInSet != null }
val groupedByOwnExpectWithActualSourceSetIds = expects.map { expect ->
// It's possible that there are no `expect` declarations, but there are `actual` declarations,
whyoleg marked this conversation as resolved.
Show resolved Hide resolved
// e.g. in case `expect` is `internal` or filtered previously for some other reason.
// In this case we just merge `actual` declarations without `expect`
val groupedActualsWithSourceSets = if (expects.isEmpty()) {
listOf(actuals to actuals.flatMap { it.sourceSets }.toSet())
} else expects.map { expect ->
val actualsForGivenExpect = actuals.filter { actual ->
dependencyInfo[actual.sourceSets.single()]
?.contains(expect.expectPresentInSet!!)
Expand All @@ -118,7 +123,7 @@ public class DefaultDocumentableMerger(context: DokkaContext) : DocumentableMerg
(listOf(expect) + actualsForGivenExpect) to actualsForGivenExpect.flatMap { it.sourceSets }.toSet()
}
val reducedToOneDocumentableWithActualSourceSetIds =
groupedByOwnExpectWithActualSourceSetIds.map { it.first.reduce(reducer) to it.second }
groupedActualsWithSourceSets.map { it.first.reduce(reducer) to it.second }
return reducedToOneDocumentableWithActualSourceSetIds.let(::mergeClashingElements)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,4 +305,79 @@ class ExpectActualsTest : BaseAbstractTest() {
}
}
}

@Test
fun `public actual function should be present when expect is internal`() = testInline(
"""
/src/common/test.kt
internal expect fun function(): String?

/src/jvm/test.kt
public actual fun function(): String? = null

/src/native/test.kt
public actual fun function(): String? = null
""".trimMargin(),
multiplatformConfiguration
) {
documentablesTransformationStage = { module ->
val function = module.packages.single().functions.single { it.name == "function" }
assertTrue(function.isExpectActual)
// no `common` is present
assertEquals(
setOf("jvm", "native"),
function.sourceSets.map { it.sourceSetID.sourceSetName }.toSet()
)
}
}

@Test
fun `public actual function should be present when expect is internal and other actual is internal`() = testInline(
"""
/src/common/test.kt
internal expect fun function(): String?

/src/jvm/test.kt
public actual fun function(): String? = null

/src/native/test.kt
internal actual fun function(): String? = null
""".trimMargin(),
multiplatformConfiguration
) {
documentablesTransformationStage = { module ->
val function = module.packages.single().functions.single { it.name == "function" }
assertTrue(function.isExpectActual)
// `common` - internal, `native` - internal, so only `jvm` is present
assertEquals(
setOf("jvm"),
function.sourceSets.map { it.sourceSetID.sourceSetName }.toSet()
)
}
}

@Test
fun `public actual classe should be present when expect is internal`() = testInline(
"""
/src/common/test.kt
internal expect class Class

/src/jvm/test.kt
public actual class Class

/src/native/test.kt
public actual class Class
""".trimMargin(),
multiplatformConfiguration
) {
documentablesTransformationStage = { module ->
val classlike = module.packages.single().classlikes.single { it.name == "Class" }
assertTrue(classlike.isExpectActual)
// no `common` is present
assertEquals(
setOf("jvm", "native"),
classlike.sourceSets.map { it.sourceSetID.sourceSetName }.toSet()
)
}
}
}
Loading