aboutsummaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
Diffstat (limited to 'core/src')
-rw-r--r--core/src/main/kotlin/Kotlin/DocumentationBuilder.kt13
-rw-r--r--core/src/test/kotlin/format/MarkdownFormatTest.kt4
2 files changed, 15 insertions, 2 deletions
diff --git a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt
index 1b6ab3fd..8cead63e 100644
--- a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt
+++ b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt
@@ -309,14 +309,23 @@ class DocumentationBuilder
val classDescriptor = extensionFunction.getExtensionClassDescriptor() ?: return@forEach
val subclasses = classHierarchy[classDescriptor] ?: return@forEach
subclasses.forEach { subclass ->
- if (subclass.defaultType.isSubtypeOf(extensionFunction.extensionReceiverParameter!!.type) &&
- possiblyShadowingFunctions.none { subclass.defaultType.isSubtypeOf(it.extensionReceiverParameter!!.type) }) {
+ if (subclass.isExtensionApplicable(extensionFunction) &&
+ possiblyShadowingFunctions.none { subclass.isExtensionApplicable(it) }) {
refGraph.link(subclass.signature(), extensionFunction.signature(), RefKind.Extension)
}
}
}
}
+ private fun ClassDescriptor.isExtensionApplicable(extensionFunction: CallableMemberDescriptor): Boolean {
+ val receiverType = extensionFunction.extensionReceiverParameter!!.type
+ if (receiverType.arguments.any { it.type.constructor.declarationDescriptor is TypeParameterDescriptor }) {
+ val receiverClass = receiverType.constructor.declarationDescriptor
+ return receiverClass is ClassDescriptor && DescriptorUtils.isSubclass(this, receiverClass)
+ }
+ return defaultType.isSubtypeOf(receiverType)
+ }
+
private fun buildClassHierarchy(classes: List<ClassDescriptor>): Map<ClassDescriptor, List<ClassDescriptor>> {
val result = hashMapOf<ClassDescriptor, MutableList<ClassDescriptor>>()
classes.forEach { cls ->
diff --git a/core/src/test/kotlin/format/MarkdownFormatTest.kt b/core/src/test/kotlin/format/MarkdownFormatTest.kt
index 508790b1..8fe45106 100644
--- a/core/src/test/kotlin/format/MarkdownFormatTest.kt
+++ b/core/src/test/kotlin/format/MarkdownFormatTest.kt
@@ -218,6 +218,10 @@ class MarkdownFormatTest {
verifyMarkdownNodeByName("inheritedExtensions", "Bar")
}
+ @Test fun genericInheritedExtensions() {
+ verifyMarkdownNodeByName("genericInheritedExtensions", "Bar")
+ }
+
@Test fun arrayAverage() {
verifyMarkdownNodeByName("arrayAverage", "XArray")
}