Commit Graph

3479 Commits

Author SHA1 Message Date
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
Dmitriy Novozhilov d4f55894b4 [FIR2IR] Properly calculate dispatch receiver type for fake overrides
If some function is not fake-override, then its type should be just
  default type of containing class
For fake overrides the default type calculated in the following way:
1. Find first overridden function, which is not fake override
2. Take its containing class
3. Find supertype of current containing class with type constructor of
   class from step 2

^KT-60252 Fixed
2023-08-25 21:06:15 +00:00
Bogdan Mukvich 7b00323b89 [Build] Update guava
Fix some reports from "Show Vulnerable Dependencies"

^KTI-1342
2023-08-25 14:10:37 +00:00
Stanislav Ruban 44a4c4ee1c [tests] BI (1P&1TV/1TIO): add tests for target types
single builder parameter
single postponed type variable
single origin of type information

relevant issues:
KT-60719
KT-60720
KT-60855
KT-60877
KT-60880
2023-08-25 14:01:56 +00:00
Nikolay Lunyak 77feb86a85 [FIR] Report the use of inline on primary constructor parameters
^KT-59664 Fixed
2023-08-25 12:23:56 +00:00
aleksandrina-streltsova aa0eca6d6d [AA] Provide KtCallableSymbol for static Java members
^KTIJ-25126 Fixed
2023-08-24 22:17:48 +03:00
Anastasia.Nekrasova aef6787e87 [Test] Add a test covering changes in the evaluation semantics of safe call with smart cast in K2
Addition to other safe call tests that are already present in tests.

^KT-41034
2023-08-24 11:38:13 +00:00
Kirill Rakhman 8de36c416e [RAW FIR] Put destructuring statements outside of main lambda block
This fixes a false positive REDECLARATION when you want to shadow
a destructured lambda parameter inside the lambda.

#KT-60771 Fixed
2023-08-24 11:07:45 +00:00
Yan Zhulanow 981dde26ea [LL API] Migrate type reference check to FirExpression.type
'FirExpression.typeRef' is deprecated. Its new, temporary replacement
is not passed to visitors, so the reference-handling code became dead.
2023-08-24 07:54:57 +00:00
Yan Zhulanow d70dbbc4cf [LL API] Resolve properties called inside code fragments
'CodeFragmentCapturedValueAnalyzer' assumes the analyzed code fragment
is then passed to the backend. For property calls, there are several
code generation strategies (field, accessor, delegate). In order to
be able to choose one, the whole property, including its possibly
'const' initializer, must be resolved.

The commit fixes a plenty of 'FirIdeNormalAnalysisSourceModuleCompilerF\
acilityTestGenerated.CodeFragments.Capturing' tests that broke after
the 'FirExpression.type' refactoring.
2023-08-24 07:54:57 +00:00
Kirill Rakhman 7fde5af7f8 [FIR] Rename FirExpression.coneType to resolvedType 2023-08-24 07:54:57 +00:00
Kirill Rakhman 8d7c5b375e [FIR] Replace usages of FirExpression.typeRef with coneTypeOrNull
#KT-59855 Fixed
2023-08-24 07:54:57 +00:00