[klib] Don't show signature clash diagnostics for local declarations

For some reason type parameters end up in
`GlobdalDeclarationTable`, and thus we tracked them in
`IdSignatureClashDetector`, which wasn't right and confused the
diagnostic renderer that uses
`org.jetbrains.kotlin.resolve.MemberComparator` for sorting the
declarations to display in diagnostics. That comparator doesn't know
jow to work with type parameters.

Besides, type parameters, like many other types of declarations, are not
considered public wrt KLIB ABI, so there's no need to show
CONFLICTING_KLIB_SIGNATURES_ERROR for them.

^KT-65723 Fixed
This commit is contained in:
Sergej Jaskiewicz
2024-02-09 19:26:27 +01:00
committed by Space Team
parent e363a1228d
commit f26e470e80
6 changed files with 50 additions and 43 deletions
@@ -37,7 +37,7 @@ abstract class GlobalDeclarationTable(private val mangler: KotlinMangler.IrMangl
return table.getOrPut(declaration) {
publicIdSignatureComputer.composePublicIdSignature(declaration, compatibleMode)
}.also {
if (recordInSignatureClashDetector) {
if (recordInSignatureClashDetector && it.isPubliclyVisible && !it.isLocal) {
clashDetector.trackDeclaration(declaration, it)
}
}
@@ -8,10 +8,6 @@
var myVal: kotlin.Int defined in com.example.klib.serialization.diagnostics
var myVal: kotlin.Long defined in com.example.klib.serialization.diagnostics
/foo.kt:17:1: error: Platform declaration clash: The following fields have the same IR signature ([ com.example.klib.serialization.diagnostics/myVal|{}myVal[0] <- Local[<BF>|FIELD PROPERTY_BACKING_FIELD name:myVal type:kotlin.Long visibility:private [static]] ]):
var myVal: kotlin.Int defined in com.example.klib.serialization.diagnostics
var myVal: kotlin.Long defined in com.example.klib.serialization.diagnostics
/foo.kt:17:1: error: Platform declaration clash: The following functions have the same IR signature (com.example.klib.serialization.diagnostics/myVal.<get-myVal>|<get-myVal>(){}[0]):
fun `<get-myVal>`(): kotlin.Int defined in com.example.klib.serialization.diagnostics
fun `<get-myVal>`(): kotlin.Long defined in com.example.klib.serialization.diagnostics
@@ -21,10 +17,6 @@
val myDelegated: kotlin.Int defined in com.example.klib.serialization.diagnostics
val myDelegated: kotlin.Long defined in com.example.klib.serialization.diagnostics
/foo.kt:19:26: error: Platform declaration clash: The following fields have the same IR signature ([ com.example.klib.serialization.diagnostics/myDelegated|{}myDelegated[0] <- Local[<BF>|FIELD PROPERTY_DELEGATE name:myDelegated$delegate type:kotlin.Lazy<kotlin.Long> visibility:private [final,static]] ]):
val `myDelegated$delegate`: kotlin.Lazy<kotlin.Int> defined in com.example.klib.serialization.diagnostics
val `myDelegated$delegate`: kotlin.Lazy<kotlin.Long> defined in com.example.klib.serialization.diagnostics
/foo.kt:19:26: error: Platform declaration clash: The following functions have the same IR signature (com.example.klib.serialization.diagnostics/myDelegated.<get-myDelegated>|<get-myDelegated>(){}[0]):
fun `<get-myDelegated>`(): kotlin.Int defined in com.example.klib.serialization.diagnostics
fun `<get-myDelegated>`(): kotlin.Long defined in com.example.klib.serialization.diagnostics
@@ -44,10 +36,6 @@
var myVal: kotlin.Int defined in com.example.klib.serialization.diagnostics
var myVal: kotlin.Long defined in com.example.klib.serialization.diagnostics
/main.kt:29:1: error: Platform declaration clash: The following fields have the same IR signature ([ com.example.klib.serialization.diagnostics/myVal|{}myVal[0] <- Local[<BF>|FIELD PROPERTY_BACKING_FIELD name:myVal type:kotlin.Long visibility:private [static]] ]):
var myVal: kotlin.Int defined in com.example.klib.serialization.diagnostics
var myVal: kotlin.Long defined in com.example.klib.serialization.diagnostics
/main.kt:29:1: error: Platform declaration clash: The following functions have the same IR signature (com.example.klib.serialization.diagnostics/myVal.<get-myVal>|<get-myVal>(){}[0]):
fun `<get-myVal>`(): kotlin.Int defined in com.example.klib.serialization.diagnostics
fun `<get-myVal>`(): kotlin.Long defined in com.example.klib.serialization.diagnostics
@@ -67,18 +55,38 @@
val myDelegated: kotlin.Int defined in com.example.klib.serialization.diagnostics
val myDelegated: kotlin.Long defined in com.example.klib.serialization.diagnostics
/main.kt:37:25: error: Platform declaration clash: The following fields have the same IR signature ([ com.example.klib.serialization.diagnostics/myDelegated|{}myDelegated[0] <- Local[<BF>|FIELD PROPERTY_DELEGATE name:myDelegated$delegate type:kotlin.Lazy<kotlin.Long> visibility:private [final,static]] ]):
val `myDelegated$delegate`: kotlin.Lazy<kotlin.Int> defined in com.example.klib.serialization.diagnostics
val `myDelegated$delegate`: kotlin.Lazy<kotlin.Long> defined in com.example.klib.serialization.diagnostics
/main.kt:37:25: error: Platform declaration clash: The following functions have the same IR signature (com.example.klib.serialization.diagnostics/myDelegated.<get-myDelegated>|<get-myDelegated>(){}[0]):
fun `<get-myDelegated>`(): kotlin.Int defined in com.example.klib.serialization.diagnostics
fun `<get-myDelegated>`(): kotlin.Long defined in com.example.klib.serialization.diagnostics
/main.kt:50:1: error: Platform declaration clash: The following functions have the same IR signature (com.example.klib.serialization.diagnostics/bar|bar(){}[0]):
/main.kt:43:5: error: Platform declaration clash: The following functions have the same IR signature (com.example.klib.serialization.diagnostics/A.parameterized|parameterized(0:0){0§<kotlin.Any?>}[0]):
fun <T> parameterized(a: T): T defined in com.example.klib.serialization.diagnostics.A
fun <T> parameterized(a: T): kotlin.Unit defined in com.example.klib.serialization.diagnostics.A
/main.kt:46:5: error: Platform declaration clash: The following functions have the same IR signature (com.example.klib.serialization.diagnostics/A.parameterized|parameterized(0:0){0§<kotlin.Any?>}[0]):
fun <T> parameterized(a: T): T defined in com.example.klib.serialization.diagnostics.A
fun <T> parameterized(a: T): kotlin.Unit defined in com.example.klib.serialization.diagnostics.A
/main.kt:48:5: error: Platform declaration clash: The following functions have the same IR signature (com.example.klib.serialization.diagnostics/A.privateMethod|privateMethod(){}[0]):
fun privateMethod(): kotlin.Int defined in com.example.klib.serialization.diagnostics.A
fun privateMethod(): kotlin.Long defined in com.example.klib.serialization.diagnostics.A
/main.kt:51:5: error: Platform declaration clash: The following functions have the same IR signature (com.example.klib.serialization.diagnostics/A.privateMethod|privateMethod(){}[0]):
fun privateMethod(): kotlin.Int defined in com.example.klib.serialization.diagnostics.A
fun privateMethod(): kotlin.Long defined in com.example.klib.serialization.diagnostics.A
/main.kt:54:1: error: Platform declaration clash: The following functions have the same IR signature ([ File '/main.kt' <- com.example.klib.serialization.diagnostics/privateTopLevelFunction|privateTopLevelFunction(){}[0] ]):
fun privateTopLevelFunction(): kotlin.Int defined in com.example.klib.serialization.diagnostics
fun privateTopLevelFunction(): kotlin.Long defined in com.example.klib.serialization.diagnostics
/main.kt:57:1: error: Platform declaration clash: The following functions have the same IR signature ([ File '/main.kt' <- com.example.klib.serialization.diagnostics/privateTopLevelFunction|privateTopLevelFunction(){}[0] ]):
fun privateTopLevelFunction(): kotlin.Int defined in com.example.klib.serialization.diagnostics
fun privateTopLevelFunction(): kotlin.Long defined in com.example.klib.serialization.diagnostics
/main.kt:67:1: error: Platform declaration clash: The following functions have the same IR signature (com.example.klib.serialization.diagnostics/bar|bar(){}[0]):
fun bar(): kotlin.Long defined in com.example.klib.serialization.diagnostics
fun bar(): kotlin.Long defined in com.example.klib.serialization.diagnostics
/main.kt:53:1: error: Platform declaration clash: The following functions have the same IR signature (com.example.klib.serialization.diagnostics/bar|bar(){}[0]):
/main.kt:70:1: error: Platform declaration clash: The following functions have the same IR signature (com.example.klib.serialization.diagnostics/bar|bar(){}[0]):
fun bar(): kotlin.Long defined in com.example.klib.serialization.diagnostics
fun bar(): kotlin.Long defined in com.example.klib.serialization.diagnostics
@@ -14,9 +14,9 @@ package com.example.klib.serialization.diagnostics
<!CONFLICTING_KLIB_SIGNATURES_ERROR!>@Deprecated("", level = DeprecationLevel.HIDDEN)
fun foo(): Long = 0L<!>
<!CONFLICTING_KLIB_SIGNATURES_ERROR, CONFLICTING_KLIB_SIGNATURES_ERROR, CONFLICTING_KLIB_SIGNATURES_ERROR!>var myVal: Long = 0L<!>
<!CONFLICTING_KLIB_SIGNATURES_ERROR, CONFLICTING_KLIB_SIGNATURES_ERROR!>var myVal: Long = 0L<!>
<!CONFLICTING_KLIB_SIGNATURES_ERROR!>val myDelegated: Long by <!CONFLICTING_KLIB_SIGNATURES_ERROR, CONFLICTING_KLIB_SIGNATURES_ERROR!>lazy { 0L }<!><!>
<!CONFLICTING_KLIB_SIGNATURES_ERROR!>val myDelegated: Long by <!CONFLICTING_KLIB_SIGNATURES_ERROR!>lazy { 0L }<!><!>
// FILE: main.kt
package com.example.klib.serialization.diagnostics
@@ -26,7 +26,7 @@ fun foo(): String = ""<!>
<!CONFLICTING_KLIB_SIGNATURES_ERROR!>fun foo(): Int = 0<!>
<!CONFLICTING_KLIB_SIGNATURES_ERROR, CONFLICTING_KLIB_SIGNATURES_ERROR, CONFLICTING_KLIB_SIGNATURES_ERROR!>@Deprecated("", level = DeprecationLevel.HIDDEN)
<!CONFLICTING_KLIB_SIGNATURES_ERROR, CONFLICTING_KLIB_SIGNATURES_ERROR!>@Deprecated("", level = DeprecationLevel.HIDDEN)
var myVal: Int = 0<!>
<!CONFLICTING_KLIB_SIGNATURES_ERROR!>@Deprecated("", level = DeprecationLevel.HIDDEN)
@@ -34,11 +34,28 @@ val myVal: String
<!CONFLICTING_KLIB_SIGNATURES_ERROR!>get() = ""<!><!>
<!CONFLICTING_KLIB_SIGNATURES_ERROR!>@Deprecated("", level = DeprecationLevel.HIDDEN)
val myDelegated: Int by <!CONFLICTING_KLIB_SIGNATURES_ERROR, CONFLICTING_KLIB_SIGNATURES_ERROR!>lazy { 1 }<!><!>
val myDelegated: Int by <!CONFLICTING_KLIB_SIGNATURES_ERROR!>lazy { 1 }<!><!>
@Deprecated("This function moved to the 'lib' module", level = DeprecationLevel.HIDDEN)
fun movedToLib() {}
class A {
<!CONFLICTING_KLIB_SIGNATURES_ERROR!>@Deprecated(message = "", level = DeprecationLevel.HIDDEN)
fun <T> parameterized(a: T): T = a<!>
<!CONFLICTING_KLIB_SIGNATURES_ERROR!>fun <T> parameterized(a: T) {}<!>
<!CONFLICTING_KLIB_SIGNATURES_ERROR!>@Deprecated(message = "", level = DeprecationLevel.HIDDEN)
private fun privateMethod(): Int = 0<!>
<!CONFLICTING_KLIB_SIGNATURES_ERROR!>private fun privateMethod(): Long = 0L<!>
}
<!CONFLICTING_KLIB_SIGNATURES_ERROR!>@Deprecated(message = "", level = DeprecationLevel.HIDDEN)
private fun privateTopLevelFunction(): Int = 0<!>
<!CONFLICTING_KLIB_SIGNATURES_ERROR!>private fun privateTopLevelFunction(): Long = 0L<!>
fun main() {
foo()
movedToLib()
@@ -11,10 +11,6 @@ Module: common
val param: kotlin.Int defined in root package
val param: kotlin.Int defined in root package
/common.kt:13:1: error: Platform declaration clash: The following fields have the same IR signature ([ /param|{}param[0] <- Local[<BF>|FIELD PROPERTY_BACKING_FIELD name:param type:kotlin.Int visibility:private [final,static]] ]):
val param: kotlin.Int defined in root package
val param: kotlin.Int defined in root package
/common.kt:13:1: error: Platform declaration clash: The following functions have the same IR signature (/param.<get-param>|<get-param>(){}[0]):
fun `<get-param>`(): kotlin.Int defined in root package
fun `<get-param>`(): kotlin.Int defined in root package
@@ -31,10 +27,6 @@ Module: platform
val param: kotlin.Int defined in root package
val param: kotlin.Int defined in root package
/platform.kt:24:1: error: Platform declaration clash: The following fields have the same IR signature ([ /param|{}param[0] <- Local[<BF>|FIELD PROPERTY_BACKING_FIELD name:param type:kotlin.Int visibility:private [final,static]] ]):
val param: kotlin.Int defined in root package
val param: kotlin.Int defined in root package
/platform.kt:24:1: error: Platform declaration clash: The following functions have the same IR signature (/param.<get-param>|<get-param>(){}[0]):
fun `<get-param>`(): kotlin.Int defined in root package
fun `<get-param>`(): kotlin.Int defined in root package
@@ -10,7 +10,7 @@ expect class A
<!CONFLICTING_KLIB_SIGNATURES_ERROR!>fun bar(x: A): Int = 2<!>
// NOTE: This must be REDECLARATION, see KT-59898
<!CONFLICTING_KLIB_SIGNATURES_ERROR, CONFLICTING_KLIB_SIGNATURES_ERROR, CONFLICTING_KLIB_SIGNATURES_ERROR!>val param = 0<!>
<!CONFLICTING_KLIB_SIGNATURES_ERROR, CONFLICTING_KLIB_SIGNATURES_ERROR!>val param = 0<!>
// MODULE: platform()()(common)
// FILE: platform.kt
@@ -21,4 +21,4 @@ actual typealias A = B
<!CONFLICTING_KLIB_SIGNATURES_ERROR!>fun bar(x: B): Int = 3<!>
// NOTE: This must be REDECLARATION, see KT-59898
<!CONFLICTING_KLIB_SIGNATURES_ERROR, CONFLICTING_KLIB_SIGNATURES_ERROR, CONFLICTING_KLIB_SIGNATURES_ERROR!>val param = 0<!>
<!CONFLICTING_KLIB_SIGNATURES_ERROR, CONFLICTING_KLIB_SIGNATURES_ERROR!>val param = 0<!>
@@ -14,11 +14,6 @@ native/native.tests/testData/compilerOutput/SignatureClashDiagnostics/main.kt:10
var myVal: kotlin.Long defined in com.example.klib.serialization.diagnostics
var myVal: Long = 0L
^^^^^^^^^^^^^^^^^^^^
native/native.tests/testData/compilerOutput/SignatureClashDiagnostics/main.kt:10:1: error: platform declaration clash: The following fields have the same IR signature ([ com.example.klib.serialization.diagnostics/myVal|{}myVal[0] <- Local[<BF>|FIELD PROPERTY_BACKING_FIELD name:myVal type:kotlin.Long visibility:private [static]] ]):
var myVal: kotlin.Int defined in com.example.klib.serialization.diagnostics
var myVal: kotlin.Long defined in com.example.klib.serialization.diagnostics
var myVal: Long = 0L
^^^^^^^^^^^^^^^^^^^^
native/native.tests/testData/compilerOutput/SignatureClashDiagnostics/main.kt:10:1: error: platform declaration clash: The following functions have the same IR signature (com.example.klib.serialization.diagnostics/myVal.<get-myVal>|<get-myVal>(){}[0]):
fun `<get-myVal>`(): kotlin.Int defined in com.example.klib.serialization.diagnostics
fun `<get-myVal>`(): kotlin.Long defined in com.example.klib.serialization.diagnostics
@@ -31,11 +26,6 @@ native/native.tests/testData/compilerOutput/SignatureClashDiagnostics/main.kt:15
var myVal: kotlin.Long defined in com.example.klib.serialization.diagnostics
@Deprecated("", level = DeprecationLevel.HIDDEN)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
native/native.tests/testData/compilerOutput/SignatureClashDiagnostics/main.kt:15:1: error: platform declaration clash: The following fields have the same IR signature ([ com.example.klib.serialization.diagnostics/myVal|{}myVal[0] <- Local[<BF>|FIELD PROPERTY_BACKING_FIELD name:myVal type:kotlin.Long visibility:private [static]] ]):
var myVal: kotlin.Int defined in com.example.klib.serialization.diagnostics
var myVal: kotlin.Long defined in com.example.klib.serialization.diagnostics
@Deprecated("", level = DeprecationLevel.HIDDEN)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
native/native.tests/testData/compilerOutput/SignatureClashDiagnostics/main.kt:15:1: error: platform declaration clash: The following functions have the same IR signature (com.example.klib.serialization.diagnostics/myVal.<get-myVal>|<get-myVal>(){}[0]):
fun `<get-myVal>`(): kotlin.Int defined in com.example.klib.serialization.diagnostics
fun `<get-myVal>`(): kotlin.Long defined in com.example.klib.serialization.diagnostics