144 Commits

Author SHA1 Message Date
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
Dmitriy Novozhilov df878918ee [FIR] Optimize memory consumption of KtPsiSourceElement
There were two lazy properties in `KtPsiSourceElement`, which were
  rarely computed, which led to the fact that source element retained
  a lot of memory for those lazy delegates

^KT-66172 Fixed
2024-03-05 07:03:35 +00:00
Nikolay Lunyak afd8895e51 [FIR] Introduce the PluginGenerated source kind
Make parcelize work consistently with
`FirOverrideChecker`.

Actually, there is a philosophical question about
what to do when a plugin generates a class
in a new package, and this class is red code
(for instance, doesn't implement an abstract
member from a supertype). There's no source
to report such an error, but we probably do
want to run checkers to avoid trying to
compile red code to binaries (because it may
crash in backend, or it may silently work).
2024-02-15 16:10:13 +00:00
Dmitriy Novozhilov 5fe1e0c1a5 [FIR] Allow nullable type arguments in diagnostic reporting utilities
Commit cceb7197 removed restriction of non-nullability of diagnostic
  arguments, but corresponding utilities were not updated
2024-02-15 13:08:35 +00:00
Dmitriy Novozhilov 73b608608a [FIR] Optimize PendingDiagnosticsCollectorWithSuppress
PendingDiagnosticsCollectorWithSuppress is a special diagnostic collector,
  which aggregates diagnostics reported during checking of some specific
  element before actually reporting them, so its workflow looks like this:

- start checking some element;
- all reported diagnostics go to `pendingDiagnosticsByFilePath` map;
- all checkers done their jobs;
- diagnostics from `pendingDiagnosticsByFilePath` go to the resulting map
  of all diagnostics (not all, only ones which lay inside the checked
  according to PSI);
- processed diagnostics removed from `pendingDiagnosticsByFilePath`

This approach works fine, but there was one problem with it:
  `pendingDiagnosticsByFilePath` is not just a list of diagnostic, but
  map of lists, grouped by the containing file. And only those lists
  actually get cleared. But if some list was completely emptied, it still
  remained in the original `pendingDiagnosticsByFilePath` map
This led to the performance problem in case, where there are no actual
  diagnostics in the `pendingDiagnosticsByFilePath`, but the map itself
  is not empty but full of empty lists. So collector iterated over this
  map on each visiting of each element
And after KT-58881 this problem was uncovered, as number of visits of
  elements was twiced (because now we iterate over the whole tree twice,
  with Common and Platform checkers)

The fix is quite trivial -- if some list in `pendingDiagnosticsByFilePath`
  becomes empty, remove it from the map

^KT-65579 Fixed
2024-02-13 12:07:41 +00:00
vladislav.grechko 9aa8fb80e7 Set correct IR origins for inc/dec operations
NB: in order to produce correct IR origins, the source element kinds for
some FIR elements has been changed. As a side effect, mapping PSI to FIR
slightly changed: namely, for `a[b]++`, `a[b]` used to be mapped on
`set` call or callable reference, but now it is mapped on `get` call.

^KT-61891: Fixed
^KT-64387: Fixed
2024-01-30 14:26:10 +00:00
Denis.Zharkov e359db4111 K2: Set proper source for implicit it/receiver parameter
Previously, error types on those implicit parameters were being lost.

Changed test data is only partly here
(only parts that are considered to be correct).

Other ones (new green-to-red changes) should belong to the next commit
and will be fixed soon (as a part of PCLA).
2024-01-11 10:32:12 +00:00
Dmitrii Gridin b6d373d8e5 Update copyright to 2024 2024-01-05 13:43:17 +00:00
vladislav.grechko 77d0d1073e Preserve origins when desugaring augmented array assignments
^KT-63827: Fixed
2023-12-20 17:15:40 +00:00
Mikhail Glukhikh dbca7358af K2: add explicit cast to Any for Any function calls on stub types
This commit solves a stub type inconsistency problem.
As a part of KT-59369 fix we decided (see commit 299d2799),
that ConeStubTypeForChainInference has a scope of Any,
so we can safely resolve only to equals/hashCode/toString.
However, later we can replace a stub type with some inferred type,
which can have its own equals/hashCode/toString implementation,
while the call still refers Any member.
In this situation FIR2IR decides that we are calling a fake override,
which is not true, in fact we are calling an overriding method.
This leads to a crash in Native backend.

To solve this situation, we provide an explicit cast of a dispatch
receiver with a stub type (ConeStubTypeForChainInference) to Any,
thus confirming directly we are calling Any method and nothing else.

#KT-63932 Fixed
2023-12-13 14:56:58 +00:00
Alexey Belkov f53f92cdd6 K2: Add KtDiagnosticRenderers.CLASS_ID to render ClassId FQNs with dots
KT-MR-13391
2023-12-08 17:26:59 +00:00
Kirill Rakhman dd1d36816b [FIR] Insert SAM conversion expressions during completion
#KT-62847 Fixed
2023-11-30 08:39:04 +00:00
Ilya Chernikov 1ad4f19181 Fix default positioning strategy handling
that causes flaky tests because the default positioning strategy
was dependent on the order of the reported messages.
The code led to it was introduced in an attempt to extract common
PSI-independent strategy because PSI is leaking into the abstract
diagnostic infrastructure. The approach is definitely problematic,
but to fix it now, the leaking dependency to the psi-based module
is introduced. This should be fixed in the future by introducing
better abstractions.
Fixes flaky tests touched in the commit.
#KT-63002 fixed
2023-11-06 21:21:16 +00:00
Ilya Chernikov 65d1c8ce7e K2 Scripting: do not report import resolution errors on implicit imports
since implicit imports are used in the gradle scripts, where it seems
difficult to precisely control list of import to avoid
unresolved names. And we can relatively safely ignore
unresolved imports there

#KT-62404 fixed
2023-11-03 21:54:23 +00:00
Dmitrii Gridin 0b45c6ce23 [FIR] FirScriptConfiguratorExtensionImpl: provide source for script parameters
We need this source to be able to find the parent declaration

^KT-62693 Fixed
2023-10-20 09:27:21 +00:00
Iaroslav Postovalov fd2954a8d3 Move DummyDelegate to :compiler:util
Deleted DummyDelegate from a pair of usages across the project, and
moved it to :compiler:util module to avoid further duplicates
2023-09-13 09:51:13 +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
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
Kirill Rakhman 8d7c5b375e [FIR] Replace usages of FirExpression.typeRef with coneTypeOrNull
#KT-59855 Fixed
2023-08-24 07:54:57 +00:00
Kirill Rakhman de1c92a32f [FIR] Update diagnostic messages 2023-08-21 16:28:48 +00:00
Alexey Merkulov e4ae15b3f0 [FIR] Allow resolve to private members from debugger evaluator
KT-60714
2023-08-10 13:40:52 +00:00
Kirill Rakhman 09f895efe6 [FIR] Implement VERSION_REQUIREMENT_DEPRECATION diagnostics 2023-08-08 09:28:08 +00:00
Marco Pennekamp 9e3ce9cf67 [FIR] Move LibraryModuleInfo to the common frontend
- FIR-specific parts of the Kotlin IntelliJ plugin depend on
  `LibraryModuleInfo`, so it should be part of the common frontend.
2023-07-26 19:09:12 +00:00
Mikhail Glukhikh 5836a8aa0b K2: add more tests/fix augmented assignment case around KT-59748 2023-07-26 06:09:15 +00:00
Mikhail Glukhikh f20e2dec31 K2: generate Unit conversion for indexed assignment at raw FIR stage
#KT-59748 Fixed
2023-07-26 06:09:15 +00:00
Mikhail Glukhikh 8c305d6143 K2: introduce infrastructure for LanguageVersionSettings checkers 2023-07-24 12:50:38 +00:00
Kirill Rakhman 9288a96f6d [FIR] Assert source is not-null when reporting cone diagnostics
#KT-55835
#KT-59856
2023-07-20 07:29:18 +00:00
Marco Pennekamp 4ead02271b [FIR] Move TrackableModuleInfo to the common frontend
- FIR-specific parts of the Kotlin IntelliJ plugin depend on
  `TrackableModuleInfo`, so it should be part of the common frontend.
2023-07-19 13:03:51 +00:00
Ilya Kirillov a9cd881a07 [FIR] add utilities to FIR compiler to throw error with attachment 2023-07-18 11:49:20 +00:00
Ilya Kirillov 15f6fe2627 Move ExceptionAttachmentBuilder near KotlinExceptionWithAttachments so it's accessible from KotlinExceptionWithAttachments 2023-07-18 11:49:20 +00:00
Anna Kozlova 190d49a1e0 [light classes] optimize accessors retrieval
Avoid expensive calls to `navigationElement` for methods
that cannot be getters/setters and would be filtered later.
Repeat partly naming generation strategy.

Merge-request: KT-MR-10689
Merged-by: Anna Kozlova <Anna.Kozlova@jetbrains.com>
2023-06-22 14:14:39 +00:00
Alexander Udalov da884bd554 Minor, add error message to linker exception
(cherry picked from commit 04048d57ab912823504e9f57ddbc3a5f06b6af7c)
2023-06-21 14:24:28 +00:00
Kirill Rakhman 8ff67218f5 [FIR] Fix serialization of annotation vararg arguments
#KT-58937 Fixed
2023-06-14 08:41:27 +00:00
Dmitriy Novozhilov ba41e8ec38 [IR] Use common expect/actual matching algorithm in IR actualizer
^KT-58578 Fixed
2023-06-10 07:33:29 +00:00
Andrei Klunnyi 2a1d4a42ae [KT-58817] Implicit import issues cannot be reported
To be reported with [1] imports require source. It was missing for
implicit script imports.

`FirScriptConfiguratorExtensionImpl` was extended and now adds fake
source elements (users don't see imports in the source code).

Since diagnostics for implicit import statements are meaningless for
IDE, they are suppressed in `LLFirDiagnosticReporter`.

----------------------------------------------------------------------
[1]: DiagnosticReporter.reportOn()
2023-05-26 12:55:00 +00:00
Kirill Rakhman bdf0b41026 [FIR] Consolidate SYNTAX and SYNTAX_WITH_MESSAGE diagnostics 2023-05-05 09:34:23 +00:00
Nikolay Lunyak efbcfb4994 [FIR] Prevent duplicate FileAnalysisException-s 2023-05-03 10:04:25 +00:00
Kirill Rakhman a818c543a9 [FIR] Verify diagnostic messages don't reference non-existent parameters 2023-04-27 12:54:31 +00:00
Yahor Berdnikau eb4e96a113 Add kotlin-build-tools-enum-compat workaround
It acts as a workaround for the case when build tools or dependencies
are compiled with latest 'kotlin-stdlib' version, but at a runtime older
 'kotlin-stdlib' is provided, which does not know about new
 `EnumEntries`.

 ^KT-57317 Fixed
2023-04-21 14:57:17 +00:00
Nikolay Lunyak f644eb7988 [FIR JS] Implement FirJsExportDeclarationChecker 2023-03-29 08:51:48 +03:00
Nikolay Lunyak a2e2a96fd3 [FIR] KT-56846: Unwrap SourceCodeAnalysisException on transformFile
^KT-56846 Fixed

Merge-request: KT-MR-9065
Merged-by: Nikolay Lunyak <Nikolay.Lunyak@jetbrains.com>
2023-03-23 09:54:43 +00:00
Ivan Kylchik 2302e14dd6 [FIR LT] Extract getChildren function into common utils 2023-03-21 16:33:01 +00:00
Kirill Rakhman 45d2424ad8 [FIR] Let prefix inc/dec call getter twice for compatibility with K1
#KT-57179 Fixed
2023-03-21 08:48:38 +00:00
Denis.Zharkov 3f052af517 K2: Propagate explicit getter type to the property without initializer
In K1, we have the rules like:
- if there's explicit type of a property, then use it
- if there's an initializer, obtain its expression-type
- Otherwise, use getter's return type

The case when getter's type is implicit is handled at
FirDeclarationsResolveTransformer.transformProperty

^KT-56707 Fixed
2023-02-21 18:39:40 +00:00
Yahor Berdnikau 0cad069522 [Build] Pin api and language level to 1.8 in Kotlin compiler modules used by KGP
This is required to be able to compile KGP and it's dependencies which
set LV to 1.4 when repo will use LV 1.9. This caused by the change how
enums are compiled (KT-48872).
2023-02-18 13:26:54 +00:00
Denis.Zharkov 8fa84e7bea K2: Add clarification comment to KtFakeSourceElementKind 2023-02-15 08:13:55 +00:00
Denis.Zharkov d7399ed1cf K2: Avoid losing diagnostics for synthetic calls
Some of the changed tests may duplicate other existing diagnostics,
but that should not be reason not to report them at all.

There might be another job to be done to avoid diagnostic duplications
2023-02-15 08:13:41 +00:00
Denis.Zharkov a311d6eea0 K2: Extract CheckerContextForProvider from CheckerContext
So, the idea is that CheckerContext should remain just read-only
while the one who runs the checkers might build/modify the context.

^KT-56460 Related
2023-02-09 12:08:05 +00:00
Dmitriy Novozhilov f479a56f5e [FIR] Fix reporting of CANNOT_INFER_PARAMETER_TYPE on lambda parameters
^KT-56138 Fixed
2023-02-06 08:09:57 +00:00
Dmitriy Novozhilov ad3ae0ff69 [FIR] Add ability to specify that diagnostic collector should visit nodes with specific fake kind 2023-02-06 08:09:55 +00:00