Commit Graph

3552 Commits

Author SHA1 Message Date
Denis.Zharkov 66eb29962a K2: Add minor clarification comment to FirDeclarationsResolveTransformer 2023-02-21 18:39:40 +00:00
Denis.Zharkov 3f052af517 K2: Propagate explicit getter type to the property without initializer
In K1, we have the rules like:
- if there's explicit type of a property, then use it
- if there's an initializer, obtain its expression-type
- Otherwise, use getter's return type

The case when getter's type is implicit is handled at
FirDeclarationsResolveTransformer.transformProperty

^KT-56707 Fixed
2023-02-21 18:39:40 +00:00
Denis.Zharkov c09607c791 K2: Minor. Reformat and clean up a couple of transformers
`@Suppress("UNCHECKED_CAST")` became redundant there
2023-02-21 18:39:40 +00:00
Denis.Zharkov bdb1e28912 K2: Minor. Simplify condition at FirDeclarationsResolveTransformer
Just to avoid double negation at !hasNonDefaultAccessors
2023-02-21 18:39:39 +00:00
Dmitriy Novozhilov e70e85d51a [FIR] Move unwrapSmartcastExpression util into :compiler:fir:tree module 2023-02-17 12:29:17 +00:00
Dmitriy Novozhilov d52b52ff5c [FIR] Drop unused ResolvedStatusCalculator class 2023-02-17 12:29:17 +00:00
Dmitriy Novozhilov 914acd841f [FIR] Add special kind for graph of init blocks and local functions 2023-02-17 11:26:17 +00:00
Nikolay Lunyak 3c36a4fabd [FIR] KT-56665: Filter-out valid cycles
^KT-56665 Fixed

Merge-request: KT-MR-8861
Merged-by: Nikolay Lunyak <Nikolay.Lunyak@jetbrains.com>
2023-02-16 17:48:38 +00:00
Denis.Zharkov b4b443034f K2: Fix false-positive OVERLOAD_RESOLUTION_AMBIGUITY
It's been introduced in the previous commit
("K2: Simplify handling mixed smartcast vs. original candidates")

Because previously, it was assumed wrongly that each next level of
ConeCallConflictResolver filter out the candidates that are 100% less
applicable/specific, but the main one (ConeOverloadConflictResolver)
either leaves the single candidate or the whole same set, thus at
FilteringOutOriginalInPresenceOfSmartCastConeCallConflictResolver
we've got 4 candidates only two of which we might filter out.
2023-02-15 08:13:57 +00:00
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 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 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 181f23bd8d K2: Emulate K1 behavior in case of when-elvis combination
^KT-55692 Related
2023-02-15 08:13:51 +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
Denis.Zharkov 427b221eaf K2: Get rid of redundant parameter of ConeCallConflictResolver methods
discriminateGenerics was only set to false in recursive calls of
ConeOverloadConflictResolver
2023-02-14 07:14:10 +00:00
Kirill Rakhman 314784f435 [FIR] Introduce FirDeclarationStatus.hasStableParameterNames
This flag is true by default but is set to false for

- Java methods and constructors
- interface delegation methods that delegate to Java

The NAMED_ARGUMENTS_NOT_ALLOWED logic is mostly refactored to use the
new flag though some custom logic remains for determining the correct
message and to work around a corner case with fake overrides.

The flag is (de)serialized from/to metadata. For backward compatibility
with K1, delegated methods to Java types are deserialized as stable.

^KT-40480 Fixed
2023-02-13 12:09:39 +00:00
Kirill Rakhman 152e63b198 [FIR] Remove redundant setting of DeclarationStatus properties 2023-02-13 12:09:39 +00:00
Dmitriy Novozhilov ff4c5c1d03 [FIR] Pass symbol of containing class to FirStatusTransformerExtension instead of fir node 2023-02-10 12:30:13 +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
Mikhail Glukhikh 1ee93553df K2: extract isSubtypeForSamConversion for SAM arguments check
Related to KT-53966
2023-02-08 17:40:21 +00:00
Mikhail Glukhikh 898a9a0f2c K2: apply SAM if argument has postponed lambdas #KT-53966 Fixed 2023-02-08 17:40:21 +00:00
aleksandrina-streltsova 7db32f6430 [FIR] Fix unexpected primary constructor scope in secondary constructor
^KTIJ-23720
^KT-56353 Fixed
2023-02-06 10:30:28 +00:00
Dmitriy Novozhilov c25a5bc9c1 [FIR] Cleanup storing context for lambdas during body resolution 2023-02-06 10:08:37 +00:00
Dmitriy Novozhilov 791a7b1c31 [FIR] Extract function type kind for lambda in argument position
^KT-56381 Fixed
2023-02-06 10:08:37 +00:00
Dmitriy Novozhilov f479a56f5e [FIR] Fix reporting of CANNOT_INFER_PARAMETER_TYPE on lambda parameters
^KT-56138 Fixed
2023-02-06 08:09:57 +00:00
Dmitriy Novozhilov 76d360d793 [FIR] Properly set source for inferred return type of function 2023-02-06 08:09:56 +00:00
Dmitriy Novozhilov e9204521a9 [FIR] Properly create type ref for error type in various places 2023-02-06 08:09:56 +00:00
Dmitrii Gridin cc7527a5bc [FIR] CompilerRequiredAnnotationsHelper: update kdoc and drop commented values
^KT-56046
2023-02-03 19:49:15 +00:00
Dmitrii Gridin 24041bf96d [FIR] CompilerRequiredAnnotationsHelper: add kdoc about usages from SLC
^KT-56046
2023-02-03 19:48:56 +00:00
Dmitrii Gridin 16caeafa98 [FIR] temporarily remove Retention and Target annotations from COMPILER_REQUIRED_ANNOTATIONS phase
currently AbstractFirSpecificAnnotationResolveTransformer doesn't
work well for annotations with arguments

^KT-56046
2023-02-03 19:48:44 +00:00
Dmitrii Gridin 77609c2223 [AA FIR] avoid redundant resolve by annotations in IDE mode
^KT-56046
2023-02-03 19:48:43 +00:00
Dmitrii Gridin 00633e3abc [FIR] Move annotations required by IDE to COMPILER_REQUIRED_ANNOTATIONS phase
this annotations should be already resolved before TYPES phase
to avoid deadlocks

^KT-56046
2023-02-03 19:48:43 +00:00
Yan Zhulanow e8570826e6 [LL API] Replace 'FirScript.containingFileSymbol' with 'FirProvider' API 2023-02-03 08:59:37 +00:00
Nikolay Lunyak 603b46e531 [FIR] KT-55503: Prefer members-extensions over @HidesMembers extensions
Passing `EXTENSION_RECEIVER` when processing `noReceiver`
looks like a mistake in general. This change is backed
by the `hidesMembers` and
`memberWithHidesMemberAnnotationVsMemberWithout` tests.

The exact reason with `memberWithHidesMemberAnnotationVsMemberWithout`
is that it first checks `@HidesMembers` candidates,
only takes the `kotlin/collections/Iterable<T>.forEach`,
but then yields `InapplicableWrongReceiver`,
because `explicitReceiverKind = EXTENSION_RECEIVER`
(which is strange, because we really don't have an explicit receiver).
Then we visit the same scope once more (now for all candidates)
and take 2 functions:

- `kotlin/collections/Iterable<T>.forEach`
- `kotlin/sequence/Sequence<T>.forEach`

...and they both result in `RESOLVED`,
because this time `explicitReceiverKind = NO_EXPLICIT_RECEIVER`.

This change ensures the first candidate we see
while checking `@HidesMembers` is taken as `RESOLVED`.

^KT-55503 Fixed
2023-02-03 08:26:17 +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