Commit Graph

30 Commits

Author SHA1 Message Date
Nikita Bobko 4c602585b0 [FIR, IR] Cleanup: drop unused allowClassActualizationWithWiderVisibility & allowTransitiveSupertypesActualization
These flags were used when ExpectActualMatchingContext was reused in K1.
2024-02-25 18:18:55 +00:00
Pavel Kunyavskiy 21ae6e46b7 [IRFakeOverrides] Also replace special symbols in annotations
This fixes some crashes on red code in diagnostic tests.
Also can be useful in the future, when we would allow things like
enum.name in annotation arguments.

^KT-65971
2024-02-21 22:10:29 +00:00
Alexander Udalov 39327a37cb IR: pass also unsubstituted member to external conditions
In the future version of JavaIncompatibilityRulesOverridabilityCondition
for IR, we need to compute the original JVM signature of a declaration.
In descriptors, it's possible simply by using `original`.
2024-01-19 12:30:48 +00:00
Pavel Kunyavskiy 882dc18e0e [IrActualizer] Don't copy attributeOwnerId in actualizer
In before, actualizer was copying attributeOwnerId to new
nodes. This leads to attributeOwnerId linked to non-actualized
node. It's unclear what it leads to, so we just stop doing that.

In particular, if attributeOwnerId references another node,
this information would be lost.

^KT-64895
2024-01-15 14:10:35 +00:00
Nikita Bobko 013b5e3780 [IR] Fix missing AMBIGUOUS_ACTUALS
^KT-59938 Fixed
Review: https://jetbrains.team/p/kt/reviews/13760

After this patch:

    > The /compiler/testData/diagnostics/tests/multiplatform/topLevelFun/conflictingImplDeclarations.kt test:

    Fixed

    > The /compiler/testData/diagnostics/tests/multiplatform/headerClass/expectDeclarationWithWeakIncompatibilities.kt test:

    Declarations are in the same module. `PACKAGE_OR_CLASSIFIER_REDECLARATION` is reported anyway

    > The /compiler/testData/diagnostics/tests/multiplatform/java/varPropertyAgainstJavaGetterAndNonFinalField.kt test:

    Expect-actual matcher doesn't match fields in K2 https://youtrack.jetbrains.com/issue/KT-63667 => green code

    > The /compiler/testData/diagnostics/tests/multiplatform/java/propertyAgainstJavaPrivateFieldAndPublicMethod.kt test:

    Expect-actual matcher doesn't match fields in K2 https://youtrack.jetbrains.com/issue/KT-63667 => green code

    > The /compiler/testData/diagnostics/tests/multiplatform/java/implicitJavaActualization_multipleActuals.kt test:

    K2 doesn't have implicit Java actualization. And PACKAGE_OR_CLASSIFIER_REDECLARATION is reported anyway

    > The /compiler/testData/diagnostics/tests/multiplatform/java/propertyAgainstJavaPublicFieldAndPublicGetter.kt test:

    Expect-actual matcher doesn't match fields in K2 https://youtrack.jetbrains.com/issue/KT-63667 => green code

    > The /compiler/testData/diagnostics/tests/multiplatform/actualClassifierMustHasTheSameMembersAsNonFinalExpectClassifierChecker/injectContextReceiverOverload.kt test:

    Context receivers are not supported in expect-actual matcher. https://youtrack.jetbrains.com/issue/KT-61447
    And K2 reports another error right now anyway
2024-01-10 08:08:42 +00:00
Pavel Kunyavskiy 9374cacdd6 [IrActualizer] Don't actualize expect types
This was never semantically correct, but was not important
before KT-63644, as they were immediately dropped after that anyway.

After KT-63644, they were used to compute fake overrides inside them,
which were later matched against actual class, which can
produce false-positive matching errors.

^KT-64835
2024-01-09 17:53:06 +00:00
Pavel Kunyavskiy c0f0c595c3 [IR Actualizer] Don't crash on incorrect code 2024-01-08 07:46:07 +00:00
Nikita Nazarov 438b2dd164 [K2, MPP] Actualize value class representation
^KT-63638 fixed
2024-01-03 16:39:56 +00:00
Roman Efremov 30aad31ece [FIR, IR] Prohibit actualization of expect Kotlin property to Java field
The problem from KT-63624 was that during matching phase we must choose
only one candidate, but in Java we can have two successfully matched
properties: 1) from field and 2) from method, which overrides Kotlin
property.
See test `propertyAgainstJavaPrivateFieldAndPublicMethod.kt`.
As a result, we choose field candidate, throw away method candidate, and
then fail during visibility check.

Instead of inventing special rule of prioritizing field over method
it was decided to prohibit actualization to Java field at all because:

1. It doesn't seem that Java fields actualization was implemented in K1
on purpose
2. People usually don't use public Java fields, and use instead
private field + getter, especially when compatibility is important, so
it shouldn't be a breaking change

Besides that, such solution simplifies code and is consistent with
the current logic of matcher, which doesn't expect that two members
can be matched successfully. Also, it fixes KT-63624 and KT-63667.

^KT-63624 Fixed
^KT-63667 Fixed
2023-12-20 13:37:43 +00:00
Pavel Kunyavskiy f50fab65cc [IrActualizer] Update doc on how the actualization process works. 2023-12-15 15:38:10 +00:00
Pavel Kunyavskiy dcd3f3b155 [FIR2IR] Replace fake override symbols with normal ones
Fir2Ir introduces temporary symbols to avoid creating
fake overrides themselves. Further pipeline is not ready to
these symbols. That's why we have introduced separate pass,
that replaces all this symbols with real fake override
symbols, after they are created.

^KT-63645
2023-12-15 15:38:10 +00:00
Pavel Kunyavskiy c485382e80 [FIR2IR] Rework actualization pipeline
There are a lot of restrictions between different parts of the pipeline.

1. Fake overrides can't be built before classes are actualized
2. Constants can't be evaluated before callables are actualized
3. Callables can't be actulaized before fake overrides are built
4. Checkers can't run before constants are evaluated

This commit reorders things to make all these restrictions happy.

^KT-63644
2023-12-15 15:38:10 +00:00
Nikita Bobko 599998039e [IR] Use resolveFakeOverrideMaybeAbstract instead of resolveFakeOverride in hasStableParameterNames
Well, the resolved fake-override can be ABSTRACT

^KT-64045 Fixed
2023-12-14 11:23:51 +00:00
Dmitriy Novozhilov 7d685522ce [IR] Fix calculation of receiver type for properies in expect/actual context
^KT-62926 Fixed
2023-12-08 13:28:27 +00:00
Nikita Bobko 48fdeeb42d [FIR, IR] Cleanups around allRecursivelyOverriddenDeclarationsIncludingSelf
- Pass containingClass (helps to avoid calculations of the
  containingClass in allRecursivelyOverriddenDeclarationsIncludingSelf
  implementation)
- Reuse allRecursivelyOverriddenDeclarationsIncludingSelf by
  DefaultArgumentsInExpectActualizedByFakeOverride &
  ActualFunctionWithDefaultParameters

Review: https://jetbrains.team/p/kt/reviews/13244
2023-12-04 13:08:23 +00:00
Roman Efremov 8f6b6e17be [IR] Print annotation arguments in report of ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT
Now IR checker is not duplicated by FIR checker reporting, so it's
useful to have more verbose report of annotations in diagnostic message.

^KT-62559
2023-11-28 23:17:23 +00:00
Roman Efremov 29c82c668f [IR] Prevent duplicated reports of ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT
...on property accessors and enum entries.

^KT-62559
2023-11-28 23:17:23 +00:00
Roman Efremov 205690b220 [IR] Fix incorrect matching of nested classes when actualized via typealias
Also, add tests for the cases when expect and actual nested classes
have no compatible matching to check new logic doesn't crash.

^KT-31636
2023-11-27 18:23:42 +00:00
Nikita Bobko 7166adb179 [FIR, IR] Convert FirDefaultArgumentsInExpectActualizedByFakeOverrideChecker into ExpectActualCheckingCompatibility
FirDefaultArgumentsInExpectActualizedByFakeOverrideChecker is an adhoc
checker which can be converted to ExpectActualCheckingCompatibility to
reuse common expect-actual checking infrastructure.

^KT-62913 Fixed
Review: https://jetbrains.team/p/kt/reviews/13094/timeline

Tests that were broken by one of my previous commits are now fixed:
- actualFakeOverride_paramsAreCompatibleViaSharedMethodWithDefaultParams.kt
- inheritedJavaMembers.kt

DEFAULT_ARGUMENTS_IN_EXPECT_ACTUALIZED_BY_FAKE_OVERRIDE diagnostic
disappeared in delegation.fir.kt because only one
AbstractExpectActualChecker incompatibility can be reported at a time
(DEFAULT_ARGUMENTS_IN_EXPECT_ACTUALIZED_BY_FAKE_OVERRIDE is now reported
not by adhoc checker but by common AbstractExpectActualChecker). It
would be nice to report both of them, but it's a separate issue KT-62631

delegation2 test makes sure that
DEFAULT_ARGUMENTS_IN_EXPECT_ACTUALIZED_BY_FAKE_OVERRIDE is reported when
NO_ACTUAL_CLASS_MEMBER_FOR_EXPECTED_CLASS is fixed
2023-11-24 18:02:49 +00:00
Nikita Bobko 5b72c127bd [FIR, IR] Commonize isFakeOverride check for AbstractExpectActualAnnotationMatchChecker
This commit fixes fakeOverrides.fir.kt test that got broken in the
previous commit

Previously isFakeOverride was only checked on IR backend. Now this check
is moved to AbstractExpectActualAnnotationMatchChecker which is used by
both: frontend and backend. That's why frontend no longer reports false
positive ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT

Review: https://jetbrains.team/p/kt/reviews/13094/timeline
2023-11-24 18:02:48 +00:00
Nikita Bobko 93cf68a08d [IR] IrExpectActualAnnotationMatchingChecker: add elaboration comment
Review: https://jetbrains.team/p/kt/reviews/13094/timeline
2023-11-24 18:02:46 +00:00
Pavel Kunyavskiy b38ebbb853 [IR] Avoid ir.actualization depending on frontend module
^KT-62292
2023-11-20 08:31:41 +00:00
Pavel Kunyavskiy 021a00f4ff [IR] Avoid depending from fir2ir on ir.actualization module
^KT-62292
2023-11-20 08:31:41 +00:00
Pavel Kunyavskiy cf6792ec65 [IR] Optimize dependencies of ir.actualization module
^KT-62292
2023-11-20 08:31:41 +00:00
Pavel Kunyavskiy 55e7ff18c6 [IR] Extract IrActualizationErrors from CommonBackendErrors
^KT-62292
2023-11-20 08:31:41 +00:00
Pavel Kunyavskiy 763d2ec2fe [IR] Move IrGetValue.actualize() to IrUtils and rename it
^KT-62292
2023-11-20 08:31:41 +00:00
Pavel Kunyavskiy e80d4b1d60 [IR] Move IrDeclaration.isExpect to IrUtils
^KT-62292
2023-11-20 08:31:41 +00:00
Pavel Kunyavskiy 41098a2e34 [IR] Extract IrDiagnosticReporter interface
^KT-62292
2023-11-20 08:31:41 +00:00
Pavel Kunyavskiy faaefbd8e7 [IR] Move .parents and .parentsWithSelf to IR utils
^KT-62292
2023-11-20 08:31:41 +00:00
Pavel Kunyavskiy 649a7bd66b [IR] Moved actualizer and related things to separate module
^KT-62292
2023-11-20 08:31:41 +00:00