Commit Graph

3490 Commits

Author SHA1 Message Date
Ilya Kirillov 56910b70a3 [Analysis API] fix "KotlinIllegalStateExceptionWithAttachments: expected as maximum one expect for the actual"
^KT-61597 fixed
2023-08-31 15:19:29 +00:00
Roman Golyshev f39153b6e6 KT-61568 [FIR][AA] Add one more testcase for AllCandidatesResolver 2023-08-31 14:59:53 +00:00
Mikhail Glukhikh 3ff2c7d6f7 K2: introduce custom Enum.entries migration checkers
Related to KT-56623, KT-56587
#KT-59344 Fixed
2023-08-31 13:29:02 +00:00
Mikhail Glukhikh d028f9ec95 K2: add stubs for enum entries deprecation diagnostics (KT-59344) 2023-08-31 13:29:01 +00:00
Pavel Kunyavskiy bf9cae6410 [Fir2Ir] Support rebuilding fake overrides over IR
^KT-61514
2023-08-31 13:12:15 +00:00
Brian Norman 997e062de9 [FIR] Check top-level property initialization via CFG
Now that files have a CFG, use it to validate properties are initialized
correctly. Update FirTopLevelPropertiesChecker to collect initialization
info for the property being checked - similar to
FirMemberPropertiesChecker - and validate proper initialization.

#KT-56683 Fixed
#KT-58531 Fixed
2023-08-31 12:50:52 +00:00
Brian Norman b55fda0c55 [FIR] Create CFG for files to track top-level property initialization
In order to properly analyze top-level property initialization, a
control-flow graph must be created for FirFiles. This change adds the
foundation for the file CFG and updates body resolve to create the CFG.
Checking the CFG for proper initialization is separated into a following
change to ease code review.

KT-56683
2023-08-31 12:50:52 +00:00
Dmitrii Gridin 99307f97e9 [Low Level FIR] introduce service for incoming psi modifications processing
This service encapsulates all logic and simplifies future evolution

^KT-60610
2023-08-31 10:06:43 +00:00
Dmitriy Novozhilov 6169834bb3 [FIR] Make FirResolvedDeclarationStatus.modality non nullable
^KT-58764 Fixed
2023-08-31 09:38:44 +00:00
Ilya Kirillov 103ebb0ab4 [kotlin] fix AssertionError: Alien file! in IJ test
We should not cache `VirtualFile` per-application
2023-08-31 08:55:17 +00:00
Roman Golyshev 1766c68e9c [FIR][AA] Rely more on isInBestCandidates flag KtFirReferenceShortener
After the KT-61568 has been fixed, `isInBestCandidates`
correctly works in more cases, and can be more
reliably used in `KtFirReferenceShortener`

^KTIJ-26808 Fixed
^KTIJ-26840 Fixed
2023-08-31 08:45:34 +00:00
Ilya Kirillov 714cb67254 [decompiler] add tests for generated psi text by builtin decompiler 2023-08-30 14:45:15 +00:00
Ilya Kirillov 5fc458d5a4 [LL FIR] implement toString for LLFirKotlinSymbolProvider and LLFirSession 2023-08-30 14:45:15 +00:00
Ilya Kirillov 9ea344fe76 [decompiler] fix ambiguities to builtin members resolve in K2 IDE
If a user has multiple kotlin-stdlib libraries in a project, all those stdlib libraries will contain builtins
which will result in resolution ambiguities.

To prevent such kind of ambiguities inside LLFirDependenciesSymbolProvider,
callables are grouped by facade class name.
Only matching callables from the first facade are used.

Facade is a Kotlin/JVM-term so right now it works only for JVM targets.
Builtins are also used in JVM, so the current solution is to have a Facade name also for builtins.

^KTIJ-26760
2023-08-30 14:45:14 +00:00
Ilya Kirillov 866368cf69 [LL FIR] fix navigation to stdlib declarations in K2 IDE
If a user has kotlin-stdlib in their project,
the IDE should resolve the builtin declarations to the kotlin-stdlib
instead of builtins from the Kotlin plugin.

^KTIJ-26760
2023-08-30 14:45:14 +00:00
Ilya Kirillov 5ab408859b [LL FIR] create a single builtin symbol provider which will be reused for the whole project when no stdlib is available
Previously, every kotlin stdlib containing builtins was searched causing resolution ambiguities.

^KTIJ-26760 fixed
2023-08-30 14:45:14 +00:00
Ilya Kirillov e8db349f24 [decompiler] extract builtin VirtualFile creation to a separate service for further reuse
^KTIJ-26760
2023-08-30 14:45:14 +00:00
Roman Golyshev 21dffe4639 KT-61568 [FIR][AA] Do not add redundant file scopes in AllCandidatesResolver
`firResolveSession.getTowerContextProvider` should already
contain all the relevant scopes, including default and
importing scopes for the file

Because of this, import and default scopes had presence over the
more local scopes, and the resolve was performed incorrecty - top level
candidates were given higher priority

^KT-61568 Fixed
^KTIJ-26824 Fixed
2023-08-30 14:30:21 +00:00
Yan Zhulanow ebd0ac8933 [LL API] Minor, move the call conflict resolver to the right package 2023-08-30 06:38:44 +00:00
Yan Zhulanow 8ad9718310 [LL API] Check the class file is in a conventional place
Although 'VirtualFile's are typically inside the containing package
directory, e.g. 'foo/bar/Baz.class' for 'foo.bar.Baz', there might
be classes with files in unexpected places. Sources of such classes
may include broken stubs, or just classes from misbehaving IDE plugins.

As we are yet to identity such cases, here we treat them as 'other'
candidates.
2023-08-30 06:38:44 +00:00
Yan Zhulanow faaba52ed5 [LL API] Minor, clean up 'LLLibraryScopeAwareConeCallConflictResolver' 2023-08-30 06:38:44 +00:00
Yan Zhulanow 4c3d414067 [LL API] Minor, fix documentation for 'globalLanguageVersionSettings' 2023-08-30 06:38:44 +00:00
Yan Zhulanow b96c1a644f [LL API] Fix code fragment compilation in library sources (KT-61383)
In complex projects, there might be several library copies (with the
same or different versions). As there is no way to build a reliable
dependency graph between libraries, a project library depends on all
other libraries. As a result, there might be several declarations in the
classpath with the same name and signature.

Normally, K2 issues a 'resolution ambiguity' error on calls to such
libraries. It is acceptable for resolution, as resolution errors are
never shown in the library code. However, the backend, to which
'evaluate expression' needs to pass FIR afterwards, is not designed for
compiling ambiguous (and non-completed) calls.
2023-08-30 06:38:44 +00:00
Yan Zhulanow 4b80c2197f [Analysis API] Run code fragment compilation tests against libraries 2023-08-30 06:38:44 +00:00
Yan Zhulanow dbb7e788b2 [LL API] Provide customizable default language version settings 2023-08-30 06:38:44 +00:00
Yan Zhulanow 705a97e9d4 [Analysis API] Fix test data for context receivers
Currently, the test files are only analyzed as source code, and present
errors do not affect code fragment analysis. In the following commits,
however, the test files will be compiled to test code fragment
analysis against library sources.
2023-08-30 06:38:43 +00:00
Alexander Kuznetsov 58350b83a8 KtFe10CompilerFacility: analyze inline delegated property accessors
One of the compiler lowerings, namely `PropertyReferenceLowering`,
optimizes usages of property references in some cases,
and if a containing delegated property accessor is inline,
it might need this accessor's bytecode.

If an accessor function is defined in a different module,
IDE tries to acquire its bytecode via the index, however,
the index doesn't cover classfiles from compiler output,
and that leads to errors like KTIJ-26706 and IDEA-320283.

One of the ways to ensure that the bytecode exists is to include files
that contain inline accessors in the compilation process. For example,
if file f1.kt from the analysis result contains property `val p by D()`,
and `D.getValue` is an inline function defined in file f2.kt,
then f2.kt must be present in the analysis result.
If f2.kt contains another property `val q by E()`,
and `E.getValue` is an inline function defined in f3.kt,
then f3.kt must be present in the analysis result. And so on.

Fixes KTIJ-26706, IDEA-320283


Merge-request: KT-MR-11793
Merged-by: Alexander Kuznetsov <Aleksander.Kuznetsov@jetbrains.com>
2023-08-29 23:55:31 +00:00
Alexey Merkulov 10c6e2da87 [LL API] Fix code generation to access private property from evaluator
Lowering asks whether to generate getter/setter call only when it should
be present. It means the code define explicit getter or setter.
And it seems correct to use it instead of trying direct field access.
2023-08-29 12:34:58 +00:00
Egor Kulikov fd5ac8575c [FIR] Do not expect FirExpression when KtLoopExpression is supplied
^KTIJ-26599 fixed

Merge-request: KT-MR-11708
Merged-by: Egor Kulikov <Egor.Kulikov@jetbrains.com>
2023-08-29 09:26:52 +00:00
Egor Kulikov d7f2f22b4b [FIR] Fix errors related to expect classes/delegated constructors
^KT-60384 fixed

Merge-request: KT-MR-11835
Merged-by: Egor Kulikov <Egor.Kulikov@jetbrains.com>
2023-08-29 08:39:36 +00:00
Roman Golyshev c8ae22eb66 KTIJ-26785 [AA] Filter JavaClassMembersEnhancementScope when shortening types
The same way as `FirClassUseSiteMemberScope` is present
when there is an implicit receiver with a pure Kotlin type,
`JavaClassMembersEnhancementScope` is present when
the receiver's type comes from Java sources

^KTIJ-26785 Fixed
2023-08-28 15:21:40 +00:00
Dmitrii Gridin 5aae053785 [AA FIR] add symbol restoring for $$result declaration
^KT-61431 Fixed
^KT-61451
2023-08-28 15:02:25 +00:00
Dmitrii Gridin 99510ca42b [AA] add test for $$result declaration
^KT-61431
2023-08-28 15:02:25 +00:00
Dmitrii Gridin adc853ebd0 [AA] extend SymbolData API to support scripts
^KT-61431
2023-08-28 15:02:24 +00:00
Dmitrii Gridin b6f34ad8c0 [AA] add API to get KtScriptSymbol for KtScript
^KT-61431
2023-08-28 15:02:24 +00:00
Dmitrii Gridin 700835ef13 [AA] generate tests for scripts
^KT-61431
2023-08-28 15:02:24 +00:00
Dmitrii Gridin 5557ea690d [AA] add generated tests for scripts
^KT-61431
2023-08-28 15:02:24 +00:00
Dmitrii Gridin 932c2a6e15 [AA FIR] KtFirReferenceShortener: process only statements in scripts
We shouldn't process other elements (like parameters/receivers) because
we can't modify them anyway. This will help to avoid exceptions like
```
Attempt to load text for binary file which doesn't have a decompiler plugged in
```
in tests

^KT-61431
2023-08-28 15:02:24 +00:00
Dmitrii Gridin bef5f89f61 [AA] add configurator for scripts
^KT-61431
2023-08-28 15:02:24 +00:00
Dmitrii Gridin 0a5501b8dd [LL FIR] add ability to pass analyseInDependentSession into AnalysisApiFirScriptTestConfigurator
^KT-61431
2023-08-28 15:02:24 +00:00
Brian Norman 833072e1fb [FIR] Add checker for MISSING_DEPENDENCY_CLASS
#KT-59371 Fixed
2023-08-28 15:00:04 +00:00
Mikhail Glukhikh 6ce096f0ed K2: handle extra value parameter in FirCallCompleter properly
#KT-60450 Fixed
2023-08-28 14:02:56 +00:00
Dmitrii Gridin 0068a3f6b8 [Analysis API FIR] mapAnnotationParameters: add debug information
^KT-61252
2023-08-28 12:59:58 +00:00
Dmitrii Gridin 7a24d0ee82 [Analysis API] KtPsiTypeProvider: disable for non-jvm platforms
Otherwise, it will throw exception like:
```
IllegalStateException: No 'FirJvmTypeMapper'
```

Anyway, PsiType is JVM conception, so it is not supposed to be used
outside the JVM platform

^KT-60318
2023-08-28 12:45:29 +00:00
Dmitrii Gridin 7fa7d8ea8d [SLC] provide light classes only for platforms with jvm target
Light classes are not supposed to work on non-jvm platforms due to its
specific

^KT-60318 Fixed
2023-08-28 12:45:29 +00:00
Nikolay Lunyak 13a7bb95b3 [FIR] Relax MULTIPLE_DEFAULTS_* to account for the K1 behavior
^KT-56442
^KT-36188
2023-08-28 10:57:40 +00:00
Nikolay Lunyak 3f1bf6112f [FIR] Report MULTIPLE_DEFAULTS_INHERITED_FROM_SUPERTYPES
Reporting it for `VIRTUAL_MEMBER_HIDDEN`
is ok, because `VIRTUAL_MEMBER_HIDDEN`
has always been an error, so we are
allowed to treat these as overrides
implicitly.

^KT-59408 Fixed
^KT-59419 Fixed
^KT-57076 Fixed
2023-08-28 10:57:40 +00:00
Dmitriy Novozhilov 0dd36ad456 [FIR2IR] Rename entrypoint function of Fir2IrConverter
Originally it was named createModuleFragmentWithSignaturesIfNeeded, because
  there was a counterpart `...WithoutSignatures`. Now that function has
  gone and there is only one entrypoint left
2023-08-28 10:22:04 +00:00
Mikhail Glukhikh 3e330241b4 K1/K2: add a test to fix state of KT-55168 2023-08-28 09:40:26 +00:00
Kirill Rakhman c30ce4aabe [FIR] Print operator keyword and token to unresolved diagnostic message
#KT-55672 Fixed
2023-08-28 08:12:25 +00:00