Commit Graph

13 Commits

Author SHA1 Message Date
Andrei Tyrin 4e10dcd808 [tests] Klib based signature clash improve coverage for KT-63670 2024-02-27 14:01:44 +00:00
Nikita Bobko 7924573d20 [FIR] Report redeclaration across KMP source sets
^KT-57585 Fixed

Related tests:
- MultiPlatformIntegrationTestGenerated.testSimpleNoImplKeywordOnTopLevelFunction
- MultiPlatformIntegrationTestGenerated.testWeakIncompatibilityWithoutActualModifier
- FirPsiJsKlibDiagnosticsTestGenerated.testSignatureClash_MPP
- LLFirPreresolvedReversedDiagnosticCompilerFirTestDataTestGenerated$ResolveWithStdlib$MultiModule.testFakeOverrides
- DiagnosticCompilerTestFE10TestdataTestGenerated$Tests$Multiplatform:
- LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated$Tests$Multiplatform
- FirOldFrontendMPPDiagnosticsWithPsiTestGenerated
- FirOldFrontendMPPDiagnosticsWithLightTreeTestGenerated
- FirLibraryModuleDeclarationResolveTestGenerated.testDataClass
- org.jetbrains.kotlin.idea.k2.highlighting.K2HighlightingMetaInfoTestGenerated$Diagnostics.testDataClassFromLibrary
- org.jetbrains.fir.uast.test.FirLightClassBehaviorTest.testContainingFile
- org.jetbrains.fir.uast.test.FirLightClassBehaviorTest.testAnnotationParameterReference
- org.jetbrains.uast.test.kotlin.org.jetbrains.uast.test.kotlin.comparison.FE1LightClassBehaviorTest.testContainingFile
2024-02-22 16:06:36 +00:00
Sergej Jaskiewicz 5836067082 [klib] Add error suppression to a signature clash diagnostic test
Currently, REDECLARATION is not reported if two conflicting declarations
are in different source sets (KT-59898). However, when it's fixed,
we want this test to keep testing the signature clash diagnostic,
and not fail because of unexpected REDECLARATION error.
2024-02-12 11:22:47 +00:00
Sergej Jaskiewicz f26e470e80 [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
2024-02-12 11:22:46 +00:00
Sergej Jaskiewicz 4c06673483 [klib] Add a test for clashing signatures in property delegates 2024-02-09 16:45:34 +00:00
Sergej Jaskiewicz 0c0943a880 [klib] Add a test for KT-65551 2024-02-09 16:45:34 +00:00
Sergej Jaskiewicz 03ca64c954 [klib] Make CONFLICTING_KLIB_SIGNATURES_DATA diagnostic more precise
Show what kind of declarations exactly are clashing: functions,
properties, or fields.

This is so that diagnostics about clashing properties and fields are
distinguishable from one another, since properties and fields
are rendered the same way in those diagnostics:
2024-02-09 16:45:34 +00:00
Sergej Jaskiewicz d80a67652f [klib] Fix NIE when showing signature clash diagnostics on properties
The issue was that when rendering declarations in
the `CONFLICTING_KLIB_SIGNATURES_DATA` diagnostics, we sort them using
`MemberComparator`. That comparator falls back to comparing
declarations' renders if all previous checks were unsuccessful
(and in case of almost identical properties they are). The renderer that
the comparator uses also renders the properties' backing field
annotations, for which it calls `PropertyDescriptor#getBackingField`.
That method wasn't implemented in IR-based descriptors.

This is fixed by returning an instance of the new
`IrBasedBackingFieldDescriptor` class from that method.

^KT-65551 Fixed
2024-02-09 16:45:34 +00:00
Sergej Jaskiewicz 06684f207a [klib] Don't rely on Lazy IR for signature clash checking
We only want to report signature clashes for declarations that come
from the module currently being serialized. In GlobalDeclarationTable,
declarations from other modules could also be stored.
Checking whether a declaration is a Lazy IR declaration to
determine if it comes from an external module works okay, but it is
a hack which relies on an implementation detail of IR, which may or
may not work in the future.

Use a more robust logic here, since IrFileSerializer is always aware
which declarations are declared in the current module and which are
just referenced from it.
2024-02-05 17:30:08 +00:00
Sergej Jaskiewicz f84fa29fef [klib] Add a test ensuring that signature clash detection works w/ MPP 2024-01-30 20:47:09 +00:00
Sergej Jaskiewicz 03aa14b473 [klib] Use "IR signatures" i/o "KLIB signatures" in diagnostics
We already use the term "IR signatures" in other places.
2024-01-30 20:47:09 +00:00
Sergej Jaskiewicz 6900e20096 [klib] Fix exception for clashing signatures from different modules
If we encounter a declaration in the current module whose signature
is the same as that of a declaration in another module which we happen
to also reference from the current module, don't report any errors,
just like we don't do it in Kotlin/JVM. This leaves the user in the KLIB
hell situation, but this is intentional, because otherwise a legitimate
change like moving a declaration to another module and marking
the original one as `@Deprecated("", level = DeprecationLevel.HIDDEN)`
would lead to a error, and we don't want that.

Also, don't try to show the diagnostics on a declaration that doesn't
have an IrFile.

^KT-65063 Fixed
2024-01-30 20:47:09 +00:00
Sergej Jaskiewicz eda30ff704 [klib] Implement diagnostics for clashing KLIB signatures
Now, we detect clashing signatures during serialization to KLIB and
report a compiler error if two or more declarations have the same
`IdSignature`

For example, for the following code:
```kotlin
@Deprecated("", level = DeprecationLevel.HIDDEN)
fun foo(): String = ""

fun foo(): Int = 0
```

the compiler will produce this diagnostic:
```
e: main.kt:1:1 Platform declaration clash: The following declarations
       have the same KLIB signature (/foo|foo(){}[0]):
    fun foo(): String defined in root package
    fun foo(): Int defined in root package
e: main.kt:4:1 Platform declaration clash: The following declarations
       have the same KLIB signature (/foo|foo(){}[0]):
    fun foo(): String defined in root package
    fun foo(): Int defined in root package
```

Note that we report this diagnostic during serialization and not earlier
(e.g., in fir2ir) for more robustness, so ensure that we check
exactly the signatures that will be written to a KLIB.
If we later introduce some annotation for customizing a declaration's
signature (e.g., for preserving binary compatibility), this
diagnostic will continue to work as expected.

^KT-63670 Fixed
2024-01-12 15:59:28 +00:00