Commit Graph

4040 Commits

Author SHA1 Message Date
Egor Kulikov 43fc4ccf40 [FIR] Source for implicit iterator calls in for should not be null
^KT-62111 fixed


Merge-request: KT-MR-13029
Merged-by: Egor Kulikov <Egor.Kulikov@jetbrains.com>
2023-11-22 17:15:24 +00:00
Roman Golyshev 347d51c90e KTIJ-27879 [AA] Enforce lazy resolve of code fragments in ContextCollector
Without it, the lazy body of code fragment is not properly resolved
and cannot be analyzed

Use the correct function from `BodyResolveContext` to take the scopes
from code fragment into account

^KTIJ-27879 Fixed
2023-11-22 16:29:28 +00:00
Dmitrii Gridin d450c1e91f [LL FIR] encapsulate FileAnnotationContainer resolution logic
As a file annotation container is required for resolution,
it should be closer to the resolution logic. Now only LLFirTargetResolver
will operate this logic, so we can change the logic in the future without
a big refactoring.
E.g., as the next step, this resolution can be integrated to the file

^KT-63042
2023-11-22 11:02:09 +00:00
Dmitrii Gridin bc1e9fd2ea [LL FIR] LLFirTargetResolver: introduce resolveDependencyTarget step
This entry point is required to be able to pre-resolve dependency
declarations.
E.g., fake override declaration shares annotation instances between
the original and the fake one, so we should resolve the original
firstly to avoid concurrent modification and correct context.
This will be done later.

This commit effectively only drops body resolution for a file annotation
container if the target element is not a file because this
is not required for correct resolution

^KT-63042
2023-11-22 11:02:09 +00:00
Dmitrii Gridin 0b07b86ec9 [FIR] make FirLazyDeclarationResolver FirElementWithResolveState-based
This is required to be able to call lazy resolve for FirFileAnnotationsContainer

^KT-63042
2023-11-22 11:02:09 +00:00
Kirill Rakhman 865b8a4175 [FIR] Create special hidden override for Java signature clash due to rename
This fixes CharBuffer.get resolving to CharBuffer.charAt

#KT-61282 Fixed
2023-11-22 08:46:17 +00:00
Alexander Udalov 471f25abfc IR: support buildSimpleType for IrCapturedType
To make it possible to change nullability of IrCapturedType and change
its annotations, which is happening when determining overridability of
functions via IR.

 #KT-63437 Fixed
2023-11-21 20:02:13 +00:00
Roman Golyshev f5131d0be2 KTIJ-27730 [AA] Do not shorten constructors of nested classes by default
The relevant tests are in the `intellij` repo

^KTIJ-27730 Fixed
2023-11-21 18:52:57 +00:00
Pavel Kirpichenkov 5729fab8c4 Fix deprecation warning
KTIJ-27752
2023-11-21 18:43:06 +00:00
Pavel Kirpichenkov 645e4af8b1 [IDE] Move KotlinJavaScriptMetaFileDecompiler to kotlin.git
KTIJ-27752
2023-11-21 18:43:06 +00:00
Pavel Kirpichenkov b41c4bc4c1 [IDE] create KotlinLabelProviderService on request
getServiceIfCreated doesn't create a service instance if id wasn't
created before. There are no other service requests for
KotlinLabelProviderService, so it was not used for file types.

KTIJ-27755
2023-11-21 18:43:06 +00:00
Mikhail Glukhikh 0c61ce61c3 K2: for Java source override, don't compare return types in override checker
#KT-57044 Fixed
2023-11-21 18:11:58 +00:00
Roman Golyshev 7d7256536c KT-63627 [AA] Properly handle object declarations when traversing scopes in KtFirReferenceShortener
`KtClass` denotes only classes, interfaces and enums.
To handle object declarations, we now use
`KtClassOrObject` PSI type

^KT-63627 Fixed
2023-11-21 18:08:43 +00:00
strangepleasures 7c6375c85a KT-63552 [SLC] Support empty arrays in property initializers and default parameter values 2023-11-21 13:20:26 +00:00
Marco Pennekamp 166964bfcc [LL] Declaration modification service: Discover contract removal in "element removed" events
- PSI tree change events from the IDE aren't necessarily paired. For
  example, when we delete a contract statement via `PsiElement.delete`,
  only "after removal" PSI tree change events will be published.
- Previously, the declaration modification service would not see such
  contract removal as an out-of-block modification because it didn't see
  the already removed contract in the associated function. As there is
  no "before removal" event, the service had no chance to discover the
  contract removal.
- This fix adds the removed element as a property of `ModificationType`.
  While the element will already be removed and its parent will be a
  dummy holder, we can still analyze its PSI to determine whether it is
  a contract.

^KT-63538 fixed
2023-11-21 13:12:29 +00:00
Marco Pennekamp 4efe7a00f1 [AA] KtFirSymbolContainingDeclarationProvider: Support EnumGeneratedDeclaration in getContainingPsi
- The root cause of the exception in KT-62982 is that symbol light
  classes are accessed in dumb mode (see KT-63490). Nonetheless, we can
  patch the exception by supporting `EnumGeneratedDeclaration` in
  `getContainingPsi`.
- To create a symbol from the containing PSI,
  `KtFirSymbolContainingDeclarationProvider` will still try and fail to
  find the enum class symbol via symbol providers, but it'll fall back
  to a designators search in the same `FirFile`, which will find the
  symbol without index access (see `findSourceNonLocalFirDeclaration` in
  LL API's `declarationUtils.kt`).

^KT-62982 fixed
2023-11-21 11:38:40 +00:00
Marco Pennekamp dd23415793 [AA] Improve coding conventions of KtAnalysisSession
- This commit rewords the coding conventions around `KtAnalysisSession`
  and forbids usage of class context receivers. As explained in the
  KDoc, classes opaquely capture their context receivers as properties,
  which is a high-risk source of leakage.
2023-11-21 11:37:55 +00:00
Ivan Kylchik fd4a3a0b88 [FIR] Forbid to use equality and unsigned comparison in const expression
#KT-62683
2023-11-21 09:48:58 +00:00
Ivan Kylchik 8715bd6189 [IR] Don't evaluate expressions in inner class of an annotation 2023-11-21 09:48:58 +00:00
Ivan Kylchik 3fa82c7bb1 [K2] Properly evaluate complex boolean constants
Some boolean expressions could be transformed into `IrWhen`
node. To understand that this node is actually
a boolean expression, we need to analyze its origin.

#KT-62683
2023-11-21 09:48:57 +00:00
Dmitrii Gridin 0b253dc815 [FIR] resolve delegate field return type in correct scope
We should resolve it in the same way as delegate constructor call
to avoid access to nested class scopes

^KT-63522 Fixed
^KT-63042
2023-11-21 08:11:21 +00:00
Dmitrii Gridin ab6b3a6047 [LL FIR] fix scope for constructor resolution
We should grab static scope before in the same way as scopesBefore
to not get already updated static scope with nested scopes.
Also, we should restore such "before" snapshots to avoid their modification
(this can be reproduced with in the next commit)

^KT-63042
2023-11-21 08:11:21 +00:00
Dmitrii Gridin a9aa0e020a [LL FIR] add tests for constructors
We are resolving delegated constructor call in the wrong context
```
TYPES:
FILE: [ResolvedTo(IMPORTS)] superTypeCallNameClash.kt
    public? open [ResolvedTo(SUPER_TYPES)] class Base : R|kotlin/Any|
    public? final? [ResolvedTo(TYPES)] class MyClass : R|second/Base| {
        public? [ResolvedTo(TYPES)] [ContainingClassKey=MyClass] constructor(): R|second/MyClass| {
            LAZY_super<R|second/MyClass.Base|> // should be R|second/Base|
        }

        public? open [ResolvedTo(RAW_FIR)] class Base : R|kotlin/Any|
    }
```

^KT-63042
2023-11-21 08:11:21 +00:00
Dmitrii Gridin b3b184f00d [FIR] add more tests diagnostic tests on data and delegated classes
^KT-63522
^KT-63512
^KT-63042
2023-11-21 08:11:20 +00:00
strangepleasures 03ed1d1d31 KT-62560 [SLC] Fix handling of empty varargs in annotations 2023-11-20 20:57:21 +00:00
Roman Golyshev 4f5926a88f KT-62675 [AA] Handle labeled this expressions in reference shortener
At the moment, there is no good way to meaningfully filter `this`
expressions. The filters for the reference shortener can work only with
symbols, and it does not make a lot of sense to check any particular
symbol when deciding whether to shorten a labeled `this` expression.

We would probably need a better API for the shortener to be able
to filter more precisely (see KT-63555)

^KT-62675 Fixed
2023-11-20 20:18:18 +00:00
Roman Golyshev d47557067c KT-62675 [AA] Get rid of second override of ElementsToShortenCollector.addElementToShorten
Those two overrides were odd - one of them was deconstructing
`ElementToShorten` into its fields, and the other one was
re-constructing it back
2023-11-20 20:18:17 +00:00
Roman Golyshev 12fbc3384e KT-62675 [AA] Refactor ElementsToShortenCollector.createElementToShorten
Use it more instead of the constructor calls
2023-11-20 20:18:17 +00:00
Roman Golyshev 132467ae1e KT-62675 [AA] Simplify ElementToShorten hierarchy
Clearly separate `ShortenKDocQualifier` from it,
it does not belong there for now
2023-11-20 20:18:16 +00:00
Roman Golyshev 6b48ec7780 KT-62675 [AA] Refactor KtFirReferenceShortener.kt
Separate FIR visitor from collector
2023-11-20 20:18:16 +00:00
Svyatoslav Kuzmich 7092541e34 [Wasm] K2 js(code) constant checker (KT-56849)
Reuse K/JS FirJsCodeConstantArgumentChecker by moving it to web.common
2023-11-20 18:10:54 +00:00
Mikhail Glukhikh 3ff16f7798 K2: split JavaTypeParameterStack to mutable/immutable
#KT-62314 Fixed
2023-11-20 17:00:03 +00:00
Marco Pennekamp b43ceab880 [AA] Avoid running modifiable PSI tests on the EDT
- `runWriteCommandAction`, which is required for PSI modification
  functions like `PsiElement.delete`, must be invoked on the EDT.
  However, instead of `runWriteCommandAction` we can use
  `runUndoTransparentAction`, which does not need to be run on the EDT
  and fulfills the same requirement.

^KT-63560
2023-11-20 16:29:26 +00:00
Marco Pennekamp 1870189e47 [AA] Fix write access configuration in unit test application environments
- We cannot configure the application's write action accessibility on a
  per-test basis because (1) the application may be shared across
  concurrent tests and (2) the application is usually cached, so the
  configuration will be missed entirely.
- There is actually a much easier solution to allow write access
  selectively: We can enable it in `runWriteAction` blocks, and keep it
  in a thread local to support concurrent test runs. As Analysis API
  tests never call `runWriteAction`, there will be no "analyze cannot be
  called from a write action" error, and if `analyze` is somehow called
  from a write action, it will now be caught.

^KT-63560 fixed
2023-11-20 16:29:26 +00:00
Mikhail Glukhikh 3b7f43a9c2 K2: don't throw an exception for type parameter case in isJavaTypeOnThePath
#KT-63569 Fixed
2023-11-20 15:35:58 +00:00
Evgeniy.Zhelenskiy f5168527ae [FIR] Report type-parameterized implicit invoke call over type-parameterized property access
^KT-59988
2023-11-20 14:59:06 +00:00
Dmitrii Gridin ea8a645513 [LL FIR] FirLazyBodiesCalculator: do not touch declarations during file annotation calculation
It leads to many problems in concurrent case.
E.g., we can transform the status of a declaration without the lock

^KT-62947 Fixed
2023-11-20 13:41:30 +00:00
Dmitriy Novozhilov 3dff232710 [FIR2IR] Generate IR for unbound symbols in allowNonCachedDeclarations mode
`allowNonCachedDeclarations` mode allows referring source declaration which
  does not belong to the set of sources passed to fir2ir (e.g. for debugger
  support). So if code refers to such declaration, fir2ir creates symbol
  for it but not the IR declaration itself
2023-11-20 13:36:27 +00:00
Mikhail Glukhikh bb8002d9f1 K2: reproduce KT-60604 2023-11-20 10:32:05 +00:00
Mikhail Glukhikh a139965231 K2: reproduce KT-63164 2023-11-17 20:29:58 +00:00
Marco Pennekamp 271f83d07d [LL] Disable declaration modification service tests temporarily
- We cannot configure write access using the application environment
  creation because application environments are cached between test
  runs.

^KT-63560
2023-11-17 18:09:55 +00:00
Aleksandra.Arsenteva af63763da2 KT-62138 add testcases 2023-11-17 15:47:34 +00:00
Artem Kobzar e64068cf82 [K/JS, K/Wasm, K/Native] Process anonymous initializers inside classes as a part of their primary constructors ^KT-61929 Fixed 2023-11-17 13:04:34 +00:00
Ilya Kirillov 364dcd30c8 [LC] optimize String allocations in org.jetbrains.kotlin.asJava.LightClassUtil.isMangled
^KT-63486 fixed
2023-11-17 07:19:14 +00:00
Stanislav Ruban 6edc742934 [tests] builder inference test-set: regenerate diagnostic & codegen tests 2023-11-17 07:02:15 +00:00
Mikhail Glukhikh ce381f335d K2: reproduce KT-56614 2023-11-16 20:12:34 +00:00
Marco Pennekamp 6668cc281d [LL] Avoid exceptions when analyzing inconsistent PSI in LLFirDeclarationModificationService
- The exceptions in KT-63130 occur because PSI tree change events may be
  published when parts of the PSI under modification are inconsistent.
  Such inconsistent elements are then analyzed by
  `LLFirDeclarationModificationService` to check if the modification
  occurs in a contract statement.
- The solution adds `*OrNull` functions to `KtQualifiedExpression` which
  return `null` instead of failing with an exception when the receiver
  or selector cannot be found.

^KT-63130 fixed
2023-11-16 19:50:51 +00:00
Marco Pennekamp 6c67835128 [LL] Add PSI resilience tests for LLFirDeclarationModificationService
- The cause of KT-63130 is that `LLFirDeclarationModificationService`
  tries to analyze inconsistent PSI. These new tests replicate the
  inconsistent PSI by deleting different children and then call the
  declaration modification service with it, making sure that the service
  doesn't throw any exceptions. Both exceptions mentioned in the issue
  are reproduced by the added tests, specifically, the receiver and
  selector resilience tests for dot-qualified expressions.
- A few of the tests need to be marked with `IGNORE_FIR` until the error
  has been fixed in the subsequent commit.

^KT-63130
2023-11-16 19:50:51 +00:00
Marco Pennekamp 12b6096b67 [LL] Add a test base for PSI-modifying low-level API tests
- To support PSI modification, the test environment requires some
  additional configuration, which is encapsulated in
  `AnalysisApiPsiModificationTestServiceRegistrar`.
- The test also has to allow write access explicitly, which is
  configured in `AnalysisApiFirModifiablePsiSourceTestConfigurator`.
2023-11-16 19:50:51 +00:00
Marco Pennekamp 03a7162f37 [AA] Enable test-specific configuration of write access permissions
- In general, Analysis API tests forbid write access because the
  Analysis API should not be used from write actions. However, in some
  cases we might want tests to e.g. modify PSI, which requires write
  access. This change allows `AnalysisApiTestConfigurator`s to enable
  write access for the specific test.
2023-11-16 19:50:51 +00:00