Commit Graph

943 Commits

Author SHA1 Message Date
Dmitrii Gridin 8cdba7b9e7 [LL FIR] KtFirVisibilityChecker: use getOrBuildFirSafe instead of resolveToFirSymbol againg
It is unexpected, but getOrBuildFirSafe here now works better than resolveToFirSymbol

^KT-59266
^KT-59453 Fixed
2023-06-17 18:04:59 +00:00
Brian Norman 0ff9982b31 [FIR] Additional errors to distinguish resolution to classifier cases
When a call is resolved to a classifier, only a single error message was
being used for multiple cases. This lead to confusion as the default
message may not be applicable to a given error case. Added additional
errors and messages to distinguish between these error cases.

#KT-57251 Fixed
2023-06-16 16:26:50 +00:00
Dmitrii Gridin 13732881a6 [AA FIR] reduce resolve calls
^KT-59266
2023-06-16 14:47:49 +00:00
Anna Kozlova 09f4f0af66 [AA] delegate to resolveToFirSymbol to avoid decompilation
`getReturnTypeForKtDeclaration` is called by UAST on probably compiled declarations.
In order to avoid redundant decompilation + building raw FIR + resolve,
let's delegate to deserialized FIR which is already prepared in stubs

Fixes KTIJ-24810

When `findSourceNonLocalFirDeclaration` is called on non-physical property accessor e.g.,
during completion, then traverse tree should allow drilling into FirProperty;
otherwise, no FIR would be found
2023-06-16 09:00:09 +00:00
Anna Kozlova dd059a1e63 [LL] find fir by psi: allow fallthrough to traverse tree for invalid code
In case of broken code e.g., duplicated classes provider would return first class,
though we definitely need some code insight in this case
at least to add navigation fixes, etc.
Similar to this, a file copy is created during completion,
where additional elements might appear and we need to search for them.

Added test cases for duplicated classes.
2023-06-15 17:32:40 +00:00
Anna Kozlova f80ed4592d [AA] Handle KtTypeReference children in CompileTimeConstantProvider
CompileTimeConstantProvider could receive a reference expression,
whose grandparent is KtTypeReference (seen that in UAST inspection).
FIR would not contain anything explicit for this reference,
FirResolvedTypeRef would be received as the nearest parent.
Of course, in this case, there could be no compile time constant anyway.
2023-06-15 07:06:41 +00:00
Mikhail Glukhikh 5304afb097 Fix AA/LC behavior accordingly to changes related to KT-54844 2023-06-14 07:09:15 +00:00
Roman Golyshev 9f819b4c57 KTIJ-25823 [Analysis API][FIR] Filter reanalysed parts by type in FirBodyReanalyzingVisitorVoid
There are SOE exceptions caused by the fact that `getOrBuildFir` can
return a FIR declaration for the parent PSI. I wasn't able to reproduce
it locally, but this commit should prevent such problems by using
`getOrBuildFirSafe` with explicit type specification
2023-06-13 12:33:06 +00:00
Dmitrii Gridin 563f913a95 [LL FIR] introduce tests to check lazy resolve stdlib as sources
^KTIJ-25761
2023-06-10 17:57:52 +00:00
Dmitriy Novozhilov 6409bf2fe8 [FIR] Store expressions of receivers inside candidates instead of ReceiverValue
This is needed because of mutable nature of receiver values: implicit
  receiver values can be modified because of smartcasts, but in candidate
  we need to store snapshot of receiver in the form it was at the beginning
  of the resolution

^KT-58823 Fixed
2023-06-09 22:51:31 +00:00
Roman Golyshev ba6f8e9b23 KT-59199 [Analysis API][FIR] Force resolve of the bodies for the KtFirReferenceShortener and KtFirImportOptimizer
Without it, those services might see outdated FIR elements when the user
changes the PSI.

Related tickets: KT-58257, KTIJ-25785, KTIJ-25749
2023-06-09 23:56:11 +02:00
Ilya Kirillov 724386a5f1 [Analysis API] rework the resolve of the nested name references
To properly resolve qualifier parts in the middle,
we need to resolve the whole qualifier to understand
which parts of the qualifier are package or class qualifiers.
And then we will be able to resolve the qualifier
selected by the user to the proper class, package or callable.

^KT-59189
2023-06-09 21:18:45 +00:00
Ilya Kirillov 785778511b [Analysis API] rework KDoc resolution
1. Optimize it by removing a tower data context collection (KT-59189)
2. Rework the behavior, so it simulates the tower resolve by returning the set of symbols only from the first tower level, which is not empty

^KT-59189 fixed
2023-06-09 21:18:45 +00:00
Ilya Kirillov d9cb7b67d4 [Analysis API] move ShortenCommand.invokeShortening to the IDE repository
as Analysis API should not modify the code

^KT-58992 fixed
2023-06-09 14:45:23 +00:00
Ilya Kirillov 95cf892eec [Analysis API] extract the data from the ShortenCommandImpl to the base class
^KT-58992
2023-06-09 14:45:23 +00:00
Kirill Rakhman bcdd85758e [FIR] Split origin SubstitutionOverride into declaration and call-site 2023-06-09 08:22:21 +00:00
Justin Paupore f590e88bdd [Analysis API] Add source shadowing for resolve extensions.
KtResolveExtensions are designed to handle IDE analysis use cases where
source might not be available at analysis time, because that source is
generated by an external source generator, such as an annotation
processor or resource compiler. The sources generated by those external
generators can appear in the analysis scope, and cause issues with
source clash - resolution may find the virtual source from the
KtResolveExtension, the on-disk generated source from the external
generator, or both. This can cause issues, because that on-disk
generated source may be stale, and may not have symbols that will exist
the next time the generator is run (or, conversely, may have symbols
that will disappear on the next build).

To solve this, add a `getShadowedScope(): GlobalSearchScope` to
`KtResolveExtension`. Any files in the module that are included in that
scope will be hidden from resolution, allowing the resolve extension to
cleanly replace those files.

^KT-58834 fixed
2023-06-08 15:55:04 +02:00
Ilya Kirillov 481962d5f6 [LL FIR] get rid of on-air resolve of partial type qualifiers
It's very slow and leads to performance problems (see KT-58125)

Instead, we do the following:

- For a fully resolved type qualifier, when we want to resolve its part,
 we are looking for the corresponding symbol by traversing nested classes
 bottom up.
 - For an error qualifier, we are trying to resolve the maximum possible
  qualifier in the types transformer where all the type scopes are
  already available.

^KT-58125 fixed
2023-06-08 13:41:35 +00:00
Egor Kulikov f2f979134d [FIR] Change diagnostic INITIALIZER_TYPE_MISMATCH to work with for loop
^KTIJ-25251 fixed


Merge-request: KT-MR-10507
Merged-by: Egor Kulikov <Egor.Kulikov@jetbrains.com>
2023-06-08 09:40:09 +00:00
Anna Kozlova 4d97e4c572 [LL] add tests for FirDeclarationForCompiledElementSearcher
build stub if was not able to load:
expected that in IDE stubs would always be found in the index, for tests -
build from virtual file
2023-06-07 21:00:26 +00:00
Egor Kulikov 347c748182 [FIR] Add excessive delegated constructors to FIR tree
^KTIJ-25453 fixed

Merge-request: KT-MR-10379
Merged-by: Egor Kulikov <Egor.Kulikov@jetbrains.com>
2023-06-05 14:27:53 +00:00
Anna Kozlova 38ae16e9d3 [AA] explicitly search for sources of synthetic functions declarations
these synthetic classes are found by `FirBuiltinSyntheticFunctionInterfaceProvider`,
which isn't based on stubs and has no explicit source

This fixes tests in IJ repo, such as uast based tests:
`FirLegacyUastResolveEverythingTestGenerated#testLambdaReturn`

Merge-request: KT-MR-10406
Merged-by: Anna Kozlova <Anna.Kozlova@jetbrains.com>
2023-06-02 14:27:26 +00:00
Brian Norman 0298d17987 [FIR] Remove suspend lambda redundant warning for inline functions
#KT-57971 Fixed
2023-06-02 10:49:57 +00:00
Ilya Kirillov 1eb0862820 [Analysis, build] replace testApi -> testImplementation in build.gradle.kts where it's possible 2023-06-02 09:16:47 +00:00
Ilya Kirillov fbcf73eb42 [Analysis API Standalone] commonize logic for Analysis API FIR service registration between standalone and tests 2023-06-02 09:16:47 +00:00
Marco Pennekamp 0a67569163 [LL FIR] KT-58580 Add test data for resolve extensions in dependencies
- `dependency2` is needed to ensure the creation of combined Kotlin
  symbol providers. If there is only a single dependency Kotlin symbol
  provider, the combined symbol provider won't be created.
2023-05-31 18:34:42 +00:00
Marco Pennekamp a50e839660 [LL FIR] Add multi-module resolve extension reference resolve tests
- To test the reference resolution of declarations provided through
  resolve extensions of module dependencies, we need support for
  multimodule resolve extension tests.
2023-05-31 18:34:42 +00:00
Marco Pennekamp fba0648005 [AA] Move impl declaration providers to subpackage 2023-05-31 18:34:42 +00:00
Roman Efremov d2eb4a0abf [FE] Prohibit default arguments in expect declarations actualized via typealias
Cases when default argument inhertied from super class are allowed.

Some tests for default arguments already exist and can be found in
`testData/diagnostics/tests/multiplatform/defaultArguments`, for example
`annotationsViaActualTypeAlias.kt`.

^KT-57614 Fixed

Merge-request: KT-MR-10356
Merged-by: Roman Efremov <Roman.Efremov@jetbrains.com>
2023-05-31 13:14:37 +00:00
Ilya Kirillov c114cb67cb [Java resolution] make it possible to provide custom source element for JavaElement
This is needed to allow using PSI pointers in IDE in JavaElement.
`JavaElement`s are reused between read actions,
so underlying PSI elements might be invalidated when using hard PSI references

^KT-58194
2023-05-31 13:01:19 +00:00
Anna Kozlova 1d5c080dd8 [AA] calculate ktType based on symbols when possible
then, for compiled code deserialized fir would be used instead of building
decompiled text and consequence building and resolving of raw fir;

type for ktTypeReference from compiled code is called e.g., by UAST inspections
when they check annotations of the called function parameters
2023-05-31 06:26:28 +00:00
Brian Norman 8091aebbc7 [FIR] Create checker for simple enum entries with missing overrides
Complex enum entries (those with bodies) with missing overrides
are covered by an existing checker that checks all types of classes. But
simple enum entries (those without bodies) were not covered and require
a separate checker for missing overrides.

#KT-58637 Fixed
2023-05-29 16:34:44 +00:00
Egor Kulikov 9a77632f1c [FIR] Fix invalid expression throwing exception when determining type
^KTIJ-25421 fixed

Merge-request: KT-MR-10317
Merged-by: Egor Kulikov <Egor.Kulikov@jetbrains.com>
2023-05-25 12:31:42 +00:00
Egor Kulikov 5e38c2d570 [FIR] Fix invalid expression throwing exception when determining type
^KTIJ-25421 fixed

Merge-request: KT-MR-10290
Merged-by: Egor Kulikov <Egor.Kulikov@jetbrains.com>
2023-05-25 12:29:46 +00:00
Justin Paupore dd9e127d2c [Analysis API] Hide FIR-specific diagnostic details.
Change the public-facing KtFirDiagnostic to be an interface, not
a class, and change the internal implementations to be classes, not
interfaces. This allows hiding access to the KtPsiDiagnostic underlying
the AA diagnostic class.
2023-05-23 21:24:02 +02:00
Roman Efremov 439cc88525 [FE] Prohibit expect external and expect tailrec
^KT-58536 Fixed
2023-05-23 12:43:51 +00:00
Nikita Bobko de8c3826c2 [FE] Prohibit missed MUST_BE_INITIALIZED when there is no primary constructor
^KT-58472 Fixed
Review: https://jetbrains.team/p/kt/reviews/9967
2023-05-23 14:12:29 +03:00
Nikita Bobko ac40010501 [FE] Prohibit open val deferred initialization
^KT-57553 Fixed
Review: https://jetbrains.team/p/kt/reviews/9967

Other related tests:
- testUninitializedOrReassignedVariables
- testUseOfPropertiesWithoutPrimary
- @TestMetadata("compiler/testData/diagnostics/tests/secondaryConstructors")
- testAugmentedAssignmentInInitializer
- testInitOpenSetter
- testInitOverrideInConstructorComplex
- testPropertyInitializationOrder
2023-05-23 14:12:28 +03:00
Nikita Bobko 38319c55a8 [FE] Replace some MUST_BE_INITIALIZED messages with MUST_BE_INITIALIZED_OR_BE_FINAL
From user point of view it's an improvement in compilation message.

From technical point of view it's an introduction of new compilation
diagnostic.

Review: https://jetbrains.team/p/kt/reviews/9967

I'm going to deprecate `open val` case in the next few commits KT-57553.
But it is always possible to suggest using `final` for `open val` case.
2023-05-23 14:12:28 +03:00
Egor Kulikov f432bbad2e Revert "[FIR] Fix error with incorrect destructing declaration"
This reverts commit b47910e86b.
2023-05-23 12:51:43 +02:00
Egor Kulikov b47910e86b [FIR] Fix error with incorrect destructing declaration
^KTIJ-25342 fixed
2023-05-23 12:48:41 +02:00
Marco Pennekamp 326b6fa7c2 [AA] Add missing withValidityAssertion calls to scopes
^KT-58653
2023-05-22 19:21:34 +00:00
Egor Kulikov 1d8eb6dc9e [FIR] Only take receiver on lambda if present
^KTIJ-25127 fixed
2023-05-22 17:10:52 +00:00
Kirill Rakhman df03f0df0a [FIR] Implement deprecation for implementing var by inherited val
#KT-56779 Fixed
2023-05-19 15:04:46 +00:00
Alexander Udalov 75197d1b86 JVM: remove diagnostics related to JVM target 1.6 2023-05-19 13:24:00 +00:00
Dmitrii Gridin b713dfd7ea [AA FIR] KtFirOverrideInfoProvider: resolve to status only if needed
^KT-56551
2023-05-19 12:43:45 +00:00
Dmitrii Gridin 5b3f617378 [FIR] add memberRequiredPhase to declaredMemberScope
^KT-56551
2023-05-19 12:43:45 +00:00
Dmitrii Gridin 01a94624f5 [AA FIR] KtFirScopeProvider: use lazy resolve only if needed
^KT-56551
2023-05-19 12:43:45 +00:00
Dmitrii Gridin f2da13b39d [AA FIR] KtFirMemberSymbolPointer: replace explicit lazy resolve call with implicit
^KT-56551
2023-05-19 12:43:45 +00:00
Dmitrii Gridin 04231d7497 [AA FIR] add missing memberRequiredPhase to some usages of unsubstitutedScope
^KT-56551
2023-05-19 12:43:45 +00:00