Commit Graph

1022 Commits

Author SHA1 Message Date
Marco Pennekamp 32337c8255 [AA] Render types in sealed inheritors tests as fully expanded types
- This avoids discrepancies between Standalone and IDE mode for sealed
  inheritor tests with type aliases from libraries, because in
  Standalone mode, libraries are deserialized with fully expanded types,
  while in IDE mode, libraries are deserialized from stubs, where type
  aliases are currently not expanded.

^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 ed62211e06 [AA] Add packages to sealed inheritors tests
^KT-66013
2024-03-18 21:14:36 +00:00
Marco Pennekamp a9d7b0c595 [AA Standalone] Consider type aliases in direct inheritors search
A type alias may still be inherited from. For example:

```
sealed class MyClass

typealias T = MyClass

class Inheritor : T() // `Inheritor` is a direct inheritor of `MyClass`.
```

The index is a simplified version of the IDE's
`KotlinTypeAliasByExpansionShortNameIndex`, but it should be sufficient
for virtually all cases.

^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 1374bc8e2d [LL] Implement a common LLSealedInheritorsProvider
- The new `LLSealedInheritorsProvider` is based on the previous
  sealed inheritors provider implementation in the IDE. It uses the
  new direct inheritors provider and the module dependents provider to
  implement the same functionality that was previously confined to the
  IDE. With this design we avoid duplication of complex logic such as
  the KMP handling in `searchInheritors`.
- The implementation is designed to work in the production Standalone
  mode and the aforementioned services have already been implemented for
  Standalone in prior commits. Now we can get rid of the problematic
  `SealedClassInheritorsProviderForTests` and tests should more closely
  match production behavior.
- In IDE mode tests, `LLSealedInheritorsProvider` is used with
  Standalone Analysis API provider implementations. This is in line with
  the rest of the test infrastructure, where Standalone AA providers are
  generally used, as IDE providers aren't available.
- `KotlinSealedInheritorsProvider` is made obsolete by the common sealed
  inheritors provider.

^KT-66013 fixed
^KT-64505 fixed
2024-03-18 21:14:36 +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 b3827947d9 [Analysis API] Update KDoc for KtPsiTypeProvider#asKtType 2024-03-14 18:05:15 +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 88a85b8936 [Analysis API] Add reference tests for containing declaration provider 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 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 1884a655c5 KT-66498 [AA] Provide KDoc for isSubClassOf and isDirectSubClassOf 2024-03-13 16:31:41 +00:00
Roman Golyshev c6e442c18b KT-66498 [AA] Do not consider a class to be a subclass of itself in K1 impl for isSubClassOf
^KT-66498 Fixed
2024-03-13 16:31:41 +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
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
Mikhail Glukhikh 78b6432ced K2: don't make T = Type! substitutions for constructors, including SAM
Without this commit we get some ABI changes and it looks bad.

Related to KT-65596
2024-03-11 13:38:05 +00:00
Denis.Zharkov 81414d758d K2: repeat K1 representation for flexible type parameters
This commit changes the behavior of KT-59138 effectively declining it in 2.0.
However, we plan to implement KT-59138 behavior under a feature
flag in 2.0 (see KT-66447), and switch this feature on version 2.x.

Also, this commit implements the LC resolution about postponing
KT-57014 change. We don't have KT-57014 described behavior in 2.0 anymore.
However, we plan to implement a deprecation warning here, see KT-65578.

After this commit, 6 diagnostic tests become incorrectly broken:
- 5 tests from PurelyImplementedCollection group
- a test platformTypes/nullableTypeArgument.kt

This commit also breaks currently fixed-in-k2 KT-50134
(it is fixed again in the following commits),
as well as KT-58933 (it will remain not fixed till we enable KT-59138
behavior again).

#KT-65596 In Progress
#KT-57014 In Progress
#KT-58933 Submitted
2024-03-11 13:38:05 +00:00
Roman Golyshev b765cf3f99 KT-66411 [AA] Add fake source kind for single expression block around array assignments
A wrapper block was introduced as a part of fixing KT-59748, but was
assigned a real source, which had `getOrBuildFir` confused because
of the incorrectly built `KtToFirMapping`

It is relevant for:
- `if`, `when` expressions with an assignment as a single expression
- Kotlin code fragments,
when the assignment is being analysed as a single expression
in the fragment

^KT-66411 Fixed
2024-03-10 15:35:47 +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
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
Jinseong Jeon b47a33cf9d Back to getOrDefault test
The main purpose was to test getOrDefault w/ non/null value does not
bother the resolution. To be aligned with test file
mapGetOrDefault_nullable.kt, this one should test getOrDefault too.
All we needed was // WITH_STDLIB
2024-03-06 19:26:52 +00:00
Dmitrii Gridin 28c80a1581 [LL FIR] StubBasedFirMemberDeserializer: add missed deprecation provider
^KT-60996 Fixed
2024-03-06 16:13:09 +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 1ba81fca57 [Analysis API] add tests on incomplete function type parameter symbol
^KT-65858 Obsolete
2024-03-06 16:09:43 +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
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
Marco Pennekamp 7a5a1833e7 [AA] Implement disposable KtResolveExtensions
- This commit adds the `Disposable` interface to `KtResolveExtension`.
  Resolve extensions are disposed after their associated session has
  been invalidated, or reclaimed by the GC.
- Example use case: Opening a message bus connection with the lifetime
  of the resolve extension.

^KT-61222 fixed
2024-02-27 16:45:52 +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
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
Yan Zhulanow fa511fdc52 [Analysis API] Pass PCE exceptions from KtCompilerFacility 2024-02-26 10:56:24 +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
Ilya Chernikov 9037975758 K2 Scripting: Skip base class params from resolution scope
The base class in scripting considered obsolete and therefore supported
via some ad-hoc mechanisms. In particular parameters to the base class
c-tor are passed via script provided properties. But in combination
with the resolution logic, this leads to issues described in KT-60452
This commits filters out such parameters from script resolution
scope and avoids this problem for now.
Bot it should be noted that proper diagnostics for properties shadowing
should still be implemented - see #KT-65809
#KT-60452 fixed
2024-02-23 22:03:44 +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
Nikita Bobko 4120d6a8aa [FIR] Search expect for actual only in dependsOn dependencies
Before this commit, the expect-actual resolver could find expects in
regular dependencies

Note: The appeared `VIRTUAL_MEMBER_HIDDEN` in
compiler/fir/analysis-tests/testData/resolveWithStdlib/multiModule/FakeOverrides.kt
isn't caused by my change. It's caused by fixing the testData dependency
syntax notation.

The testData improperly used regular dependency syntax notation, while
it should have been using dependsOn

Before:
    Regular dependency syntax notation

    // MODULE: androidMain(commonMain)

After:
    dependsOn dependency syntax notation

    // MODULE: androidMain()()(commonMain)
2024-02-22 16:06:35 +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
Kirill Rakhman f231338cd6 [FIR] Render list of symbols with linebreaks as separators
#KT-61823 Fixed
2024-02-21 12:25:22 +00:00