Commit Graph

592 Commits

Author SHA1 Message Date
Ilya Kirillov 7db2fc522e [Analysis API Standalone] fix builtin resolution for common module
StubBasedBuiltInsSymbolProvider does not work for now for common modules (KT-61757)
 but compiler builtins provider `FirBuiltinSymbolProvider` works.

Also, stub-based symbol providers should not be used in standalone mode.

Testdata from standalone is updated because of the difference
in property accessors (KT-62449) between stub and compiler builtin symbol providers.

Additionally, this commit fixes the behavior of `KotlinStaticPsiDeclarationFromBinaryModuleProvider`.
As compiler builtin declarations have no PSI attached,
`KotlinStaticPsiDeclarationFromBinaryModuleProvider` is used to get PSI
from `DecompiledPsiDeclarationProvider.findPsi`.
`DecompiledPsiDeclarationProvider` is only used in UAST standalone mode.
2023-10-17 13:23:11 +00:00
Evgeniy.Zhelenskiy 5b4731a780 [FIR] Fix local typealias visibility resolution
#KT-60026
2023-10-17 12:48:04 +00:00
Dmitriy Novozhilov 8ccbbedbd5 [Test] Update debugger testdata because of KT-62521 2023-10-17 12:46:28 +00:00
Roman Golyshev d2fcd71d23 KTIJ-27139 [AA] Shorten qualified expressions only when the callee/type reference is in selection
If you want to shorten call like `foo.bar()` into `bar()`, then you
need your range to intersect with `bar` callee reference. Having only
`foo` in the range is not enough

Same goes for the type references - to shorten `foo.Bar` into `Bar`, you
need at least some intersection of your range with `Bar` reference

^KTIJ-27139 Fixed
^KTIJ-27015 Fixed
2023-10-16 20:05:01 +00:00
Dmitrii Gridin 5de269147f [LL FIR] add tests for synthetic property
^KT-61990
2023-10-16 15:07:11 +00:00
Anna Kozlova 3c2be4551b [AA] getExpectedType should not calculate expression type
if property doesn't specify explicit type,
property's return type would be calculated by provided initializer

^KT-62588 fixed


Merge-request: KT-MR-12564
Merged-by: Anna Kozlova <Anna.Kozlova@jetbrains.com>
2023-10-16 09:31:52 +00:00
Dmitrii Gridin 4d29d6e3b4 [LL FIR] FileStructure: accurate processing of generated declarations inside classes
We should process generated property as a part of the primary constructor.
This was already implemented in 8387ea8a, but some parts were missed.

ClassDiagnosticRetriever:
* dropped relation to properties generated from constructor parameters
as they should belong to the primary constructor only
* accurate logic to fully visit an implicit primary constructor to be
able to process nested declarations (e.g., inside a super type call)

SingleNonLocalDeclarationDiagnosticRetriever:
* add relation to generated properties as now they fully belong to
the constructor

FileElementFactory:
* dropped explicit resolution of generated properties from a constructor
* added explicit resolution of generated enum members for consistency.
Effectively, this is not required because we don't have compiler
checkers for such generated enum member declarations

ClassDeclarationStructureElement:
* do not collect mapping for generated properties from constructor
* explicitly declare that we should process only ClassDelegationField

^KT-62437 Fixed
2023-10-13 17:13:14 +00:00
Dmitrii Gridin 1a01dd4dd4 [Analysis API] add diagnostic tests for unresolved reference inside primary constructor
^KT-62437
2023-10-13 17:13:14 +00:00
Dmitrii Gridin b2c8d7e777 [FIR] do not treat external ide annotations as real one
Such annotations are supposed to affect only diagnostic warnings

^KT-62310 Fixed
2023-10-13 12:16:12 +00:00
Dmitrii Gridin 2cac922cd0 [FIR] add tests on external annotations
Tests are excluded in COMPILED_JAVA mode because in this
mode external annotations are not present at all

^KT-62310
2023-10-13 12:16:12 +00:00
Anna Kozlova 1f4d985b7b [AA] include inferred types in functional exp expected type
Fixed for K2 only, k1 remains as is

^KT-62466 fixed
2023-10-10 14:06:48 +00:00
Ilya Kirillov c32e7c723d [Analysis API] resolve [this] in KDoc to extension receiver
^KT-62407 fixed
2023-10-10 14:03:49 +00:00
Marco Pennekamp dab06c0942 [AA] Cover both static and inner classes in Java member scope tests
^KT-61900
2023-10-10 13:38:00 +00:00
Marco Pennekamp ab717c25d7 [AA] Avoid duplicate inner classes in Java declared member scopes
- Java combined declared member scopes are implemented as a composition
  of the non-static and static scope, so we have to exclude inner
  classes from the non-static scope to avoid duplicates.
- This is not an issue for Kotlin combined declared member scopes,
  because the combined scope is already the base scope.

^KT-61800
2023-10-10 13:38:00 +00:00
Marco Pennekamp 3d1262140d [AA] Add member scope tests for inner classes
^KT-61900
2023-10-10 13:38:00 +00:00
Marco Pennekamp 239cfa6d29 [AA] Add tests for combined declared member scopes
^KT-61800
2023-10-10 13:38:00 +00:00
Marco Pennekamp 5679acbbdb [AA] Remove classifiers from non-static declared member scopes
- The semantics of a non-static declared member scope should be as
  follows: For a variable `c: C` of class type `C`, the declared member
  scope should contain all members `x` accessible as `c.x` (visibility
  notwithstanding) which are *also* explicitly declared in `C`.
- Classifiers are not accessible as properties of a variable `c`, only
  as static members of the class `C` itself, so non-static declared
  member scopes should not contain any classifiers.

^KT-61800
2023-10-10 13:38:00 +00:00
Marco Pennekamp 1408556511 [AA] Refactoring: Rename AbstractMemberScopeByFqNameTest to AbstractMemberScopeTest
^KT-61900
2023-10-10 13:38:00 +00:00
Marco Pennekamp 9db9f58fba [AA] KtFirSymbolProviderByJavaPsi: Remove workaround for missing static callables in Java declared member scopes
- Now that combined declared member scopes for Java classes contain
  static callables, we don't need to search symbols in the static member
  scope. (Note that the static member scope is too broad for this use
  case, as it contains symbols from superclasses, but we only need to
  look at declared members because the correct `containingClass` is
  already chosen.)

^KT-61901
^KTIJ-25126
2023-10-10 13:38:00 +00:00
Marco Pennekamp 21efd6aff3 [AA] Add tests for *static* (declared) member scopes
^KT-61900
^KT-61800
2023-10-10 13:38:00 +00:00
Marco Pennekamp c2d08b9462 [AA] Add additional tests for declared member scopes and member scopes
^KT-61800
2023-10-10 13:37:59 +00:00
Ilya Kirillov 9dcd142f0d fixup! [Analysis API] implement an API to get a substitution based on a inheritance relationship between classes 2023-10-06 11:39:33 +00:00
Ilya Kirillov 8f6b3d37b9 fixup! [Analysis API] implement an API to get a substitution based on a inheritance relationship between classes 2023-10-06 11:39:33 +00:00
Ilya Kirillov 15e4cbc10d [Analysis API] implement an API to get a substitution based on an inheritance relationship between classes
^KT-62090 fixed
2023-10-06 11:39:33 +00:00
Ilya Kirillov 64f90f685d [Analysis API] create declarations from a library with library origin in StubBasedFirDeserializedSymbolProvider 2023-10-05 17:01:40 +00:00
Ilya Kirillov 68c7673cb3 [Analysis API FIR] fix ISE "Status should be resolved for a declaration to create it fake override"
on calling completion on an instance of `kotlin.Pair`.

Caused by unresolved status for `copy` created for data classes from a library.

^KT-62268 fixed
2023-10-05 17:01:40 +00:00
Anna Kozlova da385210d8 [AA] provide psiType#asKtType conversion
it's useful for IDE's features such as write UAST or refactorings

^KT-62302 fixed

Merge-request: KT-MR-12414
Merged-by: Anna Kozlova <Anna.Kozlova@jetbrains.com>
2023-10-05 15:18:55 +00:00
Egor Kulikov 057973f4bb [FIR] Fix NPE on invalid gets with index
^KT-60342 fixed
2023-10-03 22:34:46 +00:00
Yan Zhulanow 715f7d1a35 [LL API] Analyze code fragment in a separate 'FirSession'
Before, `KtCodeFragment`/`FirCodeFragment` was analyzed as a part of
its context `KtModule`. This has the following complications:

- In non-source sessions, diagnostic reporting is globally disabled.
  For code fragments, however, checking the code before passing it to
  the backend is essential.

- Special treatment for call ambiguities in libraries
  (`LLLibraryScopeAwareCallConflictResolverFactory`) becomes complicated
  as the conflict resolver has to be applied to a library module.

- `KtCodeFragment`s usually have a shorter lifetime than their own
  context. Caching may potentially be implemented differently for them.

^KT-61783 Fixed
2023-09-22 12:20:05 +00:00
Yan Zhulanow 9ef58f2bdb [LL API] Collect syntax errors in 'KtFirCompilerFacility'
^KTIJ-27167 Fixed
2023-09-22 11:39:49 +00:00
Ilya Kirillov d98da87278 [FIR] Render dot-separated FQNs instead of slash-separated ones in diagnostics
^KT-62030 fixed
2023-09-22 10:48:31 +00:00
Yan Zhulanow 834cbaac5a [LL API] Run fir2ir separately for files in different modules
Each module may have its own compiler configuration.

^KTIJ-27061 Fixed
2023-09-21 06:19:15 +00:00
Alexander Udalov 5cae87b263 K2: add package FQ name to ClassId of anonymous objects
This is needed because in order to figure out which declarations are
visible from anonymous objects in terms of overridability (see
`FirVisibilityChecker.isVisibleForOverriding`), we need to get the
package name of that anonymous object, because there's package-private
visibility on JVM.

 #KT-62017 Fixed
2023-09-19 09:32:55 +00:00
Yan Zhulanow 40ecd4bc1e [fir2ir] Fix annotation conversion on partial module compilation
Backend requires annotation constructors to be fully resolved for the
'IrConst' default value lowering. However, in the IDE there is usually
no need in complete annotation class resolution.

^KTIJ-27061 Fixed
2023-09-18 19:48:08 +00:00
Roman Golyshev a78d631b16 KTIJ-27050 [Analysis API] Correctly handle type parameters in KtFirReferenceShortener
Make `FirShorteningContext` correctly return symbols for type
parameters, so they are not ignored when scopes are inspected

Add additional type of `PartialOrderOfScope` - `TypeParameter`, because
otherwise it would have been classified as `Unclassified`, and that
breaks scopes comparison

Add missing type parameters to the scope of class header in
`ContextCollector`, add testdata for that

There is a bug in the compiler with type parameters leaking to nested
classes headers (KT-61959). After it's fixed, the testData with
incorrect expected shortenings/scopes should be adjusted and fixed too

^KTIJ-27050 Fixed
2023-09-18 10:23:30 +00:00
Dmitrii Gridin 1b1e1d5b3f [Analysis API] DebugSymbolRenderer: unify error types
They are still can be different in the case of error inside
type argument (e.g. `kotlin/Array<out ERROR CLASS: Incomplete code>`)
2023-09-14 18:53:25 +02:00
Dmitrii Gridin 2d83509200 [Analysis API Fe10] add missing initializer for properties 2023-09-14 18:53:25 +02:00
Dmitrii Gridin bb470b5504 [Analysis API Fe10] fix isFromPrimaryConstructor 2023-09-14 18:53:25 +02:00
Roman Golyshev 7b50506aea KT-61889 [AA] Migrate KtFirReferenceShortener to ContextCollector
This should make reference shortener considerably faster, since it won't
need to perform redundant extra resolve of the file.

`ContextCollector` more accurately collects the scopes for the scripts,
so some script tests are also fixed.

It should fix the following bugs:

^KTIJ-26714 Fixed
^KTIJ-26727 Fixed

This is also an important part of fixing the following bugs:
- KTIJ-26715
- KTIJ-26734

But those bugs also rely on KT-61890, because completion uses scopes
and snows incorrect elements from them
2023-09-13 16:43:20 +00:00
aleksandrina-streltsova 752ea6fd98 [AA] Add tests for scope context for position
KTIJ-27007
2023-09-12 14:44:23 +00:00
Yan Zhulanow 9514f8f873 [LL API] Fix analysis of functions inside code fragments
FirDeclarationsResolveTransformer.transformSimpleFunction() performs
proper local function analysis only if the parent is properly set.

^KTIJ-26608 Fixed
2023-09-12 13:08:49 +00:00
Yan Zhulanow 11096325c8 [LL API] Fix 'this' capturing inside property accessors
^KTIJ-26726 Fixed
2023-09-12 08:47:28 +00:00
Dmitrii Gridin 3a577e1c31 [Analysis API] add more tests for vararg parameters
^KT-61422
2023-09-11 15:47:47 +00:00
Roman Golyshev 23363ef1bd KT-61728 [LL API] Use ContextCollector in AllCandidatesResolver
Fix testdata for builder inference test in resolve tests - now it's the
same between K1 and K2
2023-09-08 14:41:39 +00:00
Marco Pennekamp 3fa2ca7ddd [AA] Add specific implementation for KtFirEnumEntryInitializerSymbol
- Previously, `KtFirAnonymousObjectSymbol` was a
  `KtEnumEntryInitializerSymbol`, which carried the risk that an
  anonymous object unrelated to enum entries might be used as an enum
  entry initializer. This commit introduces a specific symbol for FIR
  enum entry initializers.
- As a nice side effect, anonymous object symbol creation is simplified
  and `KtFirEnumEntryInitializerSymbolPointer` can restore the symbol
  via `KtFirEnumEntrySymbol.enumEntryInitializer`.

^KT-61425
2023-09-08 11:13:28 +00:00
Marco Pennekamp 536e172d0e [AA] Add declared member scope tests for enum entry initializers
^KT-61425
2023-09-08 11:13:28 +00:00
Marco Pennekamp 72de86a8ba [AA] Add tests for enum class member scopes
^KT-61405
2023-09-08 11:13:28 +00:00
Marco Pennekamp 3aefeb0fc5 [AA] Add tests for enum entry initializer member scopes
^KT-61425
2023-09-08 11:13:28 +00:00
Marco Pennekamp 80efa34926 [AA] Add KtEnumEntryInitializerSymbol
- An enum entry's body is an initializer with members only accessible
  within that body. Because users of the Analysis API might want to
  analyze the members of the enum entry initializer, we expose this
  initializer via `KtEnumEntrySymbol`. The initializer only exists if
  the enum entry has a body.
  - We already have some usages of the initializer inside symbol light
    classes, which generate a light class for each enum entry, which
    includes the enum entry's hidden members.
- To hide the implementation detail that initializers are anonymous
  objects, `KtEnumEntryInitializerSymbol` is simply a
  `KtSymbolWithMembers`.
- The advantage of making it a `KtSymbolWithMembers`, instead of
  providing a custom way to get a member scope, is that we can pass
  around the initializer easily, e.g. in `KtEnumEntrySymbolRenderer`.
- We implement `KtEnumEntryInitializerSymbol` directly as a
  `KtFirAnonymousObjectSymbol` without a wrapper. This has a few
  advantages:
  1. We can directly benefit from the anonymous object symbol being a
     `KtSymbolWithMembers`, so we don't have to handle enum entry
     initializers specially in e.g. `KtFirScopeProvider`.
  2. We don't have to implement a new symbol restoration mechanism for
     the initializer.
  3. This implementation matches the actual FIR tree structure (with a
     simplification that the connecting anonymous object expression
     between the enum entry and the initializing anonymous object is
     omitted).

^KT-61425 fixed
2023-09-08 11:13:28 +00:00
Marco Pennekamp e72a38dc82 [AA] Remove KtSymbolWithMembers from KtEnumEntrySymbol
- An enum entry is a variable which doesn't declare any additional
  members. It must not be confused with its implementing anonymous
  object initializer, which may declare additional members, but is an
  implementation detail hidden outside the enum entry's initializer.
  Hence, the enum entry variable should not have a (declared) member
  scope.
- A following commit will add the ability to get the enum entry's
  initializer, so that a member scope for this initializer can be
  obtained (which might be relevant for local analysis).

^KT-61405 fixed
2023-09-08 11:13:28 +00:00