From a1d4214a39fc0fe9f238966d7637b1bb8bc0ee0c Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Thu, 21 Apr 2016 12:49:00 +0300 Subject: [PATCH] Use fq-names instead of descriptors when computing ambigious names Because there can be different descriptors that are essentially equal (from different modules) See J2K test: testNullableField --- .../rendering/adaptiveClassifierNamePolicy.kt | 22 +++++++++++-------- .../conflictingPlatformDeclarations/build.log | 8 +++---- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/adaptiveClassifierNamePolicy.kt b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/adaptiveClassifierNamePolicy.kt index eae180d4342..5d04f00e960 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/adaptiveClassifierNamePolicy.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/adaptiveClassifierNamePolicy.kt @@ -20,9 +20,12 @@ import org.jetbrains.kotlin.descriptors.CallableDescriptor import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.ClassifierDescriptor import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor +import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.name.FqNameUnsafe import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.renderer.ClassifierNamePolicy import org.jetbrains.kotlin.renderer.DescriptorRenderer +import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.typeUtil.contains @@ -66,35 +69,36 @@ private class AdaptiveClassifierNamePolicy(private val ambiguousNames: List("ADAPTIVE_CLASSIFIER_POLICY") { override fun compute(objectsToRender: Collection): ClassifierNamePolicy { - val ambiguousNames = collectClassifiers(objectsToRender).groupBy { it.name }.filter { it.value.size > 1 }.map { it.key } + val ambiguousNames = + collectClassifiersFqNames(objectsToRender).groupBy { it.shortNameOrSpecial() }.filter { it.value.size > 1 }.map { it.key } return AdaptiveClassifierNamePolicy(ambiguousNames) } } -private fun collectClassifiers(objectsToRender: Collection): Set = LinkedHashSet().apply { - collectMentionedClassifiers(objectsToRender, this) +private fun collectClassifiersFqNames(objectsToRender: Collection): Set = LinkedHashSet().apply { + collectMentionedClassifiersFqNames(objectsToRender, this) } -private fun collectMentionedClassifiers(contextObjects: Collection, result: MutableSet) { +private fun collectMentionedClassifiersFqNames(contextObjects: Collection, result: MutableSet) { contextObjects.filterIsInstance().forEach { diagnosticType -> diagnosticType.contains { innerType -> - innerType.constructor.declarationDescriptor?.let { result.add(it) } + innerType.constructor.declarationDescriptor?.let { result.add(it.fqNameUnsafe) } false } } contextObjects.filterIsInstance>().forEach { - collectMentionedClassifiers(it, result) + collectMentionedClassifiersFqNames(it, result) } contextObjects.filterIsInstance().forEach { - result.add(it) + result.add(it.fqNameUnsafe) } contextObjects.filterIsInstance().forEach { - collectMentionedClassifiers(it.upperBounds, result) + collectMentionedClassifiersFqNames(it.upperBounds, result) } contextObjects.filterIsInstance().forEach { - collectMentionedClassifiers(listOf( + collectMentionedClassifiersFqNames(listOf( it.typeParameters, it.returnType, it.valueParameters, diff --git a/jps-plugin/testData/incremental/pureKotlin/conflictingPlatformDeclarations/build.log b/jps-plugin/testData/incremental/pureKotlin/conflictingPlatformDeclarations/build.log index c3d008be68b..6c49ba3e152 100644 --- a/jps-plugin/testData/incremental/pureKotlin/conflictingPlatformDeclarations/build.log +++ b/jps-plugin/testData/incremental/pureKotlin/conflictingPlatformDeclarations/build.log @@ -12,8 +12,8 @@ Exit code: ABORT ------------------------------------------ COMPILATION FAILED Platform declaration clash: The following declarations have the same JVM signature (function(Ljava/util/List;)V): - fun function(list: List): kotlin.Unit - fun function(list: List): kotlin.Unit + fun function(list: List): Unit + fun function(list: List): Unit Platform declaration clash: The following declarations have the same JVM signature (function(Ljava/util/List;)V): - fun function(list: List): kotlin.Unit - fun function(list: List): kotlin.Unit \ No newline at end of file + fun function(list: List): Unit + fun function(list: List): Unit \ No newline at end of file