Commit Graph

4186 Commits

Author SHA1 Message Date
Yan Zhulanow 0944e8fc36 [Analysis API] Keep the collected 'FirTowerDataContext' mutable
'ContextCollector' is used for computing context of 'FirCodeFragment's.
Code fragments themselves might contain additional smart cast operations
that modify the context receiver stack.

^KT-63056 Fixed
2023-12-12 17:31:52 +00:00
Dmitrii Gridin b458d69689 [Analysis API FIR] KtFirSymbolDeclarationOverridesProvider: unwrap fake overrides
We should unwrap substitution overrides as they sometimes cannot be
resolved on demand. We already have this in KDoc contract.
```kotlin
class MyClass {
    val prop = object : LazySchemeProcessor<Int, Int>() {
        override fun is<caret>SchemeFile(name: CharSequence) = name != "str"
    }
}

abstract class LazySchemeProcessor<SCHEME : Number, MUTABLE_SCHEME : SCHEME> {
    open fun isSchemeFile(name: CharSequence) = true
}
```
In this case, we will try to resolve fake override in the context of the
anonymous object, and it will fail because we cannot lazily resolve
local declarations as they are a part of the containing declarations
(KT-64243 for more details)

^KT-64108 Fixed
2023-12-12 16:13:10 +00:00
Dmitrii Gridin e033fe5ba1 [Analysis API FIR] more tests for KtSymbolDeclarationOverridesProvider
^KT-64108
2023-12-12 16:13:10 +00:00
strangepleasures 9670de74f1 [AA] KT-61776 Use an implementation of library scope that is immune to Jar cache invalidations
Merge-request: KT-MR-13356
Merged-by: Pavel Mikhailovskii <Pavel.Mikhailovskii@jetbrains.com>
2023-12-12 14:05:53 +00:00
Ivan Kylchik 79c300209e [K2] Avoid type check for Kotlin's property in ConstUtils
When we check Java field for constant initializer, we could
be asked to get and check the type of Kotlin's property that
is used in this Java field. But there is no guarantee that the type
resolve phase was finished and this type is available. So we just
check for `const` modifier and skip type check.

#KT-63752 Fixed
#KT-62558 Obsolete
#KT-61786 Declined
2023-12-12 13:54:32 +00:00
Mikhail Glukhikh 2680c8effd K2: allow/disallow coercion-to-unit for callable references more precisely
Before this commit, K2 always applied coercion-to-unit for
callable references if expected type was Unit, and actual non-Unit.
However, this may not work in case when actual return type is
a type parameter and it must be inferred into Unit.
In this commit we started to disallow coercion-to-unit
for references with synthetic outer call (~ top-level in K1)
AND a type parameter as a return type (both should be true to disallow).
This provides better K1 consistency,
while still keeping some broken K1 cases working in K2.

See also added comment in CallableReferenceResolution.kt.

#KT-62565 Fixed
2023-12-12 13:52:29 +00:00
Marco Pennekamp fa3da87401 [LL] Fix rest library symbol providers computing the wrong package sets
- See KT-63718 for a detailed description of the issue. This fix is a
  workaround (see KT-64236).
- It's worth mentioning that it's too expensive to compute package sets
  for "all libraries except one". Package sets are just an optimization.

^KT-63718 fixed
2023-12-12 12:00:41 +00:00
Dmitrii Gridin fab51ff83c [Analysis API FIR] KtSymbolByFirBuilder: simplify call-site substitution override unwrap logic
Not we have separate SubstitutionOverride for declaration and call site,
so this logic can be simplified a lot
2023-12-12 10:46:24 +00:00
Ilya Chernikov db804b7f93 K2 Scripting: fix CFG processing related testdata in LL 2023-12-12 09:58:19 +00:00
Ilya Chernikov ff4f30ddc1 FIR: replace receiver in anon initializer with containing decl
This way the abstraction represents the intended use better and
doesn't stay on the way of using FirAnonymousInitializer in scripts
2023-12-12 09:58:19 +00:00
Ilya Chernikov 12da3d2b9f K2 Scripting: add proper CFG processing for scripts
#KT-59683 fixed
#KT-63328 fixed
2023-12-12 09:58:19 +00:00
Ilya Chernikov a69eaa0ea3 K2 Scripting: fix testdata changed after script statements wrapping 2023-12-12 09:58:19 +00:00
Ilya Chernikov eeb723eb01 K2 Scripting: wrap script statements into blocks
(reuse anonymous initializers as block wrappers) so the top-level script
elements are all declarations now. Rename the property accordingly (
together with the previous commit).
It makes script more similar to the class and thus simplify e.g.
control flow analysis and resolve code.
2023-12-12 09:58:19 +00:00
Ilya Chernikov c9aee5bf09 minor: rename FirScript.statements do declarations...
to simplify the following commit that actually convert the types
and wrap statements into blocks.
2023-12-12 09:58:19 +00:00
Kirill Rakhman 8a863e00ba [FIR] Add proper constraint if Unit upper bound leads to Unit lambda return type
#KT-63524 Fixed
2023-12-12 08:36:49 +00:00
Alexey Belkov f53f92cdd6 K2: Add KtDiagnosticRenderers.CLASS_ID to render ClassId FQNs with dots
KT-MR-13391
2023-12-08 17:26:59 +00:00
Alexey Belkov 1766d0e86a K2: Use ClassId instead of FqName in FIR diagnostics
IJ-CR-118828
KT-MR-13391
2023-12-08 17:26:59 +00:00
Dmitrii Gridin 061734d84b [FIR] do not transform type annotations from function parameter during implicit type phase
We shouldn't treat them as local and transform during the implicit type
phase as they are visible from outside the function

^KT-64164 Fixed
2023-12-08 17:17:36 +00:00
Dmitrii Gridin 3d43dff8b5 [LL/FIR] add tests on function parameter as implicit return type
^KT-64164
2023-12-08 17:17:36 +00:00
Dmitriy Novozhilov c34511af37 [Test] Reproduce KT-63738 2023-12-08 15:19:55 +00:00
Brian Norman 0881910a1b [FIR] Rewind DFA after call arguments for correct receiver smartcasting
^KT-63709 Fixed
2023-12-08 14:32:22 +00:00
Dmitriy Novozhilov 7d685522ce [IR] Fix calculation of receiver type for properies in expect/actual context
^KT-62926 Fixed
2023-12-08 13:28:27 +00:00
Evgeniy.Zhelenskiy 9cef8a2133 [FIR, Tests] Add box tests to verify that disappeared DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE leads to executable code
#KT-59903


Merge-request: KT-MR-13423
Merged-by: Evgeniy Zhelenskiy <Evgeniy.Zhelenskiy@jetbrains.com>
2023-12-08 13:18:59 +00:00
Dmitriy Novozhilov 58678c09e8 [FIR2IR] Include generated IR fields into Fir2IrCommonMemberStorage
In case of HMPP structure with common JVM module (e.g. shared between
  JVM and Android) one can reference the same field from java code,
  so it should be shared between fir2ir sessions

^KT-63574 Fixed
2023-12-08 11:16:03 +00:00
Roman Golyshev 78f492394c KT-64186 [LL] Correctly handle anonymous objects' headers in ContextCollector
This bug spilled into reference shortener, and then to
"redundant qualifier inspection" and code completion from there;
it caused KTIJ-26024 to reproduce again (but only for anonymous objects)

^KT-64186 Fixed
2023-12-08 09:14:43 +00:00
Vladimir Dolzhenko a3c1f4ea12 Fix rendering of platform type for value parameters
#KT-63979 Fixed
2023-12-08 06:45:22 +00:00
Dmitrii Gridin 97956b4374 [LL FIR] resolve propagated type annotations correctly
This commit is Low Level FIR part of changes around propagated
annotations (aka foreign annotations).
It includes such changes as:
* implicit type phase postpones foreign annotations resolution
* annotation arguments are requests resolution for postponed
annotations from implicit type phase as a pre-resolve step
* body resolve phase just calls lazy resolution for foreign annotations
on demand
* isResolved check for type annotations to be sure that all annotations
are resolved after annotation arguments phase

^KT-63042 Fixed
^KT-63681 Fixed
2023-12-07 12:26:40 +00:00
Dmitrii Gridin daaf30e056 [LL FIR] introduce LLImplicitBodyResolveComputationSession
This class will be used in the next commit to have a custom logic
in Low Level FIR

^KT-63042
2023-12-07 12:26:40 +00:00
Dmitrii Gridin 9888cbbfcd [FIR] do not transform propagated annotations from place other than declaration side
We shouldn't transform annotations not from declaration side due to
a possible different context and to avoid unexpected transformation of
unrelated declarations

Example:
```kotlin
fun implicitType1() = TopLevelObject.expectedType()

object TopLevelObject {
    private const val privateConstVal = "privateConstVal"
    fun expectedType(): @Anno(privateConstVal) Int = 4
}
```
Here we will try to transform the annotation from `expectedType`
during `implicitType1` and as the result, we will see unresolved
reference on the declaration side. This commit fixes this issue.

This solution is based on the fact that the compiler anyway will
resolve the propagated annotation on the declaration side.
And it doesn't matter if it is resolved before or after the call site
declaration transformation, because as a global result, we will observe
that all declarations are resolved correctly in the right context.

Hence, this commit fixes the issue in the case of "full resolution"
which is true for the compiler, but it is not correct for Low Level
FIR where we resolve declarations on demand. It will be solved in
the next commits

^KT-63042
2023-12-07 12:26:40 +00:00
Dmitrii Gridin a7afd1fe01 [FIR] ReturnTypeCalculatorWithJump: use outer transformer instead of type calculator
This is a more flexible solution

^KT-63042
2023-12-07 12:26:40 +00:00
Dmitrii Gridin ed7415ab93 [FIR] BodyResolveContext: insideClassHeader should add container as well
This container will be used during an annotation call owner search

^KT-63042
2023-12-07 12:26:40 +00:00
Dmitrii Gridin 83bdac8d61 [FIR] CustomAnnotationTypeAttribute: drop containerSymbols
Now annotations have the container symbol itself, so this property
is no longer needed.
This migration fixes issues with a missed container symbol, so now
all cases of lazy resolution from KtType are supported

^KT-63042
2023-12-07 12:26:39 +00:00
Dmitrii Gridin 264a151676 [FIR] do not copy annotations during type propagation
We should share the original instance to be able to later resolve it in
the original context. This commit returns the KT-60387 problem, but the
root cause (concurrent modification) will be fixed in the context of
KT-63042

^KT-63042
2023-12-07 12:26:39 +00:00
Dmitrii Gridin 69559689fd [LL/FIR] add more resolve tests for declarations with annotations
^KT-63042
2023-12-07 12:26:39 +00:00
Dmitrii Gridin c5cba4c053 [FIR] builder: provide containingDeclarationSymbol
We cannot use only non-local declarations as anchors due to the same
resolution logic between member declarations of local classes, so we
have to support such cases as well

^KT-63042
2023-12-07 12:26:39 +00:00
Dmitrii Gridin 1d5ab8c24f [FIR] builder: more tests for annotations
^KT-63042
2023-12-07 12:26:39 +00:00
Nikita Nazarov 0898dd1e7f [FIR] Don't check Java annotations for cycles
^KT-64083 fixed
2023-12-07 08:56:56 +00:00
Yan Zhulanow 1726a94c87 [Pill] Update module structure 2023-12-07 08:53:35 +00:00
Roman Golyshev f266a44356 KT-64080 [LL] Resolve super calls to BODY_RESOLVE for on-air resolve
^KT-64080 Fixed
2023-12-07 01:26:23 +01:00
Roman Golyshev 3c7dfc0e5b KT-64080 [LL] Use nullable receiver overload for isAncestor function
This simplifies the `bodyResolveRequired` a lot
2023-12-07 00:41:55 +01:00
Roman Golyshev a475a3031e KT-64080 [LL] Add on-air resolve tests for enum entry resolution 2023-12-07 00:41:53 +01:00
Nikita Bobko 0d67ae7b23 [TEST] Add regression test for KT-59805 ACTUAL_MISSING for constructor 2023-12-06 18:35:39 +00:00
Tomas Husak 5ccae2801d [FIR] KT-59368 regenerate tests 2023-12-06 17:34:05 +00:00
Tomas Husak d7eb67a436 [FIR] KT-59368 context receiver subtyping checker 2023-12-06 17:34:05 +00:00
Dmitrii Gridin e0c931f69d [LL FIR] rebind returnTarget for delegate accessors during psi2fir
It is safe to rebind returnTarget to the original declaration during
psi2fir as it doesn't affect the resolution. We already have the same
logic for regular functions/property accessors.
This change is crucial in the context of parallel implicit type
resolution because it affects CFG builder in a bad way in the case
of on-air resolution

^KT-56551
2023-12-06 12:59:55 +00:00
Ivan Kylchik 5dbe81fd7f [FIR] Always expand a type before checking it in FirConstChecks
The issue appeared when we analyzed some typealias.
1. The typealias itself could be valid, but it could point
to an invalid type.
2. The typealias could point, for example, to an unsigned
type that must be handled in a special way

#KT-59894
2023-12-06 10:54:21 +00:00
Marco Pennekamp 1901ed36ec [LL] Expand "Low Level FIR API Tests" run configuration to include tests from submodules
- LL API tests should include LL API JDK 11 tests and, if applicable, LL
  API native tests.
2023-12-05 21:31:32 +00:00
Marco Pennekamp ee7c67ba11 [LL] Add LL API module for JDK 11 tests to support Lincheck tests
- Lincheck is compiled with JDK 11 and the `low-level-api-fir` module is
  based on the JDK 8 toolchain, so we need to add a new module with a
  JDK 11 toolchain to support Lincheck tests. We cannot bump
  `low-level-api-fir` to JDK 11 because `low-level-api-fir-for-ide`
  requires it to be based on a JDK 8 toolchain.
- Using a Gradle test suite is unfortunately not an option, because
  `low-level-api-fir-for-ide` will think that the whole
  `low-level-api-fir` module is compiled with JDK 11 if just a single
  test suite has this toolchain.

^KT-62136
2023-12-05 21:31:32 +00:00
Mikhail Glukhikh 06ce57ea56 K2: report MISSING_DEPENDENCY_CLASS for lambda parameters if needed
#KT-62525 Fixed
2023-12-05 18:16:52 +00:00
Mikhail Glukhikh 4b649cbbe9 [tests] Drop a BI codegen test for should-be-red issue KT-63648 2023-12-05 18:15:53 +00:00