Commit Graph

99029 Commits

Author SHA1 Message Date
Denis.Zharkov 1e1d122dd3 K2: Simplify ConeConflictResolver hierarchy
Remove AbstractConeCallConflictResolver super class where it's actually
unnecessary
2023-02-15 08:13:56 +00:00
Denis.Zharkov 65f1485dc9 K2: Clarify condition for when-with-one-branch optimization
It's safe resolve the branch in the independent context when
resolution mode would require full completion and there's no expected type
2023-02-15 08:13:56 +00:00
Denis.Zharkov 1bacef4327 K2: Simplify handling mixed smartcast vs. original candidates
There's no real need in binding overrides for smartcast/original members
after FilteringOutOriginalInPresenceOfSmartCastConeCallConflictResolver

Instead, we just create candidates for all of them and filter out after
the ones that came from original type (if needed)
2023-02-15 08:13:55 +00:00
Denis.Zharkov 8fa84e7bea K2: Add clarification comment to KtFakeSourceElementKind 2023-02-15 08:13:55 +00:00
Denis.Zharkov 8ac39dc284 K2: Adjust spec test data behavior with KT-55725
^KT-55725 Related
2023-02-15 08:13:55 +00:00
Denis.Zharkov b6b132a9a3 K2: Avoid false-positive overload resolution ambiguity with smart casts
The idea is that when we have successful candidates both from smart cast
and original type, we should discriminate in the favor of former ones.

While this problem (see kt55722.kt) existed before this branch is merged,
initially it was recognized on FP Ultimate when we stopped assuming
captured types from the same projections as equal (see kt55722Initial.kt).

^KT-55722 Fixed
^KT-55024 Fixed
^KT-56283 Related
^KT-56310 Related
2023-02-15 08:13:54 +00:00
Denis.Zharkov 7b6c6fceb6 K2: Adjust test data for KT-55698
It started being reported after we stopped ignoring diagnostics
on synthetic calls.
2023-02-15 08:13:54 +00:00
Denis.Zharkov a4c5e1bc87 K2: Unwrap fake overrides before using them as DFA identifiers
It's necessary because even for stable a.b.c.d we can't guarantee that
this reference will always point to the same symbol because
different capture type instantiations generate different scopes
with different resulting symbol instances.
2023-02-15 08:13:53 +00:00
Denis.Zharkov 9af3e5704d K2: Do not add extension receiver's constraint twice for references
The job is already done at CheckExtensionReceiver resolution stage
And repeating it might only lead to incorrect errors caused by
double-capture of receiver type that leads to contradiction because
in previous commit we started assuming different capture instantiations
as different types.
2023-02-15 08:13:53 +00:00
Denis.Zharkov 2b3f34cc52 K2: Fix false-positive type equality for different captured types
This is mostly a revert of 2f61a2f56f
There, we erroneously assumed that we may take captured types as equal
if they are based on the same-typed projections.

Each instance of capturing defines its own captured type,
that should not be equal to any other type captured in other place.

Initial motivation was brought by FP Ultimate, where a piece of code
from the new test was found that started working differently after
recent changes.

The most obvious consequence is the change in addAllProjection.fir.kt:
one cannot use an instance as an argument when expected type
is captured type based on the same instance.

Otherwise, it would lead to CCE if we allowed to put arbitrary charsequences
to the list that initially was a MutableList<String>

All other test data changes (but addAllProjection.fir.kt and differentCapturedTypes.kt)
are irrelevant and will be fixed in the subsequent commits
2023-02-15 08:13:52 +00:00
Denis.Zharkov 181f23bd8d K2: Emulate K1 behavior in case of when-elvis combination
^KT-55692 Related
2023-02-15 08:13:51 +00:00
Denis.Zharkov e46ef0bbec Fix FIR bootstrap caused by KT-55281
In this branch it's necessary, because we started reporting diagnostics
that have been ignored before
2023-02-15 08:13:51 +00:00
Denis.Zharkov 2bafcddf7a K2: Avoid using Nothing? as inference result in the majority of cases
Namely, do not choose `Nothing?` result type when fixing a variable
that has other constraints besides the ones that came from
the relevant type parameter's upper bounds.

See more details in KT-55691.

In K1, the case from specialCallWithMaterializeAndExpectedType.kt
was working (inferred to String?) just because the branches
were analyzed independently with `String?` expected type.

This change became necessary after the previous commit when we united
inference subsystems for if/when branches (see motivation there).

NB: For K1, the behavior is left the same, but the code
was refactored a bit.

^KT-55691 Fixed
^KT-56448 Fixed
2023-02-15 08:13:50 +00:00
Denis.Zharkov f12a4e08cf K2: Do not force completion for 'when' branches with expected type
Otherwise, it leads to branches inference run fully independent,
while there are cases when it's necessary to flow type information from
one of the branch to another (see the new test).

NB. In K1, it worked differently: if branches were inferred altogether
only for Any/Any? expect types (otherwise they're analyzed independently)
See foo2/foo4 in the test.

To avoid breaking change we need to support foo1/foo3, but we're trying
not to have some special rule for Any, so we've got a new resolution mode
that provides expect type, but doesn't require full completion.

^KT-45989 Fixed
^KT-56563 Fixed
^KT-54709 Related

For change in specialCallWithMaterializeAndExpectedType.kt
At first, see at KT-36776

Long time ago, it's been decided that if/when resolution
should look similar to similar "select()" calls,
but it's a breaking change (see KT-36776), and we were ready for that back then.

But then, there were too many broken cases found, thus we reverted it at
100a6f70ca

But probably, it would be better to try to infer `String?`
instead of `Nothing?` (see next commits)

Note that change in specialCallWithMaterializeAndExpectedType.kt
will be addressed in later commits, too
2023-02-15 08:13:49 +00:00
Denis.Zharkov e43d8bbb47 K2: Require resolved type for ResolutionMode.WithExpectedType
Implicit type might have two meaning there:
- noExpectedType
- unknown declaration type where this expression is assigned to

For both cases, we've got ResolutionMode.ContextIndependent that works
just fine
2023-02-15 08:13:48 +00:00
Denis.Zharkov df826f04a7 K2: Generify completion mode computation
Now, it's generated from ResolutionMode, that later allows to define
more granular rules
2023-02-15 08:13:48 +00:00
Denis.Zharkov 28ff276320 K2: Unify completeCall overloads and usages
- Leave only the overload with ResolutionMode parameter
- Get rid of boolean flags that belong to ResolutionMode.WithExpectedType
2023-02-15 08:13:48 +00:00
Denis.Zharkov 73fa41f7fb Minor. Reformat FirExpressionsResolveTransformer.kt 2023-02-15 08:13:47 +00:00
Denis.Zharkov cc1b608661 K2: Merge all expected-type related resolution modes into single class
It looks more natural and allows to combine different properties
of these cases
2023-02-15 08:13:47 +00:00
Denis.Zharkov 33dcbaac16 K2: Change resolution rules of when/if expressions with expected type
When expected type is known, use it as expected type for branch bodies.
While it indeed becomes different from the usual select call resolution,
where expected type is applied only after completion starts,
it helps to support, e.g. callable references resolution just as powerful
as it was in K1.

Also, in some cases where diagnostics have been changed, they become
a bit more helpful since they are reported closer
to the problematic places

cannotCastToFunction.kt test has been removed because it relied
on the case erroneously supported by the hack removed from
the FirCallResolver in this commit.

^KT-45989 Fixed
^KT-55936 Fixed
^KT-56445 Fixed
^KT-54709 Related
^KT-55931 Related
2023-02-15 08:13:46 +00:00
Denis.Zharkov a38040680c K2: Do not use KFunctionN as representation type for adapted references
Beside some corner cases, it's already prohibited in K1 because
adaptation have a bit strange nature
(they don't represent any existing real function exactly)

^KT-55137 Fixed
2023-02-15 08:13:45 +00:00
Denis.Zharkov dcdc48a233 K2: Support callable references adaptation on top-level
^KT-45989 In progress
^KT-54709 Related
^KT-55217 Fixed
2023-02-15 08:13:44 +00:00
Denis.Zharkov 8f8ea8c57f K2: Optimize one-branch when-expr case only for independent context
Using independent one where `when` is nested doesn't look correct
2023-02-15 08:13:43 +00:00
Denis.Zharkov 04d3996e68 K2: Resolve non-exhaustive when expressions independently
^KT-55169 Fixed
^KT-55175 Related
2023-02-15 08:13:43 +00:00
Denis.Zharkov 9fa0f51a61 K2: Fix false-negative RETURN_TYPE_MISMATCH
^KT-53987 Fixed
^KT-55932 Fixed
2023-02-15 08:13:42 +00:00
Denis.Zharkov d7399ed1cf K2: Avoid losing diagnostics for synthetic calls
Some of the changed tests may duplicate other existing diagnostics,
but that should not be reason not to report them at all.

There might be another job to be done to avoid diagnostic duplications
2023-02-15 08:13:41 +00:00
Denis.Zharkov fe5adab652 K2: Avoid inference diagnostics when arguments are already error typed
For example, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER

It became especially relevant after 0e84bf2053
that together with later commits bring a lot of unnecessary
NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER diagnostic
2023-02-15 08:13:41 +00:00
Igor Chevdar 564b40f05d [K/N] Fixed resolve order of compiler caches
#KT-56611 Fixed
2023-02-15 07:06:05 +00:00
Igor Chevdar 951ebf4082 [K/N] Added a test for KT-56611 2023-02-15 07:06:05 +00:00
Ilya Gorbunov 3d05565b99 Remove tasks for zipping compiler testdata and stdlib test sources 2023-02-14 23:37:32 +00:00
Sergey.Shanshin 498c1abbc6 [KxSerialization] Fix SERIALIZER_NOT_FOUND diagnostic for enums
If enum class from dependencies is used, which was compiled by a new version of the plugin, which uses a factory and does not create a nested `$serializer` class, then an `SERIALIZER_NOT_FOUND` diagnostic error is thrown for such an enumeration.
This happens if the old serialization runtime is used for the current project - in this case, the serializer is taken from the nested class `$serializer`. Since it is missing, the diagnostics does not work correctly.
It is acceptable for enumerations to ignore this error, because we know that enumerations are always serializable.

Merge-request: KT-MR-8818
Merged-by: Sergey Shanshin <Sergey.Shanshin@jetbrains.com>
2023-02-14 22:10:30 +00:00
Sergey.Shanshin c9b8160f1e [kxSerialization] Added diagnostic on useless Serializer annotation
Resolves Kotlin/kotlinx.serialization#2182

Merge-request: KT-MR-8718
Merged-by: Sergey Shanshin <Sergey.Shanshin@jetbrains.com>
2023-02-14 22:00:33 +00:00
Vladimir Sukharev 3124154aef [K2/N] Fix false negative interop_objc_kt55938 under K2
Merge-request: KT-MR-8817
Merged-by: Vladimir Sukharev <Vladimir.Sukharev@jetbrains.com>
2023-02-14 20:32:45 +00:00
Vladimir Sukharev 255d4fa829 [K/N] Don't reuse irGet node in cleanerField tree
Merge-request: KT-MR-8831
Merged-by: Vladimir Sukharev <Vladimir.Sukharev@jetbrains.com>
2023-02-14 20:31:13 +00: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
Dmitriy Novozhilov aef9b129d2 [FIR] Add regression tests for number of issues fixed in K2
List of issues:
KT-4113,  KT-6822,  KT-7389,  KT-17817, KT-20223
KT-21463, KT-24503, KT-24737, KT-24779, KT-24901
KT-27261, KT-28668, KT-30497, KT-30756, KT-36958
KT-37365, KT-37490, KT-38288, KT-41038, KT-41721
KT-42136, KT-42169, KT-42449, KT-42715, KT-43553
KT-43603, KT-43846, KT-43936, KT-46288, KT-46301
KT-47373, KT-47484, KT-47490, KT-47495, KT-47750
KT-47815, KT-47870, KT-48975, KT-49024, KT-49045
KT-50134, KT-50160, KT-50550, KT-51045, KT-51143
KT-51796, KT-52262, KT-52424, KT-52860, KT-52934
KT-53086, KT-53494, KT-53671, KT-53752, KT-53819
KT-54478, KT-54518, KT-54931, KT-54990, KT-55138
KT-55379, KT-55555, KT-56243
2023-02-14 17:08:55 +00:00
Dmitriy Novozhilov 8ae5213155 [FIR] Add tests for KT-50386 and KT-50646 2023-02-14 17:08:54 +00:00
Dmitriy Novozhilov 092ebf4c11 [FIR] Add test for KT-49249 2023-02-14 17:08:54 +00:00
Dmitriy Novozhilov 019d7db737 [FIR] Add regression test for KT-44392
Also related to KT-56615
2023-02-14 17:08:53 +00:00
Dmitriy Novozhilov 197f19c627 [FIR] Add test for KT-43619 2023-02-14 17:08:53 +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
Anton Lakotka 515a401b23 [Gradle, Test] separate lib publication and app assemble to different builds
To prevent build failures due to race conditions
with publication and consumption
2023-02-14 15:15:12 +00:00
Anton Lakotka 96ba03a708 [Gradle] Move configureMDConfigurations to resolvableMetadataConfiguration 2023-02-14 15:15:12 +00:00
Sebastian Sellmair 25f6b4c922 [Gradle][Minor] Make collectAllProjectStructureMetadataInCurrentBuild private
^KT-56431 Verification Pending
^KT-56461 Verification Pending
2023-02-14 15:15:11 +00:00
Sebastian Sellmair 8f4dd86788 [Gradle] Move KotlinSourceSet metadata configuration into separate source file
^KT-56431 Verification Pending
2023-02-14 15:15:11 +00:00
Sebastian Sellmair f21e08f6b9 [kotlin-tooling-core] Add extrasNullableLazyProperty API
^KT-56431 Verification Pending
2023-02-14 15:15:11 +00:00
Sebastian Sellmair b646a43dab [Gradle] ResolvableMetadataConfigurationTest: Check ide dependencies
^KT-56461 Verification Pending
2023-02-14 15:15:10 +00:00
Sebastian Sellmair 0a2b873415 [Gradle] GranularMetadataTransformation: Support dependency constraints
^KT-56431 Verification Pending
^KT-56461 Verification Pending
2023-02-14 15:15:10 +00:00
Sebastian Sellmair 380ca95661 [Gradle] resolvableMetadataConfiguration: Ensure consistent resolution across all compile dependencies
^KT-56461 Verification Pending
^KT-56431 Verification Pending
2023-02-14 15:15:10 +00:00
Anton Lakotka 5ec153822a [Gradle] Replace provider by lazy in ProjectData 2023-02-14 15:15:09 +00:00