Commit Graph

525 Commits

Author SHA1 Message Date
Marco Pennekamp 88d307d52c [AA] Add tests for diagnostics suppression on top-level declarations and class members
- `testConflictingOverloadsAtTopLevel` is currently disabled in FIR
  because it fails with a mismatch between diagnostics from the file and
  the individual elements. It will be enabled in the next commit.

^KT-62899
2023-11-13 10:20:26 +00:00
Jaebaek Seo e80f044847 K2: Update reference shortener to handle import alias
The existing reference shortener does not use import alias when it
shortens a symbol. Instead, it adds a new import directive for the
symbol that is already imported. This commit updates reference shortener
to let it reuse the existing import alias rather than adding a new one:

 1. When shortening a symbol, check whether the symbol is already
    imported.
 2. If it is already imported by an import alias, keep the symbol
    reference expression and the import alias as a string together in
    `ShortenCommand`.

The actual PSI update (shortening) based on the ShortenCommand is done
by IntelliJ.

^KTIJ-27205
2023-11-09 14:34:38 +00:00
Ilya Kirillov d2b9b487c7 [Analysis API] add test for resolution into declarations with the kotlin. package
^KT-63223
2023-11-08 17:32:49 +00:00
Ilya Kirillov c54d83dcad [Analysis API] fix resolution to declarations inside kotlin*. packages
`kotlin*.` packages should be always allowed.
`kotlin.` packages should be allowed if `AnalysisFlags.allowKotlinPackage` is `true`

^KT-63223 fixed
2023-11-08 17:32:48 +00:00
Jinseong Jeon 4110a9971a AA: fix KtTypeProvider#getReceiverTypeForDoubleColonExpression
K1 version has used a wrong expression to retrieve the slice.
K2 version mishandled property access as a receiver.

^KT-63195 fixed
2023-11-08 16:18:21 +00:00
Dmitrii Gridin 1173cc46e2 [Analysis API] add constructorSymbol to API of KtAnnotationApplicationWithArgumentsInfo
This is required for some checks on call site, and it seems that
this symbol can cover all cases.
One of the examples why this API was introduced is a request to
distinguish which vararg parameter is missed in arguments
of an annotation call from symbol light classes

^KT-62560
2023-11-07 09:06:00 +00:00
Nikita Bobko e778ddfd21 [AA] getExpectForActual analysis-api now returns compatible or weakly incompatible
^KTIJ-27522 Fixed

It's the only reasonable behavior for this API in it's current shape
(when it returns a list of declarations)

It's a common mistake to take only Compatible from
expectActualMatchingMap. The problem will be gone after I fix KT-62590

Motivation to fix this bug, is because it will be easier for me to split
expect-actual matcher-checker-monster thing KT-62590

Review: https://jetbrains.team/p/kt/reviews/12750/timeline
2023-11-06 14:41:15 +00:00
Roman Golyshev 4ca1f9d492 KT-62676 [AA] Introduce ShortenOptions class
This class should contain 'global' settings for reference shortening;
ATM it only contains the `removeThis` flag

In the future this setting might be merged together with
`ShortenStrategy` to be computed on per-element basis
2023-11-01 09:45:40 +00:00
Roman Golyshev adf7ee4535 KT-62676 [AA] Rename ShortenOption -> ShortenStrategy
`Option` is going to refer to more global settings of the
reference shortener (like shortening `this` or `Companion`
references)
2023-11-01 09:45:39 +00:00
Ilya Kirillov 4720a0faa7 [Analysis API FIR] fix NPE of == call resolve without builtins
We should not expect builtins to be always available as they are taken from indecies.

For K1 and FIR Standalone implementations, the builtins are always available.

^KT-62957 fixed
2023-10-31 12:24:16 +00:00
Ilya Kirillov 1aa5cf031f [Analysis API FIR] fix "ConeClassLikeTypeImpl is not resolved to symbol for on-error type"
We should not expect builtins to be always available as they are taken from indecies.

For K1 and FIR Standalone implementations, the builtins are always available.

^KT-62010 fixed
2023-10-31 12:24:16 +00:00
Ilya Kirillov a90562c0da [Analysis API] support creating KtSymbol by K/JS dynamic scope
^KT-61257 fixed
2023-10-26 19:28:27 +00:00
Bart van Helvert 793e7aa1d1 [AA] Add tests for retrieving field and parameter annotation types 2023-10-26 07:48:18 +00:00
Roman Golyshev 4e4f3075bd KTIJ-26423 [AA] Get rid of FE10 implementation of KtImportOptimizer
As of now, this implementation is not supposed to be used at all

If (for some reason) it becomes relevant again, please refer
to the 7fd441f1 commit which contained a FE10 implementation
of this service (copied from the old FE10 implementation of
import optimizer)
2023-10-25 20:53:14 +00:00
Roman Golyshev a6668919b0 KTIJ-26423 [AA] Remove FE10 tests for KtImportOptimizer
We don't plan to seriously support the FE10 implementation of
`KtImportsOptimizer` service, since it's not going to be used in IDE
(it has its own old version of import optimization logic)
2023-10-25 20:53:13 +00:00
Anna Kozlova e79bc5bb59 [AA] KtExpressionInfoProvider.getMissingCases: fix no subject case
return missing else branch (even if it's present, see kdoc)

^ KT-62875 fixed
2023-10-25 09:41:38 +00:00
Ivan Kochurkin 1827df82c4 Removed useless as casts from compiler code
It allows compiling code with K2 and enabled `-Werror`
2023-10-24 20:59:56 +00:00
Anna Kozlova 5cac013d8c [AA] approximate inplace type parameters bounds
^ KTIJ-27211 fixed
2023-10-24 10:54:15 +00:00
Marco Pennekamp f04b27b90b [AA] Add additional KDoc reference resolution tests for callables
- This adds KDoc reference resolution tests for callables in nested and
  inner classes, overloaded functions, and private callables.
- Private declarations are visible in KDoc from outside their containing
  classes. This is in line with K1 KDoc behavior.

^KTIJ-22324
2023-10-23 23:08:01 +00:00
Marco Pennekamp ef484c7518 [AA] Fix KDoc reference resolution of non-imported companion object members
- Similar to the fix for KTIJ-25995, the name interpretation collector
  needs to consider the companion object's member scope as well.

^KTIJ-25995
2023-10-23 23:08:01 +00:00
Marco Pennekamp 71792f9ad6 [AA] Add test for KDoc reference resolution of sibling nested class 2023-10-23 23:08:00 +00:00
Marco Pennekamp 367b84d45e [AA] Add tests for KDoc reference resolution of companion object members
^KTIJ-25995
2023-10-23 23:08:00 +00:00
Marco Pennekamp 3dbae89cdd [AA] Add tests for KDoc reference resolution of non-static callables
^KTIJ-26003
2023-10-23 23:08:00 +00:00
Roman Golyshev 0747fc36de KTIJ-27434 [AA] Unwrap safe call expression when resolving implicit invoke calls
`FirSafeCallExpression` does not implement `FirResolvable`, so we need
to unwrap it to correctly resolve calls like `foo?.bar()` when `bar` is
a lambda with receiver parameter or a functional type property

^KTIJ-27434 Fixed
2023-10-20 13:27:31 +00:00
Alexander Kuznetsov 45792c2e60 [Analysis API] support unsigned arrays creation functions
IDEA-335151, KT-62663


Merge-request: KT-MR-12614
Merged-by: Alexander Kuznetsov <Aleksander.Kuznetsov@jetbrains.com>
2023-10-18 10:53:52 +00:00
Dmitriy Novozhilov fa69d4837b [AA] Add workaround for KT-62578 2023-10-18 07:59:27 +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 1a01dd4dd4 [Analysis API] add diagnostic tests for unresolved reference inside primary constructor
^KT-62437
2023-10-13 17:13:14 +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 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 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
Nikita Bobko 43c97077eb 2/2 Extract K1 KMP matcher in its own subsystem. Fix compilation errors 2023-10-06 11:41:22 +00:00
Ilya Kirillov 0fb3c033e7 [Analysis API FE10] introduce an exception which marks some parts of the Analysis API as not supported for K1 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
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
Roman Golyshev f5c33ad380 KT-62139 [AA] Remove withValidityAssertion from FE10 implementation of createContextDependentCopy
FIR implementation already does not have this check in
`createContextDependentCopy`, because it's called not
inside `analyze` call, but before it (see
`analyzeInDependedAnalysisSession`)

^KT-62139 Fixed
2023-09-22 14:19:04 +00:00
Dmitriy Novozhilov 9e5ee3afa0 [FE] Add isLocal name to ClassId constructor calls where it needed 2023-09-21 12:40:44 +00: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
Dmitrii Gridin 3a577e1c31 [Analysis API] add more tests for vararg parameters
^KT-61422
2023-09-11 15:47:47 +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
Roman Golyshev f5307173b5 KTIJ-26959 [AA] Do not ignore underscore named properties in KtFirImportOptimizer
After the fix for the KT-60904 issue (c963eadb),
there are unnamed declarations created even for
the unused variables in destructuring declarations

Because of this, we can actually align testData
for K1 and K2. It seems like KT-59504 is no
longer relevant and can be marked as obsolete
because of the KT-60904 fix

^KTIJ-26959 Fixed
2023-09-08 09:19:06 +00:00
aleksandrina-streltsova f18d600dc8 [LL FIR] Return class as structure element for super type reference
^KT-61755 Fixed
2023-09-08 07:25:36 +00:00
Alexander.Likhachev 6eaccc997f [Build] Fix the typo junit jupyter -> jupiter 2023-09-06 22:47:34 +00:00
Alexander.Likhachev 6f96be0b76 [Build] Get rid of the testApiJUnit5 method
#KTI-1349 In Progress
2023-09-06 22:47:34 +00:00
Ilya Kirillov 209d59440b [Analysis API FIR]: fix a freeze on rendering of invalid type arguments
^KT-61750 fixed
2023-09-06 16:05:49 +00:00