Commit Graph

549 Commits

Author SHA1 Message Date
Jiaxiang Chen 7ce2f64c18 AA: apply java type enhancement to declaredMemberScope.
* added getDeclaredMemberScope to JavaScopeProvider.
2023-02-24 19:57:10 +01:00
Jinseong Jeon 5455942859 AA: handle underscore as type arguments
^KTIJ-24742 Fixed
2023-02-23 13:02:34 +01:00
Pavel Mikhailovskii 7700484a16 [AA] Fix conversion of annotation values 2023-02-22 13:55:50 +00:00
Pavel Mikhailovskii d81170fbcc KT-56840 [SLC] Don't mark primitive-backed types with @NotNull 2023-02-21 17:29:16 +00:00
Ilya Kirillov 803c3b88ac [Analysis API] fix exception on symbol restore when symbol cannot be seen from the use-site module
^KT-56763 fixed
2023-02-20 11:01:32 +00:00
Ilya Kirillov c37ee83791 [Analysis API] add more debug info to "pointer already disposed" error 2023-02-17 14:19:08 +00:00
Justin Paupore fa517180b7 [AA-FIR] Add support for constant evaluation of string templates.
Support FirStringConcatenationCall in FirCompileTimeConstantEvaluator.
This allows string templates ("foo${bar}") to be evaluated as constants,
assuming the interpolated expressions are themselves constant.

In addition, fixes some handling bugs with KtConstantEvaluationMode,
where some expressions that are not valid in a `const val` declaration
were being supported for `CONSTANT_EXPRESSION_EVALUATION`, including
non-static final Java fields in FIR, and composite expressions of
non-const properties in FE1.0.
2023-02-15 16:45:22 +01:00
Dmitriy Novozhilov 8e3022452e [FIR] Unify diagnostic message in FIR dump for syntax error between PSI and LT 2023-02-14 17:08:55 +00:00
Roman Golyshev b23aabf6e0 [Analysis API] KTIJ-24610 Ignore qualifiers with fake source in KtFirImportOptimizer
Such qualifiers can appear for extensions imported from objects

^KTIJ-24610 Fixed
2023-02-14 16:08:40 +00:00
Marco Pennekamp fb43e53ca3 [LL FIR] KTIJ-24574 Fix containing declaration finder for init blocks
- KTIJ-24574 occurred because a local destructuring declaration was
  erroneously returned as the non-local containing declaration of an
  element by `getNonLocalContainingOrThisDeclaration`. This occurred in
  `init` blocks.

KTIJ-24574 fixed
2023-02-13 10:38:26 +00:00
Jinseong Jeon 88b07f5287 SLC: keep annotations on type when converting to PsiType
^KT-55815 Fixed
2023-02-09 19:53:45 +01:00
Roman Golyshev ac8d5a0ea8 [Analysis API] KTIJ-24527 Properly handle typealiased functional types
Use expanded ConeTypes to get correct parameters and return types

Also, fix the order of rendering modifiers in `KtFunctionalTypeRenderer`

^KTIJ-24527 Fixed
2023-02-09 12:51:23 +00:00
Ting-Yuan Huang 42b08d411b [FIR] Pass container when creating FunctionType
so that it can be resolved when type annotations are demanded.
2023-02-08 19:43:24 +00:00
Jaebaek Seo a09d0aa1cf Handle SHORTEN_IF_ALEADY_IMPORTED case of KtFirReferenceShortener
For the following example, when we run the reference shortener, it
drops `a.b.c` qualifier, because it matches "FOURTH".
```
package a.b.c

fun <T, E, D> foo(a: T, b: E, c: D) = a.hashCode() + b.hashCode() + c.hashCode() // FIRST
fun <E> E.foo() = hashCode() // SECOND

object Receiver {
    fun <T, E, D> foo(a: T, b: E, c: D) = a.hashCode() + b.hashCode() + c.hashCode() // THIRD
    fun foo(a: Int, b: Boolean, c: String) = a.hashCode() + b.hashCode() + c.hashCode() // FOURTH
    fun test(): Int {
        fun foo(a: Int, b: Boolean, c: Int) = a + b.hashCode() + c // FIFTH
        return <expr>a.b.c.foo(1, false, "bar")</expr>
    }
}
```

As shown in the above example, when SHORTEN_IF_ALEADY_IMPORTED option is
given from a user, the reference shortener has to check whether it can
drop the qualifier without changing the referenced symbol and if it is
possible to do that without adding a new import directive, it deletes
the qualifier.

It needs two steps:
 1. Collect all candidate symbols matching the signature e.g., function
    arguments / type arguments
 2. Determine whether the referenced symbol has the highest reference
    priority when we drops the qualifier depending on scopes

This commit uses `AllCandidatesResolver(shorteningContext.analysisSession.useSiteSession).
getAllCandidates( .. fake FIR call/property-access ..)` for step1.
For step2, we use a heuristic based on scopes of candidates. If a
candidate symbol is under the same scope with the target expression, it
has a `FirLocalScope` which has the high priority. So when we have a
candidate under a `FirLocalScope` and the actual referenced symbol is
different from the candidate, we must avoid dropping its qualifier
because the shortening will change its semantics i.e., reference.

The order of scopes depending on their scope types is:
 1. FirLocalScope
 2. FirClassUseSiteMemberScope / FirNestedClassifierScope
 3. FirExplicitSimpleImportingScope
 4. FirPackageMemberScope
 5. others

Note that for "others" the above rule can be wrong. Please update it if
you find other scopes that have a priority higher than the specified
scopes.

One of non-trivial parts is the priority among multiple
FirClassUseSiteMemberScope and FirNestedClassifierScope. They are
basically scopes for class declarations. We decide their priorities
based on the distance of class declaration from the target expression.

Note that we take a strict approach to reject all false positive. For
example, when we are not sure, we don't shorten it to avoid changing its
semantics.

TODO: One corner case is handling receivers. We have to update
```
private fun shortenIfAlreadyImported(
    firQualifiedAccess: FirQualifiedAccess,
    calledSymbol: FirCallableSymbol<*>,
    expressionInScope: KtExpression,
): Boolean
```

The current implementation cannot handle the following example:
```
package foo
class Foo {
    fun test() {
        // It references FIRST. Removing `foo` lets it reference SECOND.
        <caret>foo.myRun {
            42
        }
    }
}
inline fun <R> myRun(block: () -> R): R = block()         // FIRST
inline fun <T, R> T.myRun(block: T.() -> R): R = block()  // SECOND
```

Tests related to TODO:
 - analysis/analysis-api/testData/components/referenceShortener/referenceShortener/receiver2.kt
 - analysis/analysis-api/testData/components/referenceShortener/referenceShortener/receiver3.kt
2023-02-08 18:39:12 +00:00
Jaebaek Seo 860dee2cb1 Fix reference resolver bug for companion object whose name is the same as class
FirReferenceResolveHelper internally checks whether the referenced class
id matches the qualifed access or not. If they do not match, it reports
an error. When the companion object has the same name as the class,
resolving a qualified expression access to a member of the companion
object causes an error because of the mismatch e.g.,

```
package my.sample

class Test {
    fun a() {
        my.sample.<caret>Test.say()
    }

    companion object Test {
        fun say() {}
    }
}
```

This commit fixes the issue.

TODO: When the companion object has a name difference from class, it
does not report an error but the resolution result is wrong in FIR. See
KT-56167.

---

Commentary from rebaser: the issue mentioned in this code is
fixed in 71a368e06e, so the actual
fix is omitted, and only test data is preserved
2023-02-08 18:39:11 +00:00
Dmitrii Gridin 3e4c6b160a [AA] KtAnnotationApplicationInfo: add more information to kdoc
^KT-56046
2023-02-03 19:49:15 +00:00
Dmitrii Gridin 482bc15a70 [AA] rename from NullAnnotationUseSiteTargetFilter to NoAnnotationUseSiteTargetFilter
^KT-56046
2023-02-03 19:49:14 +00:00
Dmitrii Gridin ceb0b95d99 [AA] KtAnnotationApplication: update kdoc
^KT-56046
2023-02-03 19:49:10 +00:00
Dmitrii Gridin 817eeb3a49 [AA] KtAnnotationApplication: add more information to kdoc
^KT-56046
2023-02-03 19:49:09 +00:00
Dmitrii Gridin 379044f2c8 [AA] KtAnnotationApplication: make index nullable
^KT-56046
2023-02-03 19:49:08 +00:00
Dmitrii Gridin 3a14fba524 [AA] DebugSymbolRenderer: update naming
^KT-56046
2023-02-03 19:49:06 +00:00
Dmitrii Gridin 17681bd803 [AA] KtAnnotated: fix kdoc
^KT-56046
2023-02-03 19:49:06 +00:00
Dmitrii Gridin cfdc9f342a [AA] KtSymbolInfoProvider: pass missing annotationUseSiteTarget to getDeprecation
^KT-56046
2023-02-03 19:49:02 +00:00
Dmitrii Gridin 93232a23df [AA] introduce AnnotationUseSiteTargetFilter to simplify API
^KT-56046
2023-02-03 19:49:01 +00:00
Dmitrii Gridin 6e25b45f7d [AA] introduce KtAnnotationApplication
^KT-56046
2023-02-03 19:49:01 +00:00
Dmitrii Gridin 3a7602a38f [AA] KtAnnotationsList: introduce 'annotationOverviews'
it provides a solution for several problems with redundant resolve.
It is a more powerful tool than 'annotationClassIds'

^KT-56046
2023-02-03 19:48:57 +00:00
Dmitrii Gridin 72d8fa216a [AA] DebugSymbolRenderer: move annotations and type arguments renderer befor type to avoid resolve race
^KT-56046
2023-02-03 19:48:56 +00:00
Dmitrii Gridin d13ad454da [AA FIR] fix nested type annotations lazy resolve
^KT-56046
2023-02-03 19:48:56 +00:00
Dmitrii Gridin 3b99a5bf34 [AA] DebugSymbolRenderer: improve context receivers render
^KT-56046
2023-02-03 19:48:55 +00:00
Dmitrii Gridin 1e2d517c21 [AA] DebugSymbolRenderer: improve type render
to process all nested annotations and types

^KT-56046
2023-02-03 19:48:55 +00:00
Dmitrii Gridin 4b955944ff [AA] KtAnnotationApplication: add 'index' parameter
it is required for lazy annotations resolve

^KT-56046
2023-02-03 19:48:47 +00:00
Dmitrii Gridin af569afb3e [AA] KtAnnotationUseSiteTargetRenderer: simplify condition
^KT-56046
2023-02-03 19:48:42 +00:00
Marco Pennekamp 5790a32436 [AA] Remove duplicate withValidityAssertion calls 2023-02-03 10:24:05 +00:00
Ilya Kirillov 8b286577c7 [Analysis API] do not throw exception when KtCall is improperly resolved
Log the exception instead. This way the analysis of the file will not be stuck after finding an improperly resolved call
2023-02-03 07:06:07 +00:00
Dmitriy Novozhilov 89c42e20c9 [FIR] Consistently use _function_ instead of _functional_ in names of classes and functions 2023-02-02 08:24:52 +00:00
Dmitriy Novozhilov 67aa80562d [FE] Completely replace FunctionClassKind with FunctionalTypeKind
FunctionalTypeKind can be used in FE 1.0 too, so there is no need to
  keep both classes. Also, removal of FunctionClassKind simplifies work
  with FunctionalTypeKind in common code, like Analysis Api
2023-02-02 08:24:50 +00:00
Anna Kozlova b415aa7446 [FIR] take ready implicit unit type instead of return type calculation
and assert that symbol is not a substitution/intersection override
in the `compute` method otherwise.

Because `fakeOverrideSubstitution` should be calculated for all real
implicit types, no call to this method should actually happen.

Otherwise, it can be problematic to create a session
which would contain the full designation path:
`provider.getFirCallableContainerFile(symbol)`
returns `firFile` of a super class which might be from module `a`,
when declaration and its outer classes are from module `b`.

^KTIJ-24105
2023-01-31 11:21:17 +00:00
aleksandrina-streltsova f3cbc1b2d4 [Analysis API] Add API for obtaining scope with synthetic properties
^KTIJ-22359 Fixed
2023-01-31 11:02:18 +00:00
Kirill Rakhman 5e56845ce0 Analysis API: Add tests for KT-54648 2023-01-31 08:39:43 +00:00
Kirill Rakhman 1eb18f13bd FIR: Fix test data after making LHS of assignment an expression
KT-54648
2023-01-31 08:39:43 +00:00
Roman Golyshev 5ec626b29d [Analysis API] KTIJ-24453 Handle TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM error in KtFe10CallResolver.kt
It makes call with such type of errors completely unresolvable in
Analysis API

^KTIJ-24453 Fixed
2023-01-30 12:45:19 +00:00
Roman Golyshev 71a368e06e [Analysis API] KTIJ-24107 Fix resolution of qualified invoke calls on objects
^KTIJ-24107 Fixed
^KTIJ-24344 Fixed
2023-01-27 16:49:30 +00:00
Anna Kozlova e5b96561e0 [FIR] skip implicit call to enum constructor if super type call exists
otherwise, reference to the super type would be resolved even when it's not
e.g. for interface constructor
^ KTIJ-24437
2023-01-27 08:20:07 +00:00
Marco Pennekamp 2922f85a98 [AA] KTIJ-23563 Add reference resolve tests for working cases
- Type arguments in invalid calls/property accesses are resolved
  correctly in many cases, for which this commit adds test cases.
2023-01-25 16:40:46 +00:00
Anna Kozlova b026678a34 [LL] retrieve fir from generated property of desugaring ++ operator
^ KTIJ-24385
Temp property to store receiver is generated for `a.b++` expression.
If this property's psi corresponds to receiver expr, then FirProperty
would be found by mapper if receiver is requested.
It works unexpectedly, because FirProperty is normally not expected by expression.
This change set fake sources for generated FirProperty, so it won't be found
by source psi
2023-01-25 11:03:29 +00:00
Yan Zhulanow 9873fe84f2 [FE] Fix exception from the 'UnusedChecker' on a destructuring
^KT-55973 Fixed
2023-01-25 08:05:58 +00:00
Anna Kozlova fd52cc4224 [AA] support qualified type in incomplete code
^ KTIJ-24373
when resolving selector expr of a dot qualified expression,
parent qualified expression is resolved
see `KtFirCallResolver.getContainingDotQualifiedExpressionForSelectorExpression`,
Fir is filled with the data. Then,
during final mapping from Fir -> psi, one need to perform the opposite:
take `selectionExpression` to get the initial KtCallExpression
2023-01-24 20:41:19 +00:00
Justin Paupore 16f14a21e2 [AA] Render reflection functional types as class types.
Render KFunctionN and KSuspendFunctionN by their class names, rather
than using arrow syntax. These types have additional functionality
beyond purely being able to invoke them (e.g. getting the name of the
referred function), so using arrow syntax throws away that functionality
and may cause breakages in the resulting code.
2023-01-24 14:39:55 +01:00
Justin Paupore cd61f545a8 [AA] Clean up typos in KtTypeRenderer. 2023-01-24 14:39:55 +01:00
Justin Paupore eccbc66581 [AA] Add implementation for annotationApplicableTargets.
Adds implementation and tests for the new
KtClassOrObjectSymbol.annotationApplicableTargets property on
KtSymbolInfoProvider. This implementation delegates to the canonical
implementation in AnnotationChecker for FE1.0, and to the implementation
in FirAnnotationHelpers for FIR.

This change also includes direct tests for annotationApplicableTargets,
and a fix for FirClassLikeSymbol.getAllowedAnnotationTargets in
FirAnnotationHelpers.
2023-01-24 14:39:55 +01:00