Commit Graph

3747 Commits

Author SHA1 Message Date
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
Nikolay Lunyak a9ceae9667 [FIR] Add the privateInFileInDifferentModule test
We only see the redeclaration
diagnostics on the declarations inside
the second file, because of
`FirRecorder::visitRegularClass`.
`data.state.classifierContainerFileMap`
references the last file, so
when checking the visibility of
the first `private class C { ... }`
(when collecting declarations that
conflict with the second `private class C`)
the provider returns the second file
instead of the first one, so the class
behaves as it is visible, and
`collectTopLevelConflict` returns in
this case.

As for why `INVISIBLE_*`s are reported
inside the first file: this is because
`data.state.classifierMap` stores the
last classifier it sees instead of
the first one.

^KT-62537
2023-10-13 11:56:54 +00:00
Ilya Kirillov ba37ad9b85 [build] remove obsolete -opt-in=kotlin.ExperimentalStdlibApi from :analysis:proejct-structure module 2023-10-13 11:49:55 +00:00
Marco Pennekamp a62ac940c4 [AA] Add abstraction for composable Kotlin providers
This further improves the `KotlinCompositeProvider` abstraction:

- Pulling the abstraction's interfaces outside the `impl` package allows
  us to write consolidated documentation on composable Kotlin providers.
- The addition of `KotlinComposableProvider` allows more specific bounds
  for the type parameters of `KotlinCompositeProvider` and
  `KotlinCompositeProviderFactory`. It also clarifies to Analysis API
  implementors which providers can be composed at all, as providers like
  `KotlinDeclarationProvider` extend this interface.
- `KotlinComposableProviderMerger` provides a unified interface for
  provider mergers.

^KT-61791
2023-10-12 16:10:32 +00:00
Marco Pennekamp c289da6cf3 [LL FIR] Use mergePackageProviders in LLFirCombinedKotlinSymbolProvider
^KT-61791
2023-10-12 16:10:32 +00:00
Marco Pennekamp b9e3d848a6 [AA] Add KotlinPackageProviderMerger
- In parallel to Kotlin declaration provider merging, we need a proper
  merging strategy for package providers as well, because resolve
  extensions may define additional package providers.
- Additionally, other non-scope-based package providers may be added in
  the future, and the merger preserves these out of the box.

^KT-61791
2023-10-12 16:10:32 +00:00
Marco Pennekamp c63dde4f7e [AA] Add abstraction for composite provider creation and merging
- Composite declaration providers and declaration provider mergers are
  extremely similar to the composite package providers and (newly to be
  implemented) package provider mergers. This commit extracts the common
  parts into a `KotlinCompositeProviderFactory`.

^KT-61791
2023-10-12 16:10:32 +00:00
Marco Pennekamp 0e6cc92958 [LL FIR] Optimize getPackage in combined Kotlin symbol providers
- `getPackage` can also benefit from a combined index access.
- Care has to be taken with allowed/disallowed `kotlin` packages. Since
  we're not delegating to individual symbol providers after the index
  access, `allowKotlinPackage` has to be taken into account in the
  combined symbol provider explicitly.

^KT-61791 fixed
2023-10-12 16:10:32 +00:00
Jaebaek Seo a6c432587f K2: Add extension point for additional KDoc resolution
Similar to K1 KDocLinkResolutionService used by Fe10KDocReference (to
support additional KDoc resolution), this commit adds K2 counterpart
AdditionalKDocResolutionProvider and uses it for KDocReferenceResolver.

^KT-62187
2023-10-12 15:17:31 +00:00
Ilya Kirillov 34ea0678ae [Analysis API Standalone] refactoring, use predefined paths to libraries in StandaloneSessionBuilderTest wher it's possible 2023-10-12 15:15:05 +00:00
Ilya Kirillov 4d38cc4548 [Analysis API Standalone] fix exception on invalid KLib from symbol provider
^KT-62244 fixed
2023-10-12 15:15:05 +00:00
Svyatoslav Kuzmich a10042f909 [Wasm] Add K2 checkers.wasm module (KT-56849)
Add first K2 checker ExternalInheritanceChecker to test the infra
2023-10-12 13:26:58 +00:00
Roman Efremov a05b37c652 [K2] Support reporting of SUPERTYPE_INITIALIZED_IN_EXPECTED_CLASS
...on regular classes and enum entries.

^KT-59979 Fixed
2023-10-12 13:01:40 +00:00
Nikolay Lunyak 598b5dbdf4 [FIR] Reproduce KT-62146 2023-10-12 08:56:12 +00:00
Alejandro Serrano Mena 166b99181b [Test] Ensure that properties cannot be used as operators
In some cases the combination of property + invoke was incorrectly allowed

^KT-62349
2023-10-12 08:32:17 +00:00
Nikolay Lunyak 54e9cafc73 [FIR] Reproduce KT-62473 2023-10-11 08:33:05 +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 17b8d59e4b [AA] Include inner classes in non-static Java declared member scopes
- `FirNoClassifiersScope` erroneously filtered out inner classes from
  non-static Java declared member scopes.

^KT-61800
2023-10-10 13:38:00 +00:00
Marco Pennekamp 17e181885f [AA] Restrict FirJavaDeclaredMembersOnlyScope to non-local classes
- Comparing the callable ID with the owner's class ID is the simplest
  way to check whether a callable is declared inside an owner class.
  However, this does not work for local classes, because they do not
  have proper class IDs. The same issue occurs when trying to get the
  containing class, because it is a lookup tag search in symbol
  providers.
- Given that the scope is only needed for Java classes and local Java
  classes cannot leak from function bodies, the easiest solution is to
  disallow creating this scope for local classes.

^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 9fa0dfe4bc [AA] Allow inner classes in non-static declared member scopes
- An inner class `Inner` in a class `Outer` is accessible as
  `Outer().Inner()` and should thus be part of the non-static declared
  member scope.
- Related issue containing a discussion about inner classes in use-site
  scopes: KT-62023.

^KT-61800
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 8b24baade9 [AA] Refactoring: Simplify JavaClassDeclaredMembersEnhancementScope
- `JavaClassDeclaredMembersEnhancementScope` actually had nothing to do
  with Java enhancement, so it is easily replaceable with a more general
  `FirDeclaredMembersOnlyScope`.

^KT-61800
2023-10-10 13:38:00 +00:00
Marco Pennekamp 7a7a923197 [AA] Add getCombinedMemberScope to KtScopeProvider
- The function is mostly for convenience, but scope providers will be
  able to optimize this scope if needed (similar to how combined
  declared member scopes are already optimized).
- `getCombinedMemberScope` will be used by `KDocReferenceResolver`.

^KT-61900
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 df54540a81 [AA] Update usages of declared member scopes
- Now that non-static declared member scopes don't contain static
  callables anymore, we have to update some usages in the Analysis API.
- In symbol light classes, many usages of `getDeclaredMemberScope` can
  be kept as-is because Kotlin classes/objects generally cannot declare
  static callables (and we do not need to create symbol light classes
  for Java classes). The only exception are enum classes, which
  implicitly declare some static callables.

^KT-61800
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 4ba0aef23b [AA] Refactoring: Simplify member scope test classes
^KT-61900
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
Marco Pennekamp dc689952cb [AA] Fix isDeclared for static callables in Java declared member scope
- Static callables don't have a `dispatchReceiverType`, but certainly a
  `CallableId`.

^KT-61800
2023-10-10 13:37:59 +00:00
Marco Pennekamp e5bfcfc9fc [AA] Refine documentation of getMemberScope and getStaticMemberScope
^KT-61900
2023-10-10 13:37:59 +00:00
Marco Pennekamp 71017298d9 [AA] Provide separate non-static and static declared member scopes
- Member scopes already don't contain static callables, only their
  static member scope counterparts. However, declared member scopes
  contained both non-static and static callables, which was confusing to
  users. See for example KT-61255.
- Now declared member scopes only contain non-static callables and
  static declared member scopes only contain static callables.
- In `KtFirScopeProvider`, the new implementation is different for
  Kotlin and Java classes, because the standard declared member scope
  doesn't work for Java. Instead, we have to get the Java *enhancement*
  scopes from `JavaScopeProvider`. Unfortunately, `JavaScopeProvider`
  doesn't have a direct enhancement declared member scope. This results
  in a somewhat complex scope structure with the declared members filter
  scope around the use-site/static Java enhancement scope, but since the
  declared members filtering scope properly reduces the set of callable
  names and scopes in general are cached, this shouldn't be an issue.
- `getCombinedDeclaredMemberScope` is introduced as a separate public
  function because for Kotlin scopes, we don't actually have to create a
  combined scope, as the non-static and static scopes are just filters
  around a combined declared member scope provided by the compiler. It's
  also important to have a convenient function to get the combined
  declared member scope, because some usages explicitly want access to
  all declared members (such as symbol light classes).
- This commit also fixes KT-61901, because
  `getFirJavaDeclaredMemberScope` now provides a proper static scope for
  Java classes, which will be accessible via the combined declared
  member scope as well.

^KT-61800 fixed
^KT-61901 fixed
^KT-61255 fixed
2023-10-10 13:37:59 +00:00
Dmitrii Gridin 5ebef0dfd1 [LL FIR] simplify common library symbol provider
createCommonLibrarySymbolProvider is simplified to avoid module clashes
and extra search

^KTIJ-27159
^KT-58325
2023-10-09 22:47:32 +00:00
Brian Norman 79303ab2db [FIR] Ignore anonymous functions during annotation argument phase
Anonymous functions (lambdas) are not allowed as annotation arguments.
However, because it is still possible to parse code written this way, it
must be handled without exception. So ignore these expressions when
processing annotation arguments.

#KT-59565 Fixed
2023-10-09 20:03:33 +00:00
Marco Pennekamp 223c793258 [SLC] Order parent classes before nested classes in structure test results
- This improves the readability of the result files.
2023-10-09 19:46:51 +00:00
Marco Pennekamp cd8143af7b [SLC] Fix nested classes missing in SLC structure tests for libraries
^KT-62038 fixed
2023-10-09 19:46:51 +00:00
Marco Pennekamp 315573d99f [SLC] Add SLC structure tests for nested classes
^KT-62038
2023-10-09 19:46:51 +00:00
Anna Kozlova 79193006ce [LC] light methods should provide type parameters for on the fly resolve
References inside LC apis are build over `ClsJavaCodeReferenceElement`,
which simplifies resolve by providing precalculated data.
When refactorings or quick fixes do on the fly resolve,
giving only text and LC context,
such precalculated data is not available and normal resolve starts.
In order for this resolve to work correctly,
LC should provide available declarations

Corresponding test in monorepo: `KotlinSymbolOnAirResolveTest`

^ KT-62440 fixed
2023-10-09 15:42:52 +00:00
Nikolay Lunyak 973248f432 [FIR] Reproduce KT-57100 2023-10-09 06:55:43 +00:00
Dmitrii Gridin f124ba627d [FIR] implicit type: avoid redundant property and function transformations
This is a contract violation – we can touch only bodies during this phase

^KT-56551
2023-10-06 14:13:37 +00:00
Dmitrii Gridin ddc4fac896 [FIR] add missing transformation of type parameters during annotation arguments phase
^KT-56551
2023-10-06 14:13:36 +00:00
Dmitrii Gridin 61063a19b6 [FIR] add missing transformation of backing field during annotation arguments phase
^KT-56551
2023-10-06 14:13:36 +00:00
Dmitrii Gridin 889c210576 [FIR] add more tests for implicit type phase
These tests demonstrate the implicit type phase problem - annotations
are also resolved, although they should not

^KT-56551
2023-10-06 14:13:36 +00:00
Dmitrii Gridin d4bc5dc717 [LL FIR] add more tests on lazy resolution for implicit type phase
These tests demonstrate the implicit type phase problem - annotations
are also resolved, although they should not

^KT-56551
2023-10-06 14:13:36 +00:00