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
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
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
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
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
I.e. emit VAL_REASSIGNMENT on repeated assignments to `this.something`,
UNINITIALIZED_VARIABLE on reads of it before any assignment if there is
no initializer, and CAPTURED_MEMBER_VAL_INITIALIZATION on assignments
inside non-called-in-place functions and named classes.
^KT-55528 Fixed
`INVISIBLE_REFERENCE` may be reported due to CandidateApplicability via
a ConeDiagnostic, or in a checker. The former leads to
`FirErrorResolvedQualifier`, so the checker is not called.
This makes little sense, because CandidateApplicability may result in
`NO_COMPANION_OBJECT`, which would prevent other more meaningful
diagnostics from being reported (like `API_NOT_AVAILABLE`).
If we run checkers for `FirErrorResolvedQualifier` we may get duplicate
`INVISIBLE_REFERENCE`. The change in the checker prevents it.
Callable symbols with SinceKotlin are filtered out by a
resolution stage, but in K1 classifiers and property accessors
report API_NOT_AVAILABLE. K2 filters out properties with
unavailable accessors, but does nothing for classifiers.
This change fixes it.
^KT-54410 Fixed
Previously it wasn't reported in FIR for ConcurrentHashMap inheritors
because the receiver id hasn't matched CHM.contains id
Fixed by unwrapping origin of the call in case of fake overrides
^KT-55606 fixed
* `return` should only be added to the last statement if the return
type is not Unit
* If there is a `return` without an argument, then the expected return
type is Unit and the last expression is not a return argument (unless
it's an incomplete call, in which case it is inferred to return Unit;
this behavior is questionable, but inherited from K1)
* There should be a constraint on return arguments even if the expected
type is Unit, otherwise errors will be missed
* When the expected type is known, using the call completion results
writer is pointless (and probably subtly wrong).
^KT-54742 Fixed
I.e. maintain a set of seen lambdas where each marked as either "data
flow only" or "both data and control flow". The latter are truly
parallel with the function being analyzed, while the former have
technically already terminated, we just don't know the types inside them
because they may not have been analyzed yet.
Also remove incorrect subtype check checkers
Test unsafeVarianceInAliasedFunctionalType.kt started to fail because
of KT-54894. This bug existed before, changes from this commit just
unhided it (previously it was hidden because incorrect subtype check
in `isSubtypeForTypeMismatch` which is used by FirFunctionReturnTypeMismatchChecker