Skip to content
Draft
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 @@ -172,6 +172,13 @@ public open class DefaultPageCreator(

private fun <T : Documentable> List<T>.renameClashingDocumentable(): List<T> =
groupBy { it.dri }.values.flatMap { elements ->
//special case: property and function with the same DRI
if(elements.any { it is DProperty } && elements.any { it is DFunction }) {
// do not rename [elements] if there is an explicit expect-actual
// they should be merged by [SameMethodNamePageMergerStrategy]
if(elements.any { it is WithIsExpectActual && it.isExpectActual }) return elements
}

if (elements.size == 1) elements else elements.mapNotNull { element ->
element.renameClashingDocumentable()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,113 @@ class ExpectActualsTest : BaseAbstractTest() {
}
}

@Test
fun `should merge an explicit-expectActual property with a single function #3685`() = testInline(
"""
/src/common/test.kt
expect class Skiko {
val isShowing
}

/src/jvm/test.kt
actual class Skiko actual constructor() {
actual val isShowing = false
fun isShowing(): Boolean {
return false
}
}

/src/native/test.kt
actual class Skiko actual constructor(){
actual val isShowing = false
}
""".trimMargin(),
multiplatformConfiguration
) {
pagesGenerationStage = { root ->
val cl = root.dfs { it.name == "Skiko" && it is ClasslikePageNode } ?: throw IllegalStateException()
// before page merging
assertEquals(2, cl.children.count { it.name == "isShowing" })
}
renderingStage = { root, _ ->
val documentables = (root.dfs { it.name == "isShowing" } as MemberPageNode).documentables
// after page merging
assertEquals(listOf(DFunction::class, DProperty::class), documentables.map { it::class })
}
}

@Test
fun `should merge an explicit-expectActual function with a single property #3685`() = testInline(
"""
/src/common/test.kt
expect class Skiko {
fun isShowing(): Boolean
}

/src/jvm/test.kt
actual class Skiko actual constructor() {
val isShowing = false
actual fun isShowing(): Boolean {
return false
}
}

/src/native/test.kt
actual class Skiko actual constructor(){
actual fun isShowing(): Boolean
}
""".trimMargin(),
multiplatformConfiguration
) {
pagesGenerationStage = { root ->
val cl = root.dfs { it.name == "Skiko" && it is ClasslikePageNode } ?: throw IllegalStateException()
// before page merging
assertEquals(2, cl.children.count { it.name == "isShowing" })
}
renderingStage = { root, _ ->
val documentables = (root.dfs { it.name == "isShowing" } as MemberPageNode).documentables
// after page merging
assertEquals(listOf(DFunction::class, DProperty::class), documentables.map { it::class })
}
}

@Test
fun `should merge an explicit-expectActual function with a single function #3685`() = testInline(
"""
/src/common/test.kt
expect class Skiko {
fun isShowing(): Boolean
}

/src/jvm/test.kt
actual class Skiko actual constructor() {
fun isShowing(b: Boolean): Boolean {
return b
}
actual fun isShowing(): Boolean {
return false
}
}

/src/native/test.kt
actual class Skiko actual constructor(){
actual fun isShowing(): Boolean
}
""".trimMargin(),
multiplatformConfiguration
) {
pagesGenerationStage = { root ->
val cl = root.dfs { it.name == "Skiko" && it is ClasslikePageNode } ?: throw IllegalStateException()
// before page merging
assertEquals(2, cl.children.count { it.name == "isShowing" })
}
renderingStage = { root, _ ->
val documentables = (root.dfs { it.name == "isShowing" } as MemberPageNode).documentables
// after page merging
assertEquals(listOf(DFunction::class, DFunction::class), documentables.map { it::class })
}
}

@Test
@OnlySymbols("context parameters")
@OptIn(ExperimentalDokkaApi::class)
Expand Down
Loading