206 Commits

Author SHA1 Message Date
Marco Pennekamp 1374bc8e2d [LL] Implement a common LLSealedInheritorsProvider
- The new `LLSealedInheritorsProvider` is based on the previous
  sealed inheritors provider implementation in the IDE. It uses the
  new direct inheritors provider and the module dependents provider to
  implement the same functionality that was previously confined to the
  IDE. With this design we avoid duplication of complex logic such as
  the KMP handling in `searchInheritors`.
- The implementation is designed to work in the production Standalone
  mode and the aforementioned services have already been implemented for
  Standalone in prior commits. Now we can get rid of the problematic
  `SealedClassInheritorsProviderForTests` and tests should more closely
  match production behavior.
- In IDE mode tests, `LLSealedInheritorsProvider` is used with
  Standalone Analysis API provider implementations. This is in line with
  the rest of the test infrastructure, where Standalone AA providers are
  generally used, as IDE providers aren't available.
- `KotlinSealedInheritorsProvider` is made obsolete by the common sealed
  inheritors provider.

^KT-66013 fixed
^KT-64505 fixed
2024-03-18 21:14:36 +00:00
Kirill Rakhman 8443daf78d [FIR] Remove FirNamedArgumentExpressions during completion
They are mostly necessary for argument mapping during resolution.
To support a couple checkers, we transform named args for varargs
into "fake" spread expressions.

Other than that, named arguments aren't needed for anything and often
lead to bugs where we forget to unwrap them for something, so it's
better to get rid of them.

#KT-66124
2024-03-13 17:05:48 +00:00
Kirill Rakhman 03fc0fd381 [FIR] Remove FirLambdaArgumentExpression
It's not really necessary if the information about if the lambda was a
trailing lambda can be directly saved in FirAnonymousFunctionExpression.

Removing the FIR node uncovered a couple of bugs
(UNINITIALIZED_ENUM_ENTRY, ERROR_IN_CONTRACT_DESCRIPTION) that were
caused by assuming that a lambda is always a trailing lambda.

#KT-66124
2024-03-13 17:05:48 +00:00
Ivan Kylchik 61fabc02ba [K2] Resolve bodies of const properties during IMPLICIT_TYPES_BODY_RESOLVE
This is required to implement constant evaluator on the FIR level.

#KT-64151
2024-03-13 16:53:59 +00:00
Ivan Kylchik 0ebf2862a9 [K2] Add new tests on lazy resolve to check new resolve rules
In the consequent commits, there are some changes in FIR resolve.
These tests will show the difference.

#KT-64151
2024-03-13 16:53:59 +00:00
Roman Efremov 284d5437e5 [FIR] Don't transform call arguments during TYPES phase
Instead, it should happen during BODY_RESOLVE phase.

This fixes KT-66150. The problem was, that `super<B>.f()` expression
in delegated constructor call was transformed during TYPES phase,
and type transformer has no special logic for allowing bare types in
super qualifiers, like the one in expressions transformer (see
`org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirExpressionsResolveTransformer.transformSuperReceiver`).
As a result, `B` without type argument leads to
WrongNumberOfTypeArgumentsError.
It looks incorrect that expressions in constructor call resolved
during TYPES phase, so skipping transformation of
argument list seems like the best solution here.

^KT-66150 Fixed
2024-03-13 14:31:14 +00:00
Roman Efremov c4f89ab32e [Test] Add test reproducing incorrect error in K2 about super qualifier
...with type arguments.
Also, add lazy resolve test to check the subsequent changes are correct.

^KT-66150
2024-03-13 14:31:14 +00:00
Kirill Rakhman 8a90032e93 [FIR] Refactor deferred computation of callable copy return types
Rename some classes for clarity and move the implementations to the use
sites.
2024-03-12 10:29:43 +00:00
Denis.Zharkov 81414d758d K2: repeat K1 representation for flexible type parameters
This commit changes the behavior of KT-59138 effectively declining it in 2.0.
However, we plan to implement KT-59138 behavior under a feature
flag in 2.0 (see KT-66447), and switch this feature on version 2.x.

Also, this commit implements the LC resolution about postponing
KT-57014 change. We don't have KT-57014 described behavior in 2.0 anymore.
However, we plan to implement a deprecation warning here, see KT-65578.

After this commit, 6 diagnostic tests become incorrectly broken:
- 5 tests from PurelyImplementedCollection group
- a test platformTypes/nullableTypeArgument.kt

This commit also breaks currently fixed-in-k2 KT-50134
(it is fixed again in the following commits),
as well as KT-58933 (it will remain not fixed till we enable KT-59138
behavior again).

#KT-65596 In Progress
#KT-57014 In Progress
#KT-58933 Submitted
2024-03-11 13:38:05 +00:00
Roman Golyshev b765cf3f99 KT-66411 [AA] Add fake source kind for single expression block around array assignments
A wrapper block was introduced as a part of fixing KT-59748, but was
assigned a real source, which had `getOrBuildFir` confused because
of the incorrectly built `KtToFirMapping`

It is relevant for:
- `if`, `when` expressions with an assignment as a single expression
- Kotlin code fragments,
when the assignment is being analysed as a single expression
in the fragment

^KT-66411 Fixed
2024-03-10 15:35:47 +00:00
Roman Golyshev ec06654a73 KT-66411 [AA] Add test for the getOrBuildFir on array assignment expression as a single when/if branch expression 2024-03-10 15:35:47 +00:00
Dmitrii Gridin 8cc2208c00 [LL FIR] support lazy resolution tests for scripts with custom definition
^KT-66276
^KT-66232
2024-03-07 12:50:59 +00:00
Dmitrii Gridin d5cfea330b [LL FIR] support parameters resolution
Script parameters now can be resolved independently of the script.
But, as parameters are part of the script, their resolve will be called
before the script.

^KT-66276 Fixed
2024-03-07 12:50:59 +00:00
Dmitrii Gridin 1ba81fca57 [Analysis API] add tests on incomplete function type parameter symbol
^KT-65858 Obsolete
2024-03-06 16:09:43 +00:00
Ivan Kylchik 5fe3fa878e [Test] Fix LL FIR test data after introducing new CONSTANT_EVALUATION phase
#KT-64151
2024-03-06 11:35:41 +00:00
Dmitrii Gridin 4d04546652 [FIR] FirPlatformDeclarationFilter: add missed lazy resolve call
`isFunctionAvailable` can be called from `PlatformDependentFilteringScope`
on unresolved declarations during `STATUS` phase

^KT-66268 Fixed
2024-03-03 22:00:06 +00:00
Dmitrii Gridin f844b87f75 [LL FIR] FirElementBuilder: do nothing for KtAnnotation
We shouldn't try to find FIR for such elements as they just don't
exist in FIR

^KT-65780
2024-03-01 19:19:00 +00:00
Dmitrii Gridin 62ec189924 [LL FIR] add getOrBuildFir for KtAnnotation
^KT-65780
2024-03-01 19:19:00 +00:00
Dmitrii Gridin 16878ca20d [LL FIR] FirElementBuilder: support KtAnnotation in file annotations
^KT-65780
2024-03-01 19:19:00 +00:00
Dmitrii Gridin ba92fc97f9 [LL FIR] add test on annotation with [] syntax
^KT-65780
2024-03-01 19:19:00 +00:00
Dmitrii Gridin 17c128adf2 [FIR] get rid of FirFileAnnotationsContainer
This element has been introduced to simplify resolution logic in LL FIR,
but now this element is redundant and only complicates the code as after
KT-56683 `FirFile` has real phases

^KT-65876 Fixed
2024-03-01 19:19:00 +00:00
Marco Pennekamp beb40484dd [LL] Add LLFirSession invalidation tests
- This commit moves all session invalidation tests from the IDE which
  are non-cyclic to the Analysis API. Cyclic session invalidation tests
  cannot be moved because the Kotlin test infrastructure doesn't support
  cyclic module dependencies.
- In fact, these new tests cover more cases, because the IDE tests only
  covered global module state and module out-of-block modification
  events. Crucially, global source modification events are now
  supported, which require libraries to be left alone.
- Module out-of-block modification for libraries is technically
  undefined, but the test still checks this behavior. The current
  session invalidation implementation behaves the same for any kind of
  module-level modification event, so it is possible to publish a module
  OOBM event for libraries. If this changes in the future, we can
  disable those tests. But for now, it's good that these tests run,
  because they will alert us to (accidental) changes to this behavior.

^KT-56288 fixed
^KT-65265 fixed
2024-02-28 21:08:18 +00:00
Dmitrii Gridin fe4ead751f [LL FIR] LLFirTargetResolver: do not resolve file annotation container before each declaration
We don't have to resolve `FirFileAnnotationsContainer` before each
declaration.
This became possible after KT-65345 as now `FirDesignation` has `FirFile`
in its path so, `PersistenceContextCollector#collectContext` resolves
it as well as we don't have problems with unresolved annotations
during diagnostics processing

^KT-65876
2024-02-28 17:10:32 +00:00
Marco Pennekamp 5819f4eaa2 [LL FIR] Test resolve extension disposal after modification events
- These tests simply ensure that a resolve extension is disposed after
  any kind of modification event is raised. It's not meant to test
  complex scenarios, but rather to detect when resolve extension
  disposal isn't invoked *at all*.
- I tried implementing a similar test for resolve extension disposal
  after soft reference garbage collection, but the only way to force the
  GC to collect soft references is to allocate memory until an
  out-of-memory error occurs. That is bad for the test infrastructure,
  because it might allocate A LOT of memory (depending on the max heap),
  which is problematic for running tests locally. Also, our Kotlin tests
  stop on an OOM error altogether (so additional configuration would be
  required) and the heap is dumped into a 20GB file (on my machine),
  which is again problematic for local test runs.

^KT-61222
2024-02-27 16:45:52 +00:00
Marco Pennekamp e62038f5f3 [AA] Tests: Rewrite sealed class inheritors collection to use the declaration provider
- Now that binary libraries are decompiled to stubs instead of PSI
  files, we cannot collect sealed inheritors from `KtFile`s anymore.
  Since all `KtFile`s and binary library stubs are both indexed by the
  declaration provider, we can collect inheritors from its index
  instead.
- Invalidating all sessions at the end of `prepareSealedClassInheritors`
  fixes some improper resolve phases in lazy resolution test data. While
  the previous implementation requested an uncached resolve session, it
  didn't account for sessions of dependencies still being cached.

^KT-65960
2024-02-26 21:57:23 +00:00
Marco Pennekamp 78ef58bef4 [AA] Tests: Remove decompiled files from LibraryBinary and add LibraryBinaryDecompiled
- `LibraryBinary` should not contain any decompiled files, as we want
  FIR symbols in tests to be provided from indexed stubs or class files,
  but definitely not from decompiled PSI. This brings `LibraryBinary`
  much closer to the behavior of binary libraries in the IDE.
- Some tests may still require access to a decompiled file, for example
  when trying to test `getOrBuildFir` for some `KtElement` coming from a
  library. This commit introduces `LibraryBinaryDecompiled`, which
  does contain decompiled files.
- We don't really need `LibraryBinary` as a main test module kind
  anymore, since tests generally want to access some main `KtFile`.
  Hence, test configurators for `LibraryBinary` have been turned into
  configurators for `LibraryBinaryDecompiled`.
- An alternative would be decompiling files on demand, but this is not
  currently feasible because the Standalone API doesn't reconcile stubs
  with decompiled PSI, like the IDE does automatically. (For the same
  declaration, the stub and the PSI will have a different identity.) As
  long as there is no support for this, we'll have to rely on a separate
  test module kind.

^KT-65960
2024-02-26 21:57:23 +00:00
Marco Pennekamp ea2bb32bc0 [PSI] Don't calculate ClassIds for local classes in call elements
- The fix uses relevant logic from  `getNonLocalContainingDeclaration`.
- The annotation entry case is covered by `KtCallElement` because
  `KtAnnotationEntry` is a subtype of it.
- KT-66038 is fixed by this because the static declaration provider only
  indexes non-local classes.

^KT-66038 fixed
2024-02-26 16:36:00 +00:00
Marco Pennekamp d52860b835 [LL] Add tests for ClassId calculation of local class inside annotation argument
- The class IDs are erroneously calculated and will be fixed in the next
  commit.

^KT-66038
2024-02-26 16:36:00 +00:00
Ilya Chernikov 9ea775cbed K2 scripting: fix containing decl for last script expression
Generally the wrapping anonymous initializer can be used as a
"containing declaration" for some elements, but since the initialiser
for the last script expression could be dropped (the expression could
be converted to the result property), this may lead to the surprises,
e.g. as described in KT-65984
This fix marks the last initialiser as local, preventing it from being
referenced as "containing declaration".

#KT-65984
2024-02-23 22:03:44 +00:00
Ilya Chernikov 266447120d K2 scripting: treat default import similarly to K1
namely, add them to importing scopes directly and according to the
schema used for other implicit imports, rather than adding them
to the regular script file imports. See KT-65982 for explanation.
#KT-65982 fixed
2024-02-23 22:03:44 +00:00
Ilya Chernikov 9037975758 K2 Scripting: Skip base class params from resolution scope
The base class in scripting considered obsolete and therefore supported
via some ad-hoc mechanisms. In particular parameters to the base class
c-tor are passed via script provided properties. But in combination
with the resolution logic, this leads to issues described in KT-60452
This commits filters out such parameters from script resolution
scope and avoids this problem for now.
Bot it should be noted that proper diagnostics for properties shadowing
should still be implemented - see #KT-65809
#KT-60452 fixed
2024-02-23 22:03:44 +00:00
Nikolay Lunyak 8f8c7fe7cf [FIR] Properly calculate visibilities
`testIntersectionOfPrimitiveBasedFunctions`
is fine, because we deprecate this
already in ^KT-63243.

`CANNOT_INFER_VISIBILITY` is
positioned as `DECLARATION_NAME`,
just in case we decide for
some reason that we do want to
report it along with
`MANY_*_NOT_IMPLEMENTED`. In that
case, we'd get a problem that
their bounds overlap, but not
completely contain one another.

^KT-63741 Fixed
^KT-59400 Fixed
2024-02-15 16:10:14 +00:00
Nikolay Lunyak 7056ad5325 [FIR] Set status.isOverride for fake overrides
Even though SO may not be correct
overrides sometimes, it feels more
natural to treat fake overrides as...
well, "overrides". And without it
we'd need to make the code in
`FirOverrideChecker` less intuitive.
2024-02-15 16:10:13 +00:00
Nikolay Lunyak 3b5fff5473 [FIR] Don't copy VP default values for fake overrides
In general, overrides should not
contain default values, and it's
better to make fake overrides be close
to proper overrides as much as
possible. It will be important when
we begin running `FirOverrideChecker`
for fake overrides.

^KT-63879 Fixed
^KT-65534
2024-02-15 16:10:13 +00:00
Dmitrii Gridin 78c394d4de [LL FIR] FirElementBuilder: search file header elements without body resolution
^KT-65780
2024-02-14 17:53:31 +00:00
Dmitrii Gridin 38a3010ac8 [LL FIR] FirElementBuilder: search file annotations without body resolution
^KT-65780
2024-02-14 17:53:31 +00:00
Dmitrii Gridin 7796ef43db [LL FIR] FileStructure: resolve FirFile to body phase as all other elements
This is the correct behavior as we have to resolve to body phase
to build CFG and run diagnostics collector correctly

^KT-65780 Fixed
2024-02-14 17:53:31 +00:00
Dmitrii Gridin 84b6d5d508 [LL FIR] add tests for getOrBuildFir for KtFileAnnotationList
^KT-65780
2024-02-14 17:53:31 +00:00
Dmitrii Gridin 5426cbc3df [LL FIR] tests for this with annotations as implicit return type
^KT-61175
^KT-64215
2024-02-14 17:46:47 +00:00
Dmitrii Gridin e02c28c88a [LL FIR] support lazy resolve of destructuring declaration entries
^KT-62840 Fixed
^KT-65727
2024-02-14 16:16:01 +00:00
Dmitrii Gridin 8c63e75f06 [LL FIR] update destructuringEntryScript testData
To reproduce getOrBuildFir for KtDestructuringDeclarationEntry

^KT-62840
2024-02-14 16:16:01 +00:00
Dmitrii Gridin 312feb3dca [FIR] make script destructuring declaration entry initializer lazy expression
This change is required to properly support such declarations in lazy
resolution mode as we usually replaced initializers with lazy
expressions during the body calculation phase

^KT-62840
2024-02-14 16:16:01 +00:00
Dmitrii Gridin 256d83b005 [LL FIR] support lazy resolve of <destruct> script declaration
But support for entries still is not implemented yet

^KT-62840
2024-02-14 16:16:01 +00:00
Dmitrii Gridin 792af849df [LL FIR] add getOrBuildFir test on destructuring declaration annotation
It doesn't resolve the property as it is treated as a local one

^KT-62840
2024-02-14 16:16:01 +00:00
Dmitrii Gridin 9ca0bdcb80 [FIR] make script destructuring declaration initializer lazy expression
This change is required to properly support such declarations in lazy
resolution mode as we usually replaced initializers with lazy
expressions during the body calculation phase

^KT-62840
2024-02-14 16:16:01 +00:00
Dmitrii Gridin 8f987644ab [LL FIR] designation refactoring
Collect `FirDesignation` by default with `FirFile` instead of just
a separate path and additional repeated logic around

^KT-65344
2024-02-13 14:58:31 +00:00
Dmitrii Gridin 47e8d987b9 [LL FIR] ContextCollector: optimize collector for file elements
We shouldn't trigger declaration processing if we want to check just
annotations/package/imports.
But currently, we still will iterate over the entire file
if there is an element somewhere inside package/import
(see `fileImportInside.kt` test case)

^KT-65344
^KT-65560 Fixed
2024-02-13 14:58:31 +00:00
Dmitrii Gridin 0c3a1dfd67 [LL FIR] ContextCollector: add tests for file package and imports
It reproduces redundant resolution

^KT-65344
^KT-65560
2024-02-13 14:58:31 +00:00
Dmitrii Gridin 58ad26ee5b [LL FIR] make script initializers independent
Now we can resolve all script declarations independently

^KT-65344 Fixed
2024-02-13 14:58:31 +00:00
Dmitrii Gridin 4f0bc86ad4 [LL FIR] make result$$ property independent
Now we can resolve this generated property in the same way
as other regular properties.
This is the pre-step for independent script initializers

^KT-65344
^KT-65523
2024-02-13 14:58:31 +00:00