Commit Graph

1219 Commits

Author SHA1 Message Date
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 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 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 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
Dmitriy Novozhilov e9204521a9 [FIR] Properly create type ref for error type in various places 2023-02-06 08:09:56 +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
Nikolay Lunyak 906b16b41e [FIR] KT-55503: Fix current behavior 2023-02-03 08:26:17 +00:00
Kirill Rakhman 1eb18f13bd FIR: Fix test data after making LHS of assignment an expression
KT-54648
2023-01-31 08:39:43 +00:00
Dmitriy Novozhilov 4c96495eef [FIR] Put new contract syntax under feauture flag
^KT-55171 Fixed
2023-01-31 07:53:09 +00:00
Dmitriy Novozhilov 2fddb15539 [Test] Move some builder inference tests from codegen to diagnostics
^KT-56169
2023-01-30 09:29:58 +00:00
Dmitriy Novozhilov 88efa6bfb6 Update tests after switching to LV 1.9 2023-01-30 09:29:57 +00:00
Nikolay Lunyak e2403c801f [FIR] KT-55747: Report error for operator fun mod
^KT-55747 Fixed

Merge-request: KT-MR-8522
Merged-by: Nikolay Lunyak <Nikolay.Lunyak@jetbrains.com>
2023-01-30 08:48:33 +00:00
pyos 99e51f6940 FIR: check assignments and references to members in constructors
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
2023-01-26 13:12:13 +00:00
Nikolay Lunyak e187c9272d [FIR] Run checkers for FirErrorResolvedQualifier
`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.
2023-01-25 07:14:19 +00:00
Nikolay Lunyak 9be819087a [FIR] KT-54410: Report API_NOT_AVAILABLE for classifiers
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
2023-01-25 07:14:19 +00:00
Vsevolod Tolstopyatov 21fe0e80ff [K2] Report CONCURRENT_HASH_MAP_CONTAINS_OPERATOR_ERROR for class hierarchies
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
2023-01-17 09:46:25 +00:00
Ilya Kirillov 3afb93ca31 [FIR] fix resolve contract violation from ConeTypeContext.getValueClassProperties
^KT-54890
2023-01-13 21:32:52 +00:00
Ilya Kirillov 1bbcae5ed2 [FIR] fix resolve contract violation from scopes
We cannot call lazy resolve to STATUS phase from scopes as scopes may be accessed on a STATUS phase or earlier

^KT-54890
^KTIJ-23587 fixed
2023-01-13 21:32:51 +00:00
Kirill Rakhman 69f2e8826a FIR: fix a bunch of issues after DiagnosticsReporter refactoring related to reporting diagnostic on null source 2023-01-11 08:30:36 +00:00
pyos 5e8591d61d FIR: use expected type for lambda return statements if possible 2023-01-10 15:40:46 +02:00
pyos 803abfeba8 FIR: rewrite lambda return type inference
* `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
2023-01-10 15:40:45 +02:00
pyos ee6af9af5f FIR: intersect flexible type bounds separately
^KT-54522 Fixed
2023-01-04 18:29:33 +00:00
Ilya Gorbunov 916f733f73 Make k.c.Volatile since 1.9 in JVM and Common KT-55268, KT-55609
Leave it experimental since 1.8 for K/Native.
2023-01-04 17:28:46 +00:00
Kirill Rakhman 721a37f7e7 K2: implement FirLateinitIntrinsicApplicabilityChecker ^KT-55495 Fixed 2023-01-04 14:42:43 +00:00
Mikhail Glukhikh 0d50f71fb8 K2: expand type aliases in annotation position #KT-55615 Fixed 2023-01-04 10:06:39 +00:00
Ilya Gorbunov e2d96da396 Introduce experimental kotlin.concurrent.Volatile annotation KT-55268, KT-55609
Use this annotation in tests to ensure it works the same at least on JVM
2022-12-23 19:07:30 +01:00
Dmitriy Novozhilov 02e327277e [FIR] Report VAL_REASSIGNMENT on assign to non-local vals
In this commit reporting on member properties in init section of class
  is not supported (see KT-55528)

^KT-55493 Fixed
2022-12-20 08:12:09 +00:00
Dmitriy Novozhilov b174bb8844 [FIR] Update testdata after introducing FirResolvedErrorReference 2022-12-15 12:12:19 +00:00
Steven Schäfer 6af616d3c3 FIR: make declarations marked with 'override' implicitly open
#KT-52236 Fixed
2022-12-14 21:46:41 +00:00
Ilya Kirillov 644d1bf0d0 [FIR] ignore tests which fail because of resolve contracts violation 2022-12-12 16:21:07 +00:00
Denis.Zharkov cd0d6d2773 Adjust test data for postponing ProhibitUsingNullableTypeParameterAgainstNotNullAnnotated
^KT-55357 Related
^KT-36770 Related
2022-12-12 11:39:04 +00:00
pyos 402ea98e02 FIR DFA: align FirLocalVariableAssignmentAnalyzer with the graph builder
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.
2022-12-08 10:19:34 +00:00
pyos 0d46dfc1ba FIR: fix substitution of type arguments in SAM type aliases
^KT-54730 Fixed
2022-12-07 22:09:20 +00:00
Dmitriy Novozhilov ac7fddaad5 [FE] Always infer upper types to intersection types in K2...
...and always use old algorithm for K1

^KT-51221
2022-11-29 12:25:44 +00:00
Evgeniy.Zhelenskiy 002f6bd34a [FIR] Fix JvmName annotation diagnostics
Signed-off-by: Evgeniy.Zhelenskiy <Evgeniy.Zhelenskiy@jetbrains.com>

#KT-55143
2022-11-25 16:30:22 +01:00
Mikhail Glukhikh 3e22f6c052 K2 opt-in: fix reporting of WasExperimental-bound errors 2022-11-23 12:00:08 +00:00
Mikhail Glukhikh f62bdb0e3d K1 opt-in: fix message/behavior for future error with WasExperimental 2022-11-23 12:00:08 +00:00
Mikhail Glukhikh 8ddc535caf Opt-in: forbid/deprecate constructor call with default arguments under marker
#KT-55074 Fixed
2022-11-23 12:00:07 +00:00
Mikhail Glukhikh b92ce68f32 K2 opt-in: restore marker annotation check for constructors 2022-11-23 12:00:07 +00:00
Mikhail Glukhikh a77750a257 K2 opt-in: drop redundant recursive check for overridables 2022-11-23 12:00:06 +00:00
Mikhail Glukhikh 73cb4d1a6e K2 opt-in: don't take sub./int. override parent classes into account
#KT-54823 Fixed
2022-11-23 12:00:04 +00:00
Dmitriy Novozhilov eb8ce449e3 [FIR] Don't lose flexible types during capturing from expression 2022-11-22 15:46:22 +00:00
Dmitriy Novozhilov 9b7b517f43 [FIR] Properly resolve declarations inside contract calls on CONTRACT phase 2022-11-22 15:46:21 +00:00
Dmitriy Novozhilov 01c6c7dc59 [FIR] Properly approximate return type of callable declarations
- approximate intersection types in all non-local declarations
- approximate local types in non-private non-local declarations
2022-11-22 15:46:20 +00:00
Dmitriy Novozhilov 991d8c18aa [FIR] Fix incorrect inference of return type of anonymous functions
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
2022-11-22 15:46:19 +00:00
Dmitriy Novozhilov 0e84bf2053 [FIR] Don't report ARGUMENT_TYPE_MISMATCH on error types 2022-11-22 15:46:19 +00:00
Dmitriy Novozhilov 07567d6748 [FIR] Always fix type variables with UNKNOWN direction 2022-11-22 15:46:18 +00:00
Dmitriy Novozhilov 1b27d60307 [FIR] Support @OnlyInputTypes annotation
^KT-54807 Fixed
2022-11-22 15:46:17 +00:00