Commit Graph

4160 Commits

Author SHA1 Message Date
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
Stanislav Ruban da0c3090a9 [tests] Regenerate test configurations 2023-12-05 18:15:53 +00:00
Kirill Rakhman 8496722603 [FIR] Make UNSAFE_INFIX_CALL and UNSAFE_OPERATOR_CALL parameter nullable
This fixes an NPE in the IDE in presence of a syntax error when the
argument expression has no source.

#KT-64062 Fixed
2023-12-05 17:25:28 +00:00
Nikita Bobko 1aeefe6c33 [FIR] Don't traverse expect hierarchy to check DefaultArgumentsInExpectActualizedByFakeOverride
^KT-63860 Fixed
Review: https://jetbrains.team/p/kt/reviews/13334/timeline

The previous code was nonsense (I wrote it). It doesn't make sense to
subtract actualOverriddenDeclarations from expectOverriddenDeclarations.
Default parameters are mentioned on the expect side. So default params
in expect/actual supertypes won't be subtracted from
expectOverriddenDeclarations (but should be)
2023-12-05 13:30:14 +00:00
Mikhail Glukhikh 1f989dce64 K2: add test for KT-56520, case (7), qualifier receivers (4.2)
This commit covers enum entry vs companion member case,
when two companion objects are in the scope.
K1 reports UNRESOLVED_REFERENCE here, probably due to ambiguity.
About K2, while resolving Some.foo it first tries to resolve Some
as a "general" variable access, and gets two candidates with companions.
After that it tries to resolve Some as a qualifier,
but we have no scope with a single qualifier, so no influence here.
With two ambiguous candidates with companions for Some,
OVERLOAD_RESOLUTION_AMBIGUITY is reported.
2023-12-04 21:50:46 +00:00
Mikhail Glukhikh 63ce4ba6b0 K2: add test for KT-56520, case (7), qualifier receivers (4.1)
This commit covers enum entry vs companion member case,
when one companion object is in the scope.
K1 reports UNRESOLVED_REFERENCE here, probably due to ambiguity.
About K2, while resolving Some.foo it first tries to resolve Some
as a "general" variable access, and gets the only candidate with companion.
After that it tries to resolve Some as a qualifier,
but we have no scope with a single qualifier, so no influence here.
Finally during foo resolve it should choose between enum entry and
companion member, and enum entry wins due to KT-37591.
2023-12-04 21:50:45 +00:00
Mikhail Glukhikh 76b2b9fc66 K2: add test for KT-56520, case (7), qualifier receivers (3)
This commit covers object vs static member case,
when no companion objects are in the scope.
K1 reports UNRESOLVED_REFERENCE here, probably due to ambiguity.
About K2, while resolving Some.foo it first tries to resolve Some
as a "general" variable access, and gets two erroneous candidates
without companions. After it tries to resolve Some as a qualifier,
but we have no scope with a single qualifier.
That's why we finally report NONE_APPLICABLE on candidates with companions.
2023-12-04 21:50:45 +00:00
Mikhail Glukhikh 602801dcfd K2: add test for KT-56520, case (7), qualifier receivers (2.2)
This commit covers object vs companion member vs static member case
but now we have two different companions (first is empty) in the scope.
K1 reports UNRESOLVED_REFERENCE here, probably due to ambiguity.
About K2, while resolving Some.foo it first tries to resolve Some
as a "general" variable access, and gets some/Some & some2/Some
because both of them have a companion. This means ambiguity.
After it tries to resolve Some as a qualifier, but we have no scope
with a single qualifier, so finally we prefer to report ambiguity
from variable access resolve.
2023-12-04 21:50:44 +00:00
Mikhail Glukhikh ab161333a7 K2: add test for KT-56520, case (7), qualifier receivers (2.1)
This commit covers object vs companion member vs static member case
in situation with only one companion in the scope.
K1 reports UNRESOLVED_REFERENCE here, probably due to ambiguity.
About K2, while resolving Some.foo it first tries to resolve Some
as a "general" variable access, and gets only some2/Some
because it has a companion. Then it tries to resolve Some as a qualifier,
but here we have an ambiguity, so finally Some with companion is preferred.
2023-12-04 21:50:43 +00:00
Mikhail Glukhikh c2ac9daa7f K2: add test for KT-56520, case (4), callable references (unbound)
Again, both frontends here ignored classifiers from
explicit star imported scope (some.HashMap, java.util.HashMap)
because of their ambiguity. In case of K2, it works so due to logic
in BodyResolveComponents.resolveRootPartOfQualifier.
This function is called to resolve qualifier without receiver.
See also cases (3) and (7).
2023-12-04 21:50:43 +00:00
Mikhail Glukhikh f0058ee0d8 K2: add test for KT-56520, case (4), callable references (bound)
In this test, things work in the similar way as in constructors case (2).
K1 resolves the explicit receiver HashMap<String, String>()
to kotlin.collections.HashMap /* = java.util.HashMap */.
K2 does the similar, but fun processConstructors from ConstructorProcessing.kt
makes a type alias substitution, so in fact constructor of expanded
java.util.HashMap is processed.

Pay attention that both frontends ignore some.HashMap and java.util.HashMap
due to ambiguous classifiers in explicit star importing scope.
See FirScope.processConstructorsByName in ConstructorProcessing.kt
2023-12-04 21:50:42 +00:00
Mikhail Glukhikh 168717b811 K2: add test for KT-56520, case (7), qualifier receivers (1)
Again, both frontends here ignored classifiers from
explicit star imported scope (some.HashMap, java.util.HashMap)
because of their ambiguity. In case of K2, it works so due to logic
in BodyResolveComponents.resolveRootPartOfQualifier.
This function is called to resolve qualifier without receiver
2023-12-04 21:50:42 +00:00
Mikhail Glukhikh 22d083a7a9 K2: add test for KT-56520, case (3), class literals
Again, both frontends here ignored classifiers from
explicit star imported scope (some.HashMap, java.util.HashMap)
because of their ambiguity. In case of K2, it works so due to logic
in BodyResolveComponents.resolveRootPartOfQualifier.
This function is called to resolve qualifier without receiver, in case
it's used as a receiver itself (::class counts as a selector equivalent).
2023-12-04 21:50:41 +00:00
Mikhail Glukhikh 6fb88102a5 K2: add test for KT-56520, cases (1), (5), (6), type references
In both these situations, we have some.HashMap & java.util.HashMap
from explicit star importing scope, and kotlin.collections.HashMap
from implicit star importing scope after it.
K1 ignores both explicitly imported classifiers due to their ambiguity,
and then resolves to kotlin.collections.HashMap at the next level.
In contrast, K2 takes explicitly imported classifiers and
properly reports ambiguity.
2023-12-04 21:50:40 +00:00
Mikhail Glukhikh d07f3a14e6 K2: add test for KT-56520, case (2), constructors, Space subcase
In this test, both frontends resolve to fun Semaphore.
Both work this way because interface/class Semaphore classifiers are
clashed (ambiguity) and ignored.
K2 reports ambiguity for some similar cases,
but constructor resolve still ignores ambiguous classifiers when found.
(see FirScope.processConstructorsByName in ConstructorProcessing.kt)
2023-12-04 21:50:40 +00:00
Mikhail Glukhikh 6049f8657b K2: add test for KT-56520, case (2), constructors
In this test, K1 resolves to kotlin.collections.HashMap /* = java.util.HashMap */
K2 does the similar, but fun processConstructors from ConstructorProcessing.kt
makes a type alias substitution, so in fact constructor of expanded
java.util.HashMap is processed.

Pay attention that both frontends ignore some.HashMap and java.util.HashMap
due to ambiguous classifiers in explicit star importing scope.
See FirScope.processConstructorsByName in ConstructorProcessing.kt
2023-12-04 21:50:39 +00:00
Roman Golyshev 99c7fab401 KT-59732 [FIR] Adjust test data for the absence of unresolved imports
Now there are no real unresolved imports - all imports are considered
resolved starting from the IMPORTS phase and until they are proven
otherwise in the checkers.

Because of that, some `UNRESOLVED_REFERENCE` diagnostics are gone -
in the cases when such references were actually resolved through
those unsupported imports.

The compilation of incorrect files should not be affected by this,
the checkers would still prevent the compilation of the files with
incorrect imports.
But now the references to the declarations from such imports no longer
will be highlighted as unresolved references.
2023-12-04 16:51:46 +00:00
Kirill Rakhman 476a0b6783 [FIR] Don't capture flexible types that only have projections in one bound
This fixes a false positive NEW_INFERENCE_ERROR.
See the code comment for the rationale.

#KT-63982 Fixed
2023-12-04 15:42:12 +00:00
Simon Ogorodnik cb3d65f669 [Test] Add test for KT-63996
False-positive TYPE_MISMATCH in builder inference with captured types
2023-12-04 15:27:20 +00:00
Nikita Bobko 8c0cf7d0bc [FIR] Fix disappeared ACTUAL_MISSING
^KT-59887 Fixed

Review: https://jetbrains.team/p/kt/reviews/13244
2023-12-04 13:08:23 +00:00
Nikita Bobko e44e84d1b0 [FIR] Reuse expect/actual matching data of outer declarations during matching of inner declarations
Review: https://jetbrains.team/p/kt/reviews/13244

Motivation:
    ```
    // Module :lib
    class Foo {
        val member: Int = 2
    }

    // Module :app
    // dependencies { implementation(project(":lib")) }
    class Foo {
        val member: Int = 2
    }
    ```

    Before the commit:
        app_Foo.expectForActual is `null`
        app_Foo.member.expectForActual = lib_foo.member
    After the commit:
        app_Foo.expectForActual is `null`
        app_Foo.member.expectForActual is `null`

    If I don't fix this problem then
    `CommonizerHierarchicalIT.testCommonizeHierarchicallyMultiModule`
    becomes red after I fix KT-59887 in the following commits

    `app_Foo.member.expectForActual = lib_foo.member` happens because we
    also need to match fake-overrides (KT-63550)

I didn't measure it, but theoretically, this commit should be a
performance improvement, becuase we reuse `expectForActual` cache

Additionally, The commit breaks some other tests (e.g.
compiler/testData/diagnostics/tests/multiplatform/headerClass/actualMissing.fir.kt).
The tests will become green again, once I fix KT-59887
2023-12-04 13:08:23 +00:00
Nikita Bobko 453d871b25 [LL] Run LLFirExpectActualMatchingTargetResolver only for KMP projects
Review: https://jetbrains.team/p/kt/reviews/13244

Motivation: Performance. When I fix KT-59887 in later commits, I will
make actual-to-expect resolve to work not only for actual declarations.
Considering that LLFirExpectActualMatcherLazyResolver worked even for
non-KMP projects that might be a potential performance regression

FirExpectActualMatcherProcessor in the compiler does the same thing (it
checks for MultiPlatformProjects before running the transformer)
2023-12-04 13:08:23 +00:00
Nikita Nazarov 1df318ff28 [FIR] Remove the redundant isFunctionType check
^KT-63865 fixed
2023-12-01 21:04:41 +00:00
Stanislav Ruban 3a77f39199 [tests] Regenerate test configurations 2023-12-01 19:20:28 +00:00
Pavel Kirpichenkov fb9bf1782e [AA] Fall back to JVM stdlib dependencies in common test modules
Returns the old test behavior, until KT-63769 is implemented.
2023-12-01 18:12:23 +00:00
Pavel Kirpichenkov 0eb1a63a2f [AA] Add symbol tests for symbols from JS klibs
Use test compiler runner to compile JS libraries. Determine compiler
by the specified TARGET_PLATFORM. Add tests for dynamic type and
JS-specific .proto extensions.

Refactor the code for mock library compilation to make the switch
between platforms more straightforward.

KTIJ-27566
KT-63217
2023-12-01 18:12:23 +00:00
Pavel Kirpichenkov 0736cb3fac [LL] Fix KtDynamicType deserialization
KT-63217
2023-12-01 18:12:23 +00:00