Commit Graph

361 Commits

Author SHA1 Message Date
Roman Golyshev d865a44c94 KT-61890 [AA] Add test for ContextCollector at loop variable position
This turns out to be important for conflict resolution in
postfix completion in K2 IDE (see `KotlinDeclarationNameValidator`)
2023-11-14 22:15:05 +00:00
Roman Golyshev 47a00bf97e KT-61890 [AA] Use ContextCollector in KtFirScopeProvider
^KT-61890 Fixed
2023-11-14 22:15:04 +00:00
Roman Golyshev 4f136cde31 KT-61890 [AA] Add testdata to ensure KDoc completion support in IDE
Completion in the IDE relies on correct scopes for KDoc positions.
So we add testData for `KtScopeProvider` and `ContextCollector`
to ensure that there are no regressions
2023-11-14 22:15:04 +00:00
Marco Pennekamp dd219cb6e6 [LL] Commit pending diagnostics from file checkers on script declarations
- In addition to file declarations and class members, we also need to
  commit pending diagnostics on declarations in scripts, to honor
  suppressions before the diagnostics are committed indiscriminately.

^KT-62899
2023-11-13 10:20:26 +00:00
Marco Pennekamp c482786bc4 [AA] Add tests for diagnostics suppression on top-level declarations in scripts
- `scriptUninitializedTopLevelProperty` 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
Marco Pennekamp c9cb2062bd [LL] Commit pending diagnostics from file checkers on top-level declarations
- In KT-62899, diagnostics produced by file checkers weren't suppressed
  because the top-level declarations on which the diagnostics are
  reported were never visited by the same reporter.
  `LLFirDiagnosticVisitor` skips nested declarations by design, as
  diagnostics are collected for each structure element separately.
  However, suppression takes effect when diagnostics are committed on
  some element. If the element is not visited, suppression is skipped
  and the diagnostic is committed at the end without a check by
  `FileStructureElementDiagnosticsCollector.collectForStructureElement`.
- The fix ensures that diagnostics are committed on top-level
  declarations, similar to how this was already done for class members.

^KT-62899 fixed
2023-11-13 10:20:26 +00:00
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
Roman Golyshev 500dd20277 KT-63096 [LL] Add test for using annotation from other module for compiler plugin 2023-11-09 23:39:32 +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
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
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 b0f15451fd KT-62676 [AA] Collect redundant this qualifiers in reference shortener
^KT-62676 Fixed
2023-11-01 09:45:40 +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
Bart van Helvert 793e7aa1d1 [AA] Add tests for retrieving field and parameter annotation types 2023-10-26 07:48:18 +00:00
Roman Golyshev bd92224aec KTIJ-26423 [AA] Ignore artificial Array type from varargs parameters in KtFirImportOptimizer 2023-10-25 20:53:15 +00:00
Roman Golyshev ef31eeae52 KTIJ-26423 [AA] Get rid of the old testdata for KtImportOptimizer
This testdata is some form will be transferred to the `intellij` repo
2023-10-25 20:53:14 +00:00
Roman Golyshev 306f404a69 KTIJ-26423 [AA] Get rid of local declarations in KtFirImportOptimizer
Adjust `computeImportableName` to return null for when passed symbol
is local
2023-10-25 20:53:13 +00:00
Roman Golyshev 421793673b KTIJ-26423 [AA] Extend KtImportOptimizer testdata with imports usage information
`KtImportOptimizerResult.unusedImports` should be removed soon, and
part of the testdata for the import optimizer service should go
to `intellij` repository
2023-10-25 20:53:12 +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
Anna Kozlova 5cac013d8c [AA] approximate inplace type parameters bounds
^ KTIJ-27211 fixed
2023-10-24 10:54:15 +00:00
Roman Golyshev 44d48510b4 KTIJ-26057 [AA] Ignore implicit receivers scope when dealing with types in reference shortener
Implicit receivers generally do not affect the resolution of types.
However, they generate scopes which might contain undesirable
classifiers, which can confuse reference shortener.

Dropping all the implicit receivers when dealing with type references
allows completely avoid such undesirable scopes instead of filtering
them by `instanceof` checks.

Also, temporary move `hasTypeParameterFromParent` check higher to the
`findClassifierElementsToShorten`, because ATM we don't know how to
properly decide whether to shorten the fully-qualified inner types
with implicit parameters or not (see KTIJ-26072).

^KTIJ-26057 Fixed
2023-10-24 07:47:30 +00:00
Marco Pennekamp 72438f4969 [AA] Remove obsolete memberScopeByFqName test data
- The test data was already moved to `memberScope`, but some files were
  not deleted (see: 67ac985be7).
2023-10-20 13:28:12 +00:00
Dmitrii Gridin 17ab005668 [Analysis API FIR] KtSymbolContainingDeclarationProvider: support script declarations
This commit also fixes a missing symbol for KtScriptInitializer
and some symbol pointers
Many tests marked as 'DO_NOT_CHECK_NON_PSI_SYMBOL_RESTORE'
due to KtFirFileSymbol#createPointer logic – the pointer can
be created only for PSI

^KT-61451
^KT-61887
^KT-62626 Fixed
^KT-62693
2023-10-20 09:27:21 +00:00
Roman Golyshev 3c68b27280 KT-62071 [AA] Do not throw error from getScopeContextForPosition when implicitScope of receiver value is null
`implicitScope` can be `null`
in case when the implicit receiver resides in a user-defined `kotlin.*`
package, but the user have not yet allowed this with compiler argument
directive.

In this case,
we don't want the IDE to crush and show exceptions - the `kotlin`
package would be highlighted by the compiler diagnostics and other
resolve problems, and that would be enough

^KT-62071 Fixed
2023-10-19 12:59:47 +00:00
Ilya Kirillov 67ac985be7 [Analysis API Standalone] fix testdata for standalone mode tests
The commit (7db2fc522e) with changing behavior of builtin symbol provider
is in a conflict with a commit (72de86a8ba) where new tests were added.

The difference should be fixed as a part of KT-62651
2023-10-18 19:50:44 +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
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
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
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
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
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 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