Commit Graph

368 Commits

Author SHA1 Message Date
Nikita Bobko 0d67ae7b23 [TEST] Add regression test for KT-59805 ACTUAL_MISSING for constructor 2023-12-06 18:35:39 +00:00
Nikita Bobko 2a7403a979 [FIR, IR] Run DefaultArgumentsInExpectActualizedByFakeOverride not only in FIR but in IR as well
Review: https://jetbrains.team/p/kt/reviews/13334/timeline

Thanks to the previous commit, it's now possible to run
DefaultArgumentsInExpectActualizedByFakeOverride on both: frontend (FIR)
and backend (IR).

We aim to perform a thorough examination of checks involving
fake-overrides on both FIR and IR, given their distinct implementations
for handling fake-overrides.

The commit decreases scope of influence of hacky
`shouldCheckDefaultParams` flag.
2023-12-05 13:30:14 +00:00
Nikita Bobko 1aeefe6c33 [FIR] Don't traverse expect hierarchy to check DefaultArgumentsInExpectActualizedByFakeOverride
^KT-63860 Fixed
Review: https://jetbrains.team/p/kt/reviews/13334/timeline

The previous code was nonsense (I wrote it). It doesn't make sense to
subtract actualOverriddenDeclarations from expectOverriddenDeclarations.
Default parameters are mentioned on the expect side. So default params
in expect/actual supertypes won't be subtracted from
expectOverriddenDeclarations (but should be)
2023-12-05 13:30:14 +00:00
Nikita Bobko 8c0cf7d0bc [FIR] Fix disappeared ACTUAL_MISSING
^KT-59887 Fixed

Review: https://jetbrains.team/p/kt/reviews/13244
2023-12-04 13:08:23 +00:00
Nikita Bobko e44e84d1b0 [FIR] Reuse expect/actual matching data of outer declarations during matching of inner declarations
Review: https://jetbrains.team/p/kt/reviews/13244

Motivation:
    ```
    // Module :lib
    class Foo {
        val member: Int = 2
    }

    // Module :app
    // dependencies { implementation(project(":lib")) }
    class Foo {
        val member: Int = 2
    }
    ```

    Before the commit:
        app_Foo.expectForActual is `null`
        app_Foo.member.expectForActual = lib_foo.member
    After the commit:
        app_Foo.expectForActual is `null`
        app_Foo.member.expectForActual is `null`

    If I don't fix this problem then
    `CommonizerHierarchicalIT.testCommonizeHierarchicallyMultiModule`
    becomes red after I fix KT-59887 in the following commits

    `app_Foo.member.expectForActual = lib_foo.member` happens because we
    also need to match fake-overrides (KT-63550)

I didn't measure it, but theoretically, this commit should be a
performance improvement, becuase we reuse `expectForActual` cache

Additionally, The commit breaks some other tests (e.g.
compiler/testData/diagnostics/tests/multiplatform/headerClass/actualMissing.fir.kt).
The tests will become green again, once I fix KT-59887
2023-12-04 13:08:23 +00:00
Roman Efremov 5cf33c3556 [IR] Render different quotes depending on IR constant type
This is needed for ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT diagnostic
message, but also seems to be good improvement for IR dumps in tests.

^KT-62559
2023-11-28 23:17: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 ec7a2c20d1 [FIR] Beautify ::class expression rendering in annotation arguments
...in `ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT` diagnostic message.

^KT-62559
2023-11-28 23:17:23 +00:00
Roman Efremov fa897e4148 [Tests] Cover rendering of KClass annotation args in
...`ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT`.

^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 2b120f6cdc [Tests] Cover rendering of diagnostic text by IR checker in
...`ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT`.

^KT-62559
2023-11-28 23:17:23 +00:00
Mikhail Glukhikh 2cea2b9098 K2/Java: add private enum constructor for MPP matching
#KT-62961 Fixed
2023-11-28 13:30:26 +00:00
Roman Efremov 5147a5e805 [Test] Add test for current behavior of resolution of nested class type
...when it is actualized via typealias.

^KT-31636
2023-11-27 18:23:43 +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
Roman Efremov d343e40ac5 [FIR] Actualize expect nested classes in type arguments in expect actual
...checker.

^KT-31636
2023-11-27 18:23:42 +00:00
Roman Efremov cec644e9db [Test] Add test for expect nested classes unwrapping
...in type arguments, when they were actualized via
typealias.

^KT-31636
2023-11-27 18:23:42 +00:00
Roman Efremov 4aaf290c99 [FIR] Fix incorrect matching of nested classes when actualized via typealias
There are still some places in `.fir.kt` where false-positive reports
remained. This is because of IR checker, which will be fixed in next
commit.

^KT-31636
2023-11-27 18:23:42 +00:00
Roman Efremov a768ece70d [Tests] Add tests for other checkers having same problem with
...nested classes marching.

^KT-31636
2023-11-27 18:23:42 +00:00
Roman Efremov bfc775faf5 [Tests] Create test for nested classes matching when actualized via typealias
^KT-31636
2023-11-27 18:23:42 +00:00
Dmitriy Novozhilov 039baf95fc [Test] Add empty platform module for MPP diagnostic test with only one module
After previous commits IrActualizer runs only there are at least two modules
  in backend input. So to check diagnostics from Actualizer all tests
  should contain at least two modules

Diagnostics in test `extendExpectedClassWithAbstractMember.kt` were
  changed because there is an exception from IrActualizer caused by
  errors from frontend (`ABSTRACT_METHOD_NOT_IMPLEMENTED`), which is
  swallowed by this kind of tests
2023-11-27 10:17:54 +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 e6bfcc7c65 [FIR] 2/2 update testData
This tests started failing after the previous commit. I extract this
change into a separate commit to make it obvious that appeared
diagnostics is not an expected behavior. I will fix these tests in the
following commits

Review: https://jetbrains.team/p/kt/reviews/13094/timeline
2023-11-24 18:02:47 +00:00
Nikita Bobko a1ce8ac175 [FIR] 1/2 match and check expect fake-overrides vs actuals
^KT-63550 Fixed
Review: https://jetbrains.team/p/kt/reviews/13094/timeline

Now it's required to create a new ScopeSession when searching for expect
members for actuals. If you keep reusing actualScopeSession then members
declared in platform may "slip into" the search results, resulting an
incorrect expect for actual (e.g. it happens in
supertypeIsExpectActual_covariantOverrideOfInjectedFromSuper_transitiveSubstitutionFakeOverride.fir.kt)

I suppose that it always has been a bug that we reused
actualScopeSession because we were mixing actualScopeSession and
expect FirSession (which is a bad idea), but we simply didn't have cases
where this bug could be observed. Now after we started matching
fake-overrides, we have such cases.

But creating a new ScopeSession every time is a suboptimal solution. We
need to design a scope caching KT-63773
2023-11-24 18:02:47 +00:00
Nikita Bobko 216006c504 [FIR] NO_ACTUAL_CLASS_MEMBER_FOR_EXPECTED_CLASS: report both mismatches and incompatibilites
This commit is a preparation step for KT-59887. For now,
expectActualInlineClass.fir.kt became slightly more verbose. Once is
KT-59887 fixed, the verbosity will go away. Because we won't report
incompatibilites mismatches for ACTUAL_MISSING declarations

Review: https://jetbrains.team/p/kt/reviews/13094/timeline
2023-11-24 18:02:46 +00:00
Roman Efremov fa20eb73f2 [Tests] Don't ignore expected file if diagnostic output is empty
Because of this, `checkDiagnosticFullText.fir.diag.txt` was
obsolete, because nothing was reported, but test was green.

^KT-62559
2023-11-23 12:17:34 +00:00
Roman Efremov fcc6f873c7 [FIR] Prevent reporting ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT twice in CLI
It is duplicated because we have two checkers: FIR (for IDE support
in simple cases) and IR ("honest" checker supporting all cases).
Fix this by running FIR checker only in IDE.

FIR checker behavior remains covered by tests in
`LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated`.

^KT-62559 Fixed
2023-11-23 12:17:34 +00:00
Roman Efremov 6a90926e2e [K2] Support reporting of IMPLEMENTATION_BY_DELEGATION_IN_EXPECT_CLASS
^KT-59983
2023-11-22 16:40:06 +00:00
Dmitriy Novozhilov d85d671b26 [FIR] Update few MPP diagnostic tests
Updated tests contain errors which are incompatible with fir2ir conversion
  (like `PACKAGE_OR_CLASSIFIER_REDECLARATION` and `EXPECT_AND_ACTUAL_IN_THE_SAME_MODULE`),
  so running fir2ir on such code may lead to exceptions
2023-11-20 13:36:27 +00:00
Roman Efremov 722d901d69 [Tests] Decline bug KT-62886 and change comment accordingly
^KT-62886
2023-11-15 16:47:04 +00:00
Roman Efremov 37b839f2c2 [Tests] Refactor: move one more annotation arguments lazy resolve test
for `ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT` checker near to
other tests of this diagnostic. It is fine to move it out of
`multiplatformCompositeAnalysis` dir, because, actually, it tests
the case with comparison of FirAnnotationCall and FirAnnotationImpl,
which doesn't require composite analysis mode.

^KT-62559
2023-11-10 19:36:10 +00:00
Roman Efremov 99bf96e747 [Tests] Refactor: move annotation arguments lazy resolve test for
...`ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT` checker near to
other tests of this diagnostic. This is because now such tests
are run in lazy resolve test suite, so no need to store them
separately.

^KT-62559
2023-11-10 19:36:10 +00:00
Roman Efremov c20a5fc650 [Tests] Fix .ll.kt KMP tests data added in previous commit
It is expected, that in some complex cases
`ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT` reports in .ll.kt disappeared
at all. This is because FIR checker doesn't catch comlex cases,
which are handled by IR checker.

Also add comments about bugs KT-62886 and KT-63382 found by tests.

^KT-62559
2023-11-10 19:36:09 +00:00
Roman Efremov 29980c6b85 [Tests] Run KMP tests in Analysis API LL FIR test suites
New tests are red in current commit!
All `.ll.kt` files are just copies of `.fir.kt` or `.kt`. This will be
fixed in the next commit to clearly show difference between LL and FIR.

The original purpose of this change was to test
`ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT` diagnostic, for which FIR checker
will be run only in IDE (to be changed in next MR), so its reports
a lost from usual KMP tests.
But this looks like a useful change for all KMP tests, not only this
diagnostic.

^KT-62559
2023-11-10 19:36:09 +00:00
Roman Efremov 026ad1cebc [Tests] Refactor: move unrelated tests out of annotationMatching dir
It will be used only for ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT
diagnostic tests.

^KT-62559
2023-11-10 19:36:09 +00:00
Dmitriy Novozhilov fe66f3a384 [FIR2IR] Manage constructor symbols in declaration storage instead of declaration generator
This is needed to be able to implement creation of unbound symbols
  for references of corresponding declarations (KT-62856)

There was an exception from FIR2IR that was fixed with this change,
 so fir2ir test SuperClass started to pass along with IrActualizer,
 which reported some new errors
2023-11-09 10:43:31 +00:00
Dmitriy Novozhilov 3c0f153de4 [FIR2IR] Manage function symbols in declaration storage instead of declaration generator
This is needed to be able to implement creation of unbound symbols
  for references of corresponding declarations (KT-62856)

There was an exception from FIR2IR that was fixed with this change,
  so fir2ir test expectDeclarationWithWeakIncompatibilities started to
  pass along with IrActualizer, which reported some new errors
2023-11-09 10:43:31 +00:00
Kirill Rakhman eba1fdec1d [Tests] Check for duplicate file names in FIR diagnostic tests with IR
The relative path of a test file is just its name, even if it's in a
module.
Diagnostics in IR are mapped to the file path and so it's reported on
all files with the same path, i.e. name.
This doesn't happen in production code because no two files can have
the same path.

The proper fix would be to prefix the test files' paths with the module
name.
Unfortunately, this breaks a bunch of test runners that rely on the
current behavior.
Especially, some JS runners turned out to be hard to fix.
The linked YouTrack issue contains a WIP, incomplete patch of fixing
some runners.

#KT-61592 Fixed
#KT-63252
2023-11-08 08:25:19 +00:00
Nikita Bobko 45c5fd7a2d [FE] Introduce a language feature entry for expect actual classes
^KT-62885 Fixed
2023-11-07 20:05:59 +00:00
Nikita Bobko 7b8445f914 [FIR] 2/2 Support more wider actual member visibility, if the expect member is effectively final
^KT-61955 Fixed

Introduce LV vs don't introduce LV:

introduce LV:
- K1 IDE and K2 project: IDE accurately shows compiler errors
- K2 IDE and K1 project: There are cases when IDE shows red but in reality it's green

don't introduce LV:
- K1 IDE and K2 project: There are cases when IDE shows red but in reality it's green
- K2 IDE and K1 project: There are cases when IDE shows green but in reality it's red
2023-11-07 15:53:54 +00:00
Nikita Bobko d6acba1c33 Add regression tests for final expect classes overrides that change modality
KT-61840
Specifically see the comment:
https://youtrack.jetbrains.com/issue/KT-61840/K2-support-changes-in-overrides-of-fake-overrides-of-expect-declarations#focus=Comments-27-8077580.0-0

Review: https://jetbrains.team/p/kt/reviews/12147/timeline
2023-11-07 10:24:35 +00:00
Nikita Bobko 75a0442b61 [FIR] 2/2 Cleanup: drop no longer necessary FirActualCallableDeclarationChecker
It became possible to drop it after KT-62590. Now, on a frontend, the
return type check is part of a common AbstractExpectActualChecker logic

Change in nestedAnnotationClassViaActualTypealias.fir.kt aligns the
behaviour with K1. KT-61964

Review: https://jetbrains.team/p/kt/reviews/12750/timeline
2023-11-06 14:41:23 +00:00
Nikita Bobko a9583e4f9a [FIR, IR] 1/2 Align FirExpectActualMatchingContextImpl.areCompatibleExpectActualTypes with ExpectActualUtilsKt.areCompatibleExpectActualTypes
Those two functions are copy-paste of each other. They diverged since
the time they were copy-pasted. This commit makes
FirExpectActualMatchingContextImpl.areCompatibleExpectActualTypes
up-to-date.

I didn't update ExpectActualUtilsKt.areCompatibleExpectActualTypes
because I will drop it in the next commit.

Change in `dynamicTypesEqualToAnything` doesn't change any logic (yet.
This change in logic will take effect in the next commit), because:
1. `dynamicTypesEqualToAnything` is only changed in
AbstractExpectActualChecker.getCallablesCheckingIncompatibility. But
AbstractExpectActualChecker.getCallablesCheckingIncompatibility doesn't
check return types on frontend (it only check return types on backend).
2. `dynamicTypesEqualToAnything` is ignored on IR backend

I have no idea what is the difference between `createTypeCheckerState()`
and `actualSession.typeContext`, but it aligns these copy-pasted
versions and makes the tests behave like in K1 (at least
'typeUsageWithUnresolvedReference' and 'kt57320' are affected)

This commit is mainly a preparation for the next commit.

Review: https://jetbrains.team/p/kt/reviews/12750/timeline
2023-11-06 14:41:23 +00:00
Nikita Bobko ddc1ae9ac6 [IR] Split INCOMPATIBLE_MATCHING to EXPECT_ACTUAL_MISMATCH & EXPECT_ACTUAL_INCOMPATIBILITY
KT-62590

Review: https://jetbrains.team/p/kt/reviews/12750/timeline
2023-11-06 14:41:22 +00:00
Nikita Bobko 60e5a9c298 [IR] Update testData INCOMPATIBLE_MATCHING
^KT-62916 Fixed
(well, actually it got fixed in one of my previous commits, but it's
hard to track)

Review: https://jetbrains.team/p/kt/reviews/12750/timeline
2023-11-06 14:41:21 +00:00
Nikita Bobko 76ffbcc67c [IR] Update testData ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT
After previous commits, IrExpectActualAnnotationMatchingChecker reports
errors even if the declaration is incompatible but matched

We had a duplicated diagnostic in other cases before my commits, anyway.
it will be fixed in
https://youtrack.jetbrains.com/issue/KT-62559/KMP-K2-prevent-reporting-ACTUALANNOTATIONSNOTMATCHEXPECT-twice-in-CLI#focus=Comments-27-8293687.0-0

Review: https://jetbrains.team/p/kt/reviews/12750/timeline
2023-11-06 14:41:20 +00:00
Nikita Bobko 8722e142f6 [IR] 2/2 Propogate expect-actual checker incompatibilities to IR backend
Review: https://jetbrains.team/p/kt/reviews/12750/timeline
2023-11-06 14:41:20 +00:00
Nikita Bobko 664b9cc3ba [FIR, IR] ClassScopes incompatibility: split unfulfilled incompatibilities into "mismatchedMembers" and "incompatibleMembers"
KT-62590 is in progress

Unfortunatelly, ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT is now reported
twice in 'classScopeViaTypealiasIncompatible' test.

We had a duplicated diagnostic in other cases before my commits, anyway.
it will be fixed in
https://youtrack.jetbrains.com/issue/KT-62559/KMP-K2-prevent-reporting-ACTUALANNOTATIONSNOTMATCHEXPECT-twice-in-CLI#focus=Comments-27-8293687.0-0

Review: https://jetbrains.team/p/kt/reviews/12750/timeline
2023-11-06 14:41:19 +00:00
Nikita Bobko bc5180656d [FIR] ReturnType expect-actual incompatibility: convert from strong to weak
It should have been WeakIncompatible from the beginning because it's not
possible to overload by return type in Kotlin

This commit is a step forward to fix KT-62591

Unfortunately, the test cannot demonstrate the problem because of
another bug in K2 KT-59887

^KT-62752 Fixed
Review: https://jetbrains.team/p/kt/reviews/12750/timeline

Motivation:

It makes expect-actual matching-checking model more consistent.

expect-actual "matching" is run before FirResolvePhase.BODY_RESOLVE. You
can't know return types, until you run BODY_RESOLVE. That's why the
return type can't be checked during expect-actual matching. But it's
cursed: you have something that have to match by, but, at the same time,
you can't do it.

expect-actual "checking" is run after FirResolvePhase.BODY_RESOLVE.
That's why if we convert ReturnType incompatibility to WeakIncompatible
(which should have been called CheckingIncompatible), then expect-actual
matching model becomes consistent.

We will also be able to get rid of unnecessary
FirActualCallableDeclarationChecker. Because it won't be necessary.
Return types will be checked by common logic of expect-actual "checker"
2023-11-06 14:41:16 +00:00
Nikolay Lunyak b8e2a17de1 [Test] Fix diagnostics arguments rendering when quotes are present
Non-capturing `(?:)` was now needed to avoid
getting an additional group that only
contains the last symbol before the closing `"`.

^KT-62711 Fixed
2023-11-03 08:14:28 +00:00