Commit Graph

2911 Commits

Author SHA1 Message Date
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
Dmitrii Gridin 87ca9e4203 [LL FIR] reduce resolution inside getOrBuildFirFor
We can avoid body resolution in some cases because it is more
than out contract is required

So ANNOTATIONS_ARGUMENTS_MAPPING should be enough for all
non-body parts of a declaration to return fully-resolved FirElement
Body parts incudes: body and default values

^KT-59266 Fixed
2023-06-16 14:47:49 +00:00
Dmitrii Gridin b9e24e9b19 [LL FIR] add more tests on getOrBuildFirFor
^KT-59266
2023-06-16 14:47:49 +00:00
Dmitrii Gridin aad99fd6eb [LL FIR] getOrBuildFir tests should render fir file
We need it to see how many declarations were resolved

^KT-59266
2023-06-16 14:47:48 +00:00
Anna Kozlova 8c2f1acc7e [LL] take originalDeclaration when exists to detect module kind
Fixes KTIJ-24609.
When completion happens outside the content root,
module kind should be detected by the original file.
Otherwise, module would not be the same because outside the content root,
each file has its own module.
Actual #findSourceFirSymbol also does search over originalDeclaration when present.
Added FirCompletionOutsideSourceRootTest in IJ monorepo
2023-06-16 13:28:26 +00:00
Brian Norman 269dfc61c8 [FIR] Display actual type for argument type mismatch error
Previously the argument type was being used for the actual type error
display. However, safe-call arguments are unwrapped which causes
nullable types to be displayed as non-null. Change to use the actual
type provided by the diagnostic instead of extracting the type from
the argument.

#KT-58844 Fixed
2023-06-16 11:44:14 +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 70b9af0566 [LL] don't request provider with non-physical element
Otherwise, if fir was requested with non-physical element
 inside existing analysis session (not on-air, e.g.,
`FirPositionCompletionContextDetector#analyzeInContext` with
 `FirSimpleParameterPositionContext`) all consequent requests
 would return fir with that non-physical source,
 which might be already invalidated.

 On-air sessions should be protected from invalidation problem but some clients
 might expect original elements anyway and in this case, it would be
 impossible to retrieve correct fir for them.

 In order to find parameters, allow to traverse tree till functions.
2023-06-15 17:32:40 +00:00
Anna Kozlova 3fc334d2eb [decompiler] additional logging for ByDescriptorIndexer 2023-06-15 15:47:17 +00:00
Brian Norman 6b5e7ae825 [FIR] Transform children independently when callee is an error
To make sure all possible types are resolved and any additional errors
are reported, resolve children of function calls using independent
resolution mode when the callee reference is an error.

#KT-59041 Fixed
2023-06-15 14:03: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
Dmitrii Gridin 7631e90f12 [LL FIR, Java] fix resolve contract violation from java symbol provider from permits
To create a smart psi type pointer, IJ Platform uses resolve
We cannot use resolve from JavaSymbolProvider,
as it may lead to resolve contract violation

^KT-59243 Fixed
2023-06-14 09:25:26 +00:00
Mikhail Glukhikh 668157eb41 FirClassAnySynthesizedMemberScope.kt: make it a declared member scope
Related to KT-54844, KT-58926
2023-06-14 07:09:16 +00:00
Mikhail Glukhikh 5304afb097 Fix AA/LC behavior accordingly to changes related to KT-54844 2023-06-14 07:09:15 +00:00
Anna Kozlova 95ec7ede66 [light classes] create enum references as PsiReferenceExpressions
Ensure that enum constants with special characters in their names are properly ignored
2023-06-13 20:09:54 +00:00
Pavel Mikhailovskii 89c8392255 Make it possible to instantiate StandaloneAnalysisAPISession with a custom clasloader 2023-06-13 13:34:11 +00:00
Anna Kozlova 57f429206c [light classes] Improve isEquivalence checks
^KTIJ-25412

Update equivalence checks for light accessor methods and light fields
 to make them equivalent if they share the same underlying property.
 Follow the `kotlinOrigin` declaration:
 even if there is a property accessor,
 use property declaration.
2023-06-13 12:39:51 +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
Mikhail Glukhikh ab1d634ad3 K2: add test for KT-59241 2023-06-12 22:36:02 +00:00
Dmitrii Gridin 6992a707dc [LL FIR, Java] fix resolve contract violation from java symbol provider from supertypes
To create a smart psi type pointer, IJ Platform uses resolve
We cannot use resolve from JavaSymbolProvider,
as it may lead to resolve contract violation

^KT-59240 Fixed
2023-06-12 16:41:26 +00:00
Pavel Mikhailovskii 46844100d5 Fix visibility of $annotations methods 2023-06-12 12:59:53 +00:00
Denis.Zharkov 41933facbb K2: Fix ISE from inference on delegate vars with implicit types
See the test data.
ISE happened because at some point after incomplete `getValue` resolution
of `a` property, we updated in the `transformAccessors` the property type
to the `Variable(Y)` type and then used it as a 3rd argument for
`setValue` call which is incorrect because the variable belongs
to a different constraint system (from `getValue`).

Mostly, the fix is just a repeating K1 behavior, namely postponing
`setValue` resolution until delegate inference is completed.

^KT-59066 Fixed
2023-06-12 11:30:35 +00:00
Dmitrii Gridin d7c197b31e [LL FIR] support lazy resolve for WrappedIntegerOperator
^KTIJ-25761 Fixed
2023-06-10 17:57:52 +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
Anna Kozlova e81099ca96 [light classes] create enum references as PsiReferenceExpressions
to better mimic java psi,
see e.g. `PsiJvmConversionHelper#getAnnotationAttributeValue(PsiAnnotationMemberValue)`
2023-06-10 08:30:26 +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
Denis.Zharkov d5f24addea K2: Fix isHiddenForThisCallSite for non-direct overridden
Previously, the call of `z.sort` in test has been resolved
to the overridden member
2023-06-08 15:53:22 +00:00
Ilya Kirillov b8f15cbbb3 [LL FIR, Java] fix resolve contract violation from java symbol provider
To create a smart psi type pointer, IJ Platform uses resolve.
We cannot use resolve from JavaSymbolProvider, as it may lead to resolve contract violation.

^KT-59133 fixed
2023-06-08 14:13:30 +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 672cc85949 [LL FIR] remove LowLevelFirApiFacadeForResolveOnAir.onAirResolveTypeInPlace
which is unused now

^KT-58125
2023-06-08 13:41:35 +00: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
Mikhail Glukhikh 0373e3fdfe KtFe10SymbolInfoProvider: take annotation use-site target into account 2023-06-08 13:34:50 +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 983d319a6b [AA] fe10 symbols adjusted to be used in goto type declaration
- try to find sources for decompiled symbols in IDE mode
- function literals can't be declared as extensions,
though there target can contain that indication,
let's take what descriptor provides
2023-06-07 21:46:49 +00:00
Anna Kozlova 86bed92a46 [AA] ensure psi files from stdlib do not leak 2023-06-07 21:00:26 +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
Nikolay Lunyak 5daec16ce0 [FIR] Forbid creating abstract class instances via any qualified access
^KT-58938 Fixed
2023-06-07 16:45:28 +00:00
aleksandrina-streltsova fccb391f31 [AA] Renderer: enable rendering name without symbol
^KTIJ-22404
2023-06-07 16:22:28 +00:00
Denis.Zharkov 69a6339935 K2: Add test for obsolete KT-51793
^KT-51793 Fixed
2023-06-07 14:49:22 +00:00
Nikolay Lunyak 97adb01600 [FIR Native] Don't add Cloneable supertype when it's not present
^KT-58549 Fixed
2023-06-07 13:03:02 +00:00
Denis.Zharkov 0d070f8ba9 K2: Fix processing inference lower bound NullableType <: T & Any
Previously, it was led to plainly adding NullableType <: T constraint
which silently led to successful call completion.
What is suggested is just marking such initial constraint
as unsuccessful.

In K1, the error was reported just via additional type checking
mechanism being run after call completion.

^KT-58665 Fixed
2023-06-07 09:42:55 +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