Commit Graph

806 Commits

Author SHA1 Message Date
Denis.Zharkov b1bb7dd25f K1: Fix regression with callable references as last statements in lambda
^KT-55729 Fixed
2023-01-19 10:00:02 +00:00
Denis.Zharkov a37e3def14 Add test for KT-55931 2023-01-19 10:00:02 +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
pyos b6653dd872 Minor: remove some duplicate test data
Apparently if you add an empty line at the start of the FIR file, that's
not enough of a difference for the test suite to complain about, but
enough for it to not add the FIR_IDENTICAL directive...
2023-01-10 15:40:46 +02:00
pyos 5e8591d61d FIR: use expected type for lambda return statements if possible 2023-01-10 15:40:46 +02:00
pyos 1eccb9aea1 FIR: assume a lambda returns Unit if it ends with a non-expression
While it is theoretically useful to know that `{ while(true) {} }`
returns Nothing, CFG node deadness is not precise enough to do that: if
the entire lambda is dead, it's no longer possible to find out whether
the loop is terminating. Besides, `while (true)` and `if (true)` are
pretty much the only constructs like that anyway.

Note that this commit does not affect resolution for lambdas that end in
a Nothing-returning expression, e.g. `throw`.
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 544cf386af Add test for KT-54742 2023-01-10 15:40:45 +02:00
Kirill Rakhman 2a724787f0 K2: fix SUPERTYPE_NOT_INITIALIZED not being reported on object expressions ^KT-55597 Fixed 2023-01-04 15:09:26 +00:00
Marco Pennekamp 5f554d0065 [FIR] KT-54980 Fix resolvability of too few/too many type arguments
- If too few or too many type arguments were provided, they were all
  thrown away in `TypeArgumentMapping`,
  `FirCallCompletionResultsWriterTransformer`, and `KtFirCallResolver`.
  The fix handles type arguments of the wrong arity more gracefully.
  - Note for `TypeArgumentMapping`: Excess type arguments are not needed
    for candidate resolution. Excess type arguments are still resolved
    due to the handling in `FirCallCompletionResultsWriterTransformer`.
- Post-processing in `AllCandidatesResolver`: When all candidates are
  resolved in `AllCandidatesResolver.getAllCandidates`, the function
  builds a FIR file. During that resolution, the
  `generic<String, String>` call (in example
  `functionCallWithTooFewTypeArguments.kt`) is correctly marked as
  inapplicable, but the missing type argument is inferred as an error
  type. `firFile` then contains a function call
  `generic<String, String, ERROR>` instead of `generic<String, String>`.
  This call is still marked as inapplicable. Despite that, the
  *subsequent* resolution by
  `bodyResolveComponents.callResolve.collectAllCandidates` disregards
  the call's inapplicability and resolves successfully into an
  applicable candidate. This is because `CandidateFactory` doesn't make
  any guarantees for already inapplicable calls. The fix adds
  post-processing to `AllCandidatesResolver` to preserve candidate
  inapplicability.
- Most tests that this commit changes had slightly different results due
  to type arguments becoming resolvable.
- `wrongNumberOfTypeArguments.kt` and
  `wrongNumberOfArgumentsInTypeAliasConstructor.kt`:
  `ConeDiagnostic.toFirDiagnostics` prefers specific errors. Because
  `ARGUMENT_TYPE_MISMATCH` is specific and `INAPPLICABLE_CANDIDATE` is
  not, only the former is reported. I see no reason to pass an illegally
  typed argument in either test, so the change reduces the errors to
  `INAPPLICABLE_CANDIDATE`.
- `typeAliasSamAdapterConstructors2.fir.kt`: See KT-55007.
- Disable `mismatchTypeParameters` JS backend test due to its handling
  of excess type arguments. See KT-55250.

^KT-54980 fixed
2023-01-02 16:36:02 +00:00
Marco Pennekamp 2cdcdce6ed [LL FIR] KT-55327 Use body resolve return type calculator for locals
- LL FIR uses `ReturnTypeCalculatorWithJump` by default because it
  cannot guarantee that the implicit types of non-local functions
  referenced in a function `f` have been resolved during body resolve
  of `f`.
- However, if `ReturnTypeCalculatorWithJump` encountered a local
  function, it tried to resolve its return type even during body
  resolve of that same local function. The fix delegates to
  `ReturnTypeCalculatorForFullBodyResolve`, which should be used for
  local declarations.

^KT-55327 fixed
^KT-55324 fixed
2023-01-02 14:03:42 +01:00
Dmitriy Novozhilov b174bb8844 [FIR] Update testdata after introducing FirResolvedErrorReference 2022-12-15 12:12:19 +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
Mikhail Glukhikh 758a4931e3 EmptyIntersectionTypeChecker: drop also incompatible supertypes check
Incompatible supertypes check also don't provoke runtime problems
in most situations, because this check is also bound to type argument
conflict. Related to KT-54411
2022-12-09 15:00:41 +00:00
Mikhail Glukhikh 2a1a5c6936 EmptyIntersectionTypeChecker: drop questionable check of arguments
The situations with conflicting type arguments normally don't provoke
any runtime problems. Also, conflicts like A<T> VS A<SomeType> aren't
valid at all. Here we decided to remove them to avoid strange
and non-actionable warnings in user code.

#KT-54411 Fixed
2022-12-09 15:00:40 +00:00
Mikhail Glukhikh 832baf81e5 EmptyIntersectionTypeChecker: fix error in diagnostic text
Related to KT-54411
2022-12-09 15:00:39 +00:00
Mikhail Glukhikh d5c8d9fecc FE: add test reproducing KT-54411 2022-12-09 15:00:38 +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
Denis.Zharkov ca12cfb90d K2: Do not fix variables that has yet unprocessed constraints in forks
Otherwise, exception from org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintInjector.TypeCheckerStateForConstraintInjector.fixedTypeVariable
might happen during forks resolution

The test data is extracted from intelliJ FP test

^KT-43296 Fixed
2022-11-24 17:29:30 +00:00
Denis.Zharkov b73acd7a3a K2: Apply constraints from forks at UNTIL_FIRST_LAMBDA completion phase
Otherwise, OVERLOAD_RESOLUTION_AMBIGUITY is reported for the calls to
the functions annotated as @OverloadResolutionByLambdaReturnType

^KT-43296 In Progress
2022-11-24 17:29:29 +00:00
Denis.Zharkov 10d63cc52a K2: Postpone inference forks resolution until FULL completion
It helps to use expected type information when choosing the branch
even in the nested calls

^KT-43296 In Progress
2022-11-24 17:29:29 +00:00
Denis.Zharkov 715a73c8fb K2: Support inference case with a mix of smart-cast and expected type
The idea is that we should not fix (i.e. choose any of the fork branches)
on the stage of candidate processing before completion, but it's enough
just to check that current state can be converged to success.

And when completion starts, and we add expected type to the system,
we've got more information to choose the correct fork branch.

NB: The old `processForkConstraints` is being called just
at the beginning of the completion phase.

^KT-43296 In Progress
2022-11-24 17:29:28 +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 1b27d60307 [FIR] Support @OnlyInputTypes annotation
^KT-54807 Fixed
2022-11-22 15:46:17 +00:00
Anna Kozlova c727dbb8ca [fir compiler] ensure type parameters are included in the resolve scope
to resolve the next parameter bounds (KTIJ-23674)
2022-11-16 22:25:02 +00:00
Dmitriy Novozhilov e6ce008415 [FIR] Ignore leaked internal types because of KT-54568 2022-11-03 08:30:09 +00:00
Dmitriy Novozhilov 22c21ca4df [FIR] Replace uninferred type variables and stub types during delegate inference 2022-11-03 08:30:07 +00:00
pyos 7787638737 FIR: fix substitution of anonymous type's supertype again
^KT-51418 Fixed
2022-11-01 15:28:41 +00:00
Ivan Kochurkin 1deb253bac [FIR] Run FirSupertypesChecker for anonymous objects, ^KT-54300 Fixed 2022-10-13 18:11:49 +00:00
Ivan Kochurkin 9c6df5313a [FIR] Fix substitution of anonymous type's supertypes, ^KT-51418 Fixed 2022-10-13 18:11:47 +00:00
Nikolay Lunyak fcd3e4f4c5 [FIR JS] KT-51740: Alter positioning of NO_VALUE_FOR_PARAMETER 2022-09-30 21:39:20 +03:00
Mikhail Glukhikh a4b2a8c4ea AbstractTypeChecker: fix special case with CapturedType as self type argument
#KT-53908 Fixed
May fix also KT-53271
2022-09-19 19:12:21 +00:00
pyos be5c4a91a4 FIR/FE1.0: keep flexibility when approximating local types 2022-09-14 08:11:04 +00:00
pyos adcbc5ec99 FE1.0: keep nullability when approximating local types (in 1.9)
Report an error that inference will change and type has to be provided
manually in other language versions, since the current behavior is an
unsoundness that can cause runtime NPEs while the new behavior may
silently change overload resolution.

^KT-30054 Fixed
2022-09-14 08:11:04 +00:00
pyos 062308c7c1 FIR: keep nullability when approximating local types
^KT-30054 Open
2022-09-14 08:11:04 +00:00
Mikhail Glukhikh e02fd8f4a8 FE: don't run builder inference in UNTIL_FIRST_LAMBDA mode
#KT-52927 Fixed
2022-09-09 12:44:39 +00:00
Simon Ogorodnik 05d486d55a Fix receiver inconsistency when builder inference restriction disabled
In 154e53c701 update of
extensionReceiverArgument in resolvedCall was accidentally moved into
language feature dependant block
2022-09-05 10:07:41 +00:00
Denis.Zharkov 490382b77f Add test for KT-52782
It just demonstrates/fixate the current "broken" behavior in K1
that we unfortunately have and that is fixed in K2
2022-08-31 09:45:54 +00:00
Denis.Zharkov db1bd4f232 Add test for KT-53124
The issue itself is supposed to be fixed after eb19d39cbf reverted

^KT-53124 Fixed
2022-08-30 15:56:31 +00:00
Denis.Zharkov 42c41a1916 Revert "[FE 1.0] Build captured type's supertypes in an alternative way: use own projection type as a first supertype, then supertypes from the corresponding type parameter's upper bounds"
This reverts commit eb19d39cbf.
2022-08-30 15:56:30 +00:00
Simon Ogorodnik 154e53c701 K1: add diagnostic BUILDER_INFERENCE_STUB_RECEIVER
It's reported on receivers in extension function calls with stub type,
as such calls can shadow members of finalized stub types causing
change of resolve when corresponding type argument specified explicitly

It works by checking extension receiver during call resolution parts run
That way we can easily detect if we found an extension applicable to
stub receiver and report call diagnostic for it

KT-53739
2022-08-30 10:19:26 +00:00
Simon Ogorodnik 105358dcf6 K1: add diagnostic BUILDER_INFERENCE_MULTI_LAMBDA_RESTRICTION
Let's call builder lambdas (BL) a lambda that has non-fixed input type
projection at the moment of lambda arguments analysis, such lambdas
is a subject to be analyzed with builder inference
Due to bug in constraint system joining algorithm, currently system
of two or more such lambdas may lead to unsound type inference

Diagnostic added here should be reported in case when there are two
BL that shares a common constraint system, while not annotated with
@BuilderInference, as a protection against aforementioned bug

It's reported by ConstraintSystemCompleter when such situation has
occurred during builder inference phase, it is the same place that
decides wherever lambdas is subject to builder inference or not

KT-53740
2022-08-30 10:19:25 +00:00
Mikhail Glukhikh f6ad6fb816 Add test for stub type receiver and for KT-53639 2022-08-30 10:19:24 +00:00
Mikhail Glukhikh 5cbecd276c FE: add test reproducing builder inference problem from KT-53422 2022-08-30 10:19:23 +00:00
Mikhail Glukhikh b78106e437 Don't report INFERRED_..._INTO_EMPTY_INTERSECTION with explicit arguments 2022-08-19 14:01:38 +00:00
Mikhail Glukhikh a6b90fcb8e Add a test with false positive "inferred into empty intersection"
Related to KT-50232
2022-08-19 14:01:37 +00:00
Simon Ogorodnik 2a16fe1d0f FIR: Fix overloading by type-arguments
In K1, upper bound violated causes candidate to have lower applicability
due to constraint errors, in K2 however constraint errors has to be
reported explicitly
2022-08-04 22:56:08 +02:00
Victor Petukhov 00d1e46c5a [FE 1.0] Don't throw exception during substitution of accessors, just return original 2022-07-22 16:03:53 +00:00
Victor Petukhov 42e71f8c53 Remove explicit enabling the new type inference from test data 2022-07-22 16:03:52 +00:00