Commit Graph

1514 Commits

Author SHA1 Message Date
Marco Pennekamp 9d2298b326 [AA] Resolve isSubClassOf from the context of a use-site session again
`isSubClassOf` was changed in an earlier commit to use the session of
`subClass` instead, but that approach comes with multiple problems:

- We need to resolve classes from the use-site to take actualization of
  `expect` types into account.
- If `superClass` is a builtin and we resolve supertypes from
  `subClass`'s session, we may get multiple instances of symbols for the
  same builtin from different sessions (i.e. one from a stdlib session
  via the use-site session and another from the fallback builtins
  provider for binary libraries if `subClass` is from a binary library).

^KT-66013
2024-03-18 21:14:36 +00:00
Marco Pennekamp 2e00879fe1 [AA] Add sealed inheritors tests for inheritors with the wrong package
- Inheriting from a sealed class in the wrong package is illegal, so a
  library test makes no sense here, as the test infrastructure wouldn't
  be able to compile the library.

^KT-66013
2024-03-18 21:14:36 +00:00
Marco Pennekamp 54f2655b4d [AA] Add sealed inheritors tests for type aliased classes/interfaces
- The test data is partially incorrect, as type alias support needs to
  be added to `KotlinStandaloneDirectInheritorsProvider`.

^KT-66013
2024-03-18 21:14:36 +00:00
Marco Pennekamp 5c8c3020c6 [AA] Add tests for getSealedInheritors
- Previously, the sealed inheritors provider was only tested indirectly
  through diagnostics tests on `when` expressions.

^KT-66013
2024-03-18 21:14:36 +00:00
Marco Pennekamp b2639a469b [AA Standalone] Implement KotlinDirectInheritorsProvider
- We are relying on static indexing to find candidates for sealed
  inheritors, hence the extension to the index.
- The direct usage of `KotlinStaticDeclarationProviderFactory` in
  `KotlinStandaloneDirectInheritorsProvider` is not pretty, but a proper
  design requires making the static index available as a service and
  moving "static" services to the Standalone API (from AA providers).

^KT-66013
2024-03-18 21:14:35 +00:00
Egor Kulikov 36b89f5e84 [FIR] Fix resolve for java synthetic properties in KDoc
^KT-62880 fixed
2024-03-18 17:35:32 +00:00
Sebastian Sellmair 6b98602afc [Analysis Api] Expose klibSourceFile via KtKlibSourceFileProviderMixIn
This `klibSourceFile` information is deserialized from klibs
to retain the information of the original SourceFile location
of a declaration.

^KT-66271 Fixed
2024-03-18 10:13:57 +00:00
Jaebaek Seo 90ccdb79ed K2: Set special function kind to function param with receiver
`StubBasedFirTypeDeserializer` handles function parameter with a
receiver with a special exception, which sets it as
`ExtensionFunctionType`, but skips setting special function kinds for it
even when the function parameter type is a special function kind. This
drops `Composable` annotation from a lambda expression if the function
parameter taking the lambda expression as an argument has a receiver,
which causes a severe CodeGen error for Compose app on K2 Android
Studio.

^KT-66526 Fixed
2024-03-14 20:08:24 +00:00
Dmitrii Gridin 5689dedea0 [Analysis API FIR] KtFirPsiTypeProvider: drop redundant TODO
Regular type annotations work as expected

^KT-62351 Obsolete
2024-03-14 18:05:15 +00:00
Dmitrii Gridin ba421aa320 [Analysis API FIR] KtFirPsiTypeProvider: support type parameter position in asKtType
^KT-66530
2024-03-14 18:05:15 +00:00
Dmitrii Gridin 675bf36049 [FIR] JavaTypeParameterStack: allow nullable return from get
It is not always possible to have the correct mapping,
at least on the Analysis API side

^KT-66530 Fixed
2024-03-14 18:05:15 +00:00
Yan Zhulanow 0fec50135f [kotlin] Provide CFG facade for the extract function refactoring
This is the first implementation of a control flow graph facade for the
extract function IDE refactoring. The exact contents of
'KtDataFlowExitPointSnapshot' will be refined later.

^KT-65762 Fixed
2024-03-14 10:53:11 +00:00
Yan Zhulanow 1f39bc9a18 [Analysis API] Add tests for foreign values 2024-03-14 10:20:29 +00:00
Yan Zhulanow 2dd16e1179 [Analysis API] Fix 'getContainingDeclaration()' for foreign values
Foreign values (such as '_DebugLabel' properties contributed by the
debugger) don't have a parent (or a valid source element in general).

^KTIJ-27382 Fixed
2024-03-14 10:20:29 +00:00
Yan Zhulanow 88a85b8936 [Analysis API] Add reference tests for containing declaration provider 2024-03-14 10:20:29 +00:00
Yan Zhulanow e171e21165 [Analysis API] Minor, remove duplicating check 2024-03-14 10:20:29 +00:00
Yan Zhulanow 0147d725fb [Analysis API] Provide type mapping for callable references
Strictly speaking, callable references are not calls. However, type
arguments are still inferred for references, and 'KtCall' is the only
place in Analysis API that exposes call-substituted types.

^KT-66485 Fixed
2024-03-14 06:10:31 +00:00
Kirill Rakhman 1876c8a9ee [AA] Fix getKtExpressionType for augmented array assignment
This previously worked on accident because the get call in an
augmented array assignment wouldn't have a resolved argument list, and
so `argumentsToSubstitutedValueParameters` would return null.
Now, we additionally verify that we're in a `set` call.

#KT-66124
2024-03-13 17:05:48 +00:00
Kirill Rakhman 8443daf78d [FIR] Remove FirNamedArgumentExpressions during completion
They are mostly necessary for argument mapping during resolution.
To support a couple checkers, we transform named args for varargs
into "fake" spread expressions.

Other than that, named arguments aren't needed for anything and often
lead to bugs where we forget to unwrap them for something, so it's
better to get rid of them.

#KT-66124
2024-03-13 17:05:48 +00:00
Kirill Rakhman 03fc0fd381 [FIR] Remove FirLambdaArgumentExpression
It's not really necessary if the information about if the lambda was a
trailing lambda can be directly saved in FirAnonymousFunctionExpression.

Removing the FIR node uncovered a couple of bugs
(UNINITIALIZED_ENUM_ENTRY, ERROR_IN_CONTRACT_DESCRIPTION) that were
caused by assuming that a lambda is always a trailing lambda.

#KT-66124
2024-03-13 17:05:48 +00:00
Roman Golyshev de75297875 KT-66498 [AA] Add more tests for the isSubClassOf/isDirectSubClassOf
Also, reproduce the difference between the K1 and K2 implementation
of `isSubClassOf` for the same class
2024-03-13 16:31:41 +00:00
Nikolay Lunyak d3dfbec01a [FIR] Report warnings for inconsistent visibilities of accessors
K1 didn't report diagnostics for accessors
of intersection overrides, so this change
prevents a BC.

^KT-66046 Fixed
2024-03-12 16:35:05 +00:00
Dmitriy Novozhilov d352cc9d96 [Frontend] Make DiagnosticSuppressor a project-level extension
Originally it was an application-level component, which caused non-trivial
  logic and cognitive load to carefully handle those extensions to avoid
  memory leaks.

6740a596 introduced a way to easily register `DiagnosticSuppressor` to
  project, and this commit continues this work, making it a proper
  project-level extension

A lot of changes caused by the fact, that this extension is needed to be
  obtained from `BindingContext` (see `BindingContextSuppressCache` and
  its usages), so almost all changes are introducing `Project` to
  `BindingContext`

^KT-66449 Fixed
2024-03-12 06:43:58 +00:00
Vadim.Mishenev df1d44b15f KT-64051 [AA] Fix resolve of KDoc references to a typealias by full name 2024-03-11 21:38:09 +00:00
Roman Golyshev 83a80a45a9 KT-66411 [AA] Add more tests for resolving compound set operators 2024-03-10 15:35:47 +00:00
Anna Kozlova 943d829fa7 [AA] treat named arguments as write access
^KTIJ-16835 fixed
2024-03-08 22:12:25 +00:00
Ivan Kochurkin 2d4f4b9bb5 [FIR] Disallow operators not on functions
Introduce `NOT_FUNCTION_AS_OPERATOR` and use it instead of `PROPERTY_AS_OPERATOR`

^KT-65881 Fixed

Merge-request: KT-MR-14547
2024-03-08 10:07:23 +00:00
Jinseong Jeon 9c16c52564 AA: pass wildcard suppression hints on declarations
^KT-61734
2024-03-07 10:17:00 +00:00
Jinseong Jeon d089db5a45 AA: honor wildcard suppression on type during type conversion
^KT-61734
2024-03-07 10:16:59 +00:00
Jinseong Jeon d4d2bae630 AA: add tests about wildcard suppress
^KT-61734
2024-03-07 10:16:58 +00:00
Dmitrii Gridin 805b7bc8f4 [Analysis API] add diagnostic tests on deprecated declarations
^KT-60996
2024-03-06 16:13:09 +00:00
Dmitrii Gridin 9cc2c22116 [Analysis API] drop obsolete tests
They were renamed during 2ce324f1fc,
but old wasn't dropped
2024-03-06 16:09:43 +00:00
Dmitrii Gridin 1ba81fca57 [Analysis API] add tests on incomplete function type parameter symbol
^KT-65858 Obsolete
2024-03-06 16:09:43 +00:00
Dmitriy Novozhilov 624bea3ecf [FIR] Never create ConeSubstitutorByMap with empty substitution
Relates to KT-66323
2024-03-06 06:40:28 +00:00
Alexander Udalov 3bb2ea10b6 K2: add inline JVM target version checker
#KT-60777 Fixed
2024-03-04 22:25:36 +00:00
Nikita Klimenko c49edfef04 [FIR] Extension point for function calls
This extension point allows changing the return type of call
 from a declared type to its subtype.
With an idea that such a plugin needs the ability to
control available (extension) properties for this type.
A set of properties should be decided based on the resolved function,
provided arguments, types, and resolved lambdas.
It is not a goal to enable plugins to affect resolution in any way.
Types are not intended to have any structured capabilities

In other words.
The goal was to come up with a way to enable a limited form
of an "extensible records" mechanism through plugins.
- It should give enough value for a practical use.
(more info in the ticket).
- It should have minimal effect on the compilation process
This appears to be an extension point that solves this problem.

^KT-65859 Fixed
2024-03-04 06:33:24 +00:00
Jaebaek Seo a17ad6bc55 Fix K2 CodeGen annotation parameter resolution failure
When we have parameters of annotation like
```
// FILE: Anno.kt
package p3

@Target(AnnotationTarget.FUNCTION)
annotation class Anno(vararg val x: String)

// FILE: main.kt
import p3.Anno

@Anno("A", "B")
fun foo(): Int = 10
```
the K2 CodeGen causes an exception reporting the unresolved type
reference. A lazy resolution call fixes the issue.

In addition, FIR for the value parameter to IR conversion fails because
`Fir2IrLazyProperty` for the value parameter tries to resolve the
initializer before creating the `IrParameterSymbol`. When it checks the
`localStorage`, it reports an error for the missing `IrParameterSymbol`.
This commit adds `IrParameterSymbol` before resolving the initializer.

^KT-65099 Fixed
2024-02-29 06:44:05 +00:00
Marco Pennekamp 708ed81eb2 [Test] Avoid importing unused @Nested annotations in generated tests
- Unused `Nested` imports frequently cause unused import warnings in the
  IDE, which are especially annoying in after-commit warning/error
  analysis.
2024-02-27 20:30:06 +00:00
Anna Kozlova e650ba9855 [AA] return expect declaration for "implicit" actual
If actual declaration is broken (missing explicit `actual` keyword),
expect declaration still makes sense.
This way, we allow refactorings on broken code

^KT-65191 fixed
2024-02-27 18:49:02 +00:00
Artem Kobzar 3429cbd321 [K/JS] Support companion objects in external and exported declarations 2024-02-27 16:30:13 +00:00
Roman Efremov 23ae617ea0 Fix inaccurate report of DEPRECATED_ACCESS_TO_ENTRY_PROPERTY_FROM_ENUM
Add separate diagnostic for the case when it is reported on qualifiers.

^KT-64488
2024-02-27 11:22:35 +00:00
Roman Efremov 02b5fed389 Fix inaccurate report of DEPRECATED_ACCESS_TO_ENTRY_PROPERTY_FROM_ENUM
It can be reported not only from within the enum, but also from
top-level functions. Add separate diagnostic for such cases.

^KT-64488
2024-02-27 11:22:35 +00:00
Marco Pennekamp b5eccd63b1 [AA] Fix compilation facility "multi binary module" test module structure
- The module structure for these tests was set up backwards: We should
  keep the test module kind of the main module flexible (as it is
  configured by test configurators), but keep the module kinds of the
  binary libraries fixed.

^KT-65960
^KT-64994
2024-02-26 21:57:23 +00:00
Marco Pennekamp 78ef58bef4 [AA] Tests: Remove decompiled files from LibraryBinary and add LibraryBinaryDecompiled
- `LibraryBinary` should not contain any decompiled files, as we want
  FIR symbols in tests to be provided from indexed stubs or class files,
  but definitely not from decompiled PSI. This brings `LibraryBinary`
  much closer to the behavior of binary libraries in the IDE.
- Some tests may still require access to a decompiled file, for example
  when trying to test `getOrBuildFir` for some `KtElement` coming from a
  library. This commit introduces `LibraryBinaryDecompiled`, which
  does contain decompiled files.
- We don't really need `LibraryBinary` as a main test module kind
  anymore, since tests generally want to access some main `KtFile`.
  Hence, test configurators for `LibraryBinary` have been turned into
  configurators for `LibraryBinaryDecompiled`.
- An alternative would be decompiling files on demand, but this is not
  currently feasible because the Standalone API doesn't reconcile stubs
  with decompiled PSI, like the IDE does automatically. (For the same
  declaration, the stub and the PSI will have a different identity.) As
  long as there is no support for this, we'll have to rely on a separate
  test module kind.

^KT-65960
2024-02-26 21:57:23 +00:00
Marco Pennekamp 7baaa38b8a [AA] Add KtTestModule.moduleKind
- `TestModule.explicitTestModuleKind` requires a directive to be present
  to get the `TestModuleKind`. But we still want to find out the test
  module kind for test modules without a directive. Hence, we have to
  add this property to `KtTestModule` during its construction.

^KT-65960
2024-02-26 21:57:23 +00:00
Jaebaek Seo 2f64a878e4 K2: Support dependency symbol providers for binary libraries
When a symbol X from a binary library A uses another symbol Y from
another binary library B, `LLFirDependenciesSymbolProvider` cannot
resolve Y for X. This is because the existing
LLFirAbstractSessionFactory passes symbol providers for only builtin
libraries to `LLFirDependenciesSymbolProvider` even when the session has
dependencies. As a result, when `LLFirDependenciesSymbolProvider`
searches a symbol, it can find only symbols from the builtin libraries,
but it cannot find a symbol from libraries other than builtin libraries.
This happens only for the binary libraries.

^KT-65240 Fixed
2024-02-26 18:02:08 +00:00
Jaebaek Seo 171ea3571c K2: Use deserialized type annotation for lambda type resolution.
This commit adds code to check whether a deserialized cone type is a
special function type kind or not when resolving the type of a lambda
expression (anonymous function). If it is a special function kind, it
sets the type of lambda based on the special function kind.

^KT-64994 Fixed
2024-02-25 10:10:43 +00:00
Jaebaek Seo 512efb9649 K2: Support binary library dependencies between test modules
The test infrastructure for analysis supports binary module tests, but
the binary build does not use another binary module as a dependency when
it passes the class path. As a result, each binary module build does not
work when they have dependency on each other.

This commit fixes the issue by
1. Topological sort in the order of dependency graph for test modules.
2. Pass module paths as extra class paths when they have dependency on
   each other.

^KT-64994
2024-02-25 10:10:43 +00:00
Roman Golyshev c1ea878e52 KT-64808 [stubs] Add extra tests for synthethic declarations from data and value classes
It's not related to the stubs format changes, but there were no tests
for that in symbols resolve tests
2024-02-23 10:51:28 +00:00
Yahor Berdnikau 6b19b8b9d0 [Repo] Don't use kotlinOptions in repo build scripts
^KT-63419 In Progress
2024-02-22 14:48:10 +00:00