Commit Graph

118 Commits

Author SHA1 Message Date
Evgeniy.Zhelenskiy 7eab4b672d [K1, K2, CLI] Mark whole position range of compiler diagnostics in CLI
#KT-64989
2024-02-08 12:59:31 +00:00
Denis.Zharkov 5db1bb921b Temporary comment out some parts of a slow diagnostic test
K2 version runs like for 15s.

It became slow after PCLA (KT-59791) was implemented,
and the reasons for that is the presence of a lot of interconnected TV
which leads to O(NUMBER_OF_CONSTRAINTS*NUMBER_OF_VARIABLES)
asymptotic during constraint incorporation.

The test itself in any way doesn't represent some common BI use case,
so it seems reasonable to mute it temporary.

^KT-65005 Related
2024-01-25 11:11:36 +00:00
Denis.Zharkov 72b0372927 K2: Allow PCLA inference when a value parameter has a TV type
^KT-64877 Fixed
2024-01-11 10:32:12 +00:00
Denis.Zharkov b2ca19da73 K2: Adjust test data after correcting source for it
While reporting a diagnostic there seems to be correct because the
parameter type is ConeErrorType, the former fact is a bug
in PCLA that should be fixed soon
2024-01-11 10:32:12 +00:00
Denis.Zharkov e359db4111 K2: Set proper source for implicit it/receiver parameter
Previously, error types on those implicit parameters were being lost.

Changed test data is only partly here
(only parts that are considered to be correct).

Other ones (new green-to-red changes) should belong to the next commit
and will be fixed soon (as a part of PCLA).
2024-01-11 10:32:12 +00:00
Denis.Zharkov 7e4d9d9f64 K2: Add new tests for PCLA implementation
Many of them have been found & minimized at FP tests/user projects

^KT-59791 Fixed
2024-01-10 14:56:31 +00:00
Denis.Zharkov 90feeab076 K2: Temporary mute controversial K2 IDE test after PCLA implementation
^KT-59791 In Progress
2024-01-10 14:56:30 +00:00
Denis.Zharkov 8365eb54dd K2: Adjust test data after PCLA implementation [multiLambdaRestriction]
^KT-59791 In Progress
2024-01-10 14:56:30 +00:00
Denis.Zharkov b9019d3de1 K2: Adjust test data after PCLA implementation [red-to-green]
^KT-59791 In Progress
2024-01-10 14:56:30 +00:00
Denis.Zharkov 8459465177 K2: Adjust test data after PCLA implementation [green-to-red, controversial]
^KT-59791 In Progress
2024-01-10 14:56:30 +00:00
Denis.Zharkov 6052e24626 K2: Adjust test data after PCLA implementation [red-to-red]
^KT-59791 In Progress
2024-01-10 14:56:30 +00:00
Mikhail Glukhikh 8a560d2629 FE tests: don't render text of disabled diagnostics 2024-01-05 17:20:32 +00:00
Simon Ogorodnik c2ddbfc93b K2: Fix false-positive error with captured types in builder inference
Error arises from the fact that type substitution operation isn't
consistent when applied to captured types.

E.g.:
```
substitution = { A => B }
substituteOrSelf(C<CapturedType(out A)_0>) -> C<CapturedType(out B)_1>
substituteOrSelf(C<CapturedType(out A)_0>) -> C<CapturedType(out B)_2>
C<CapturedType(out B)_1> <!:> C<CapturedType(out B)_2>
```

Relates to KT-53749
2023-12-04 15:27:21 +00:00
Simon Ogorodnik d46075a9db K2: Use correct position for substitution constrains in builder inference
Before, we were wrapping the original constraint position into
ConeBuilderInferenceSubstitutionConstraintPosition twice during the
constraint substitution in builder inference.

It was causing problems with diagnostic reporting.

Remove TODOs about diagnostic reporting from FirBuilderInferenceSession.
Propagation of errors from the common system is now implemented
Diagnostic reporting in updateCalls isn't needed, since we
report errors after the system completion unlike K1

Relates to KT-53749
2023-12-04 15:27:21 +00:00
Simon Ogorodnik 2f367b013a K2: Don't lose constraint errors in the builder inference session
Pass constraint errors from the integration system into a candidate to
make sure it is reported later.

Related to KT-59426, KT-59437, KT-53749
#KT-55168 Submitted
2023-12-04 15:27:20 +00:00
Simon Ogorodnik cb3d65f669 [Test] Add test for KT-63996
False-positive TYPE_MISMATCH in builder inference with captured types
2023-12-04 15:27:20 +00:00
Mikhail Glukhikh 526bc1744a K2: implement BUILDER_INFERENCE_MULTI_LAMBDA_RESTRICTION
#KT-59390 Fixed
2023-12-01 10:54:29 +00:00
Simon Ogorodnik 299d279915 K2: Don't report BUILDER_INFERENCE_STUB_RECEIVER for members of Any
This commit actually does two things:
- Adds Any scope to stub type
- Makes CheckDispatchReceiver treat stub types
as non-null for the unsafe call check to make such candidates viable

Related to KT-59369
2023-12-01 10:54:29 +00:00
Mikhail Glukhikh 0ed6256bcc K2: implement BUILDER_INFERENCE_STUB_RECEIVER
#KT-59369 Fixed
2023-12-01 10:54:29 +00:00
Kirill Rakhman fbf68a5bcc [FIR] Narrow down range of NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER
This uses the same approach as
INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION where we use a visitor
to find a call to a symbol that contains the type variable in question.

#KT-56140 Fixed
2023-09-22 13:49:59 +00:00
Kirill Rakhman d0cc86f52c [Tests] Update test data after changes to FIR diagnostic messages 2023-08-21 16:28:48 +00:00
Kirill Rakhman 724d527fd8 [FIR] Fixes for call conflict resolution
Let ConeCompositeConflictResolver pass the results of the previous
resolver to the next one.
Otherwise, we get false positive conflicts when a set of candidates
can't be fully reduced by one resolver but could be resolved by the
subsequent application of multiple ones.
This change makes ConeCompositeConflictResolver order-dependent and
thus, ConeOverloadConflictResolver must be invoked last, because it
must work on a pre-filtered list.

Also, let ConeEquivalentCallConflictResolver use
FirStandardOverrideChecker instead of compareCallsByUsedArguments
because it's stricter.

This all fixes a false positive overload resolution ambiguity in common
metadata compilation that is caused by stdlib using the new KMP
format.
Now stdlib metadata is in the classpath, and so declarations from the
stdlib are returned from both MetadataSymbolProvider and
KlibBasedSymbolProvider.
This isn't a problem per se because duplicate candidates are filtered
out by ConeEquivalentCallConflictResolver (K1 works analogously), but
in the case of top-level functions with generic receivers like
Collection<T>.toTypedArray, the check failed because of the direct
comparison of receiver types.

#KT-60943 Fixed
2023-08-11 10:54:24 +00:00
Nikolay Lunyak d13e60aaec [FIR] Prevent loosing errors for synthetic outer calls
The error occurs when completing the
call for the outer synthetic call
`ACCEPT_SPECIFIC_TYPE`. The error
is saved into the CS of this outer
candidate, which leads to its
callable reference to be an error
reference, but since such calls are
not parts of the FIR tree, we never
collect such errors.

^Fixed KT-59233
2023-07-10 10:26:43 +00:00
Brian Norman 48484368c7 [Test] Support RENDER_DIAGNOSTICS_FULL_TEXT directive for FIR tests 2023-06-06 15:42:21 +00:00
Simon Ogorodnik 3e6b42083b FIR: Fix leakage of type variables in builder inference for lambdas returning Unit
When BI/incomplete call is present in return argument, it will be
added to the main call-tree, leading to requirement violation in
`ConstraintSystemCompleter.getOrderedAllTypeVariables`
as after `FirBuilderInferenceSession.inferPostponedVariables` it will
be completed, and its type variables couldn't be found anymore

In K1, we actually do the same, but we are able to find type variables
of such calls due to architecture difference:
In K2, `getOrderedAllTypeVariables` uses FIR as the main source to
lookup
In K1, `getOrderedAllTypeVariables` uses resolution atom tree, where
candidate/CS of the call is still available after
`inferPostponedVariables`

In fact, all incomplete calls were analyzed in FULL mode according to
the contract of `FirBuilderInferenceSession.addPartiallyResolvedCall`.
Thus, it means we normally shouldn't add them to the main call-tree, but
accidentally do it as incomplete calls contain non-completed candidate

This particular commit addresses the problem partially, only
in cases when the expected return type for the lambda is Unit and when
the incomplete call is located in the last expression of the lambda

In such cases, we can skip the call from the last expression completely,
since all potential calls there were analyzed in FULL mode,
and couldn't introduce any useful info to the CS of the main call-tree

^KT-54294
2023-05-17 10:50:36 +00:00
Kirill Rakhman b2fa104081 [FIR] Keep all failed resolution candidates and fully resolve them
Previously, when a candidate was found with an applicability that is
better than the current best applicability, all previous candidates were
thrown away. Now we keep them, unless the new applicability is
successful. If no successful candidates are found, we fully resolve all
the unsuccessful ones and select the ones with the least bad
applicability. This improves diagnostics for unresolved calls.

#KT-57844 Fixed
2023-05-10 11:48:58 +00:00
Denis.Zharkov 7b46c59d57 K2: Complete property-candidate before starting invoke resolution
Before this commit, for property candidates in K2 their types wasn't
inferred/susbtituted properly.

So, when candidate for fooBar.liveLoaded.invoke() was created,
the type of `fooBar.liveLoaded` was just X type parameter for which
there is no any `bar()` functions in its member scope.

While proposed semantics is a bit different from K1, where
both property and invoke candidates are united into common system,
it doesn't contradict to the specification (https://kotlinlang.org/spec/overload-resolution.html#callables-and-invoke-convention)
which says explicitly that invoke-convention should be desugared as
`r.foo.invoke()`, thus `r.foo` should be completed independently.

Also, this strategy supports some reasonable use-cases like KT-58259
while it's still a breaking change but for more artificial-looking
situations (see KT-58260) and should be passed through
the language committee.

The changes in stubTypeReceiverRestriction* tests looks consistent
because of how `genericLambda` now works
(with full completion of property call).
NB: The code is going to be red once KT-54667 is fixed and also there's
already similar diagnostic in K1 (INFERRED_INTO_DECLARED_UPPER_BOUNDS)

^KT-58142 Fixed
^KT-58259 Fixed
^KT-58260 Related
2023-04-28 12:46:20 +00:00
Nikolay Lunyak 8d04ab3142 [FIR] Ignore nullability in the definition of "identity-less"
The definition of a "builtin" already
ignores nullability.

`Int? === String?` must trigger a
diagnostic by design.
2023-04-19 16:05:19 +00:00
Nikolay Lunyak f0720c1d12 [FIR] Fix K2 behavior according to RULES1
The compiler should only report diagnostics for
comparisons over builtins and identity-less types,
other incompatibilities should be reported
via inspections.

It's ok that in `equalityChecksOnIntegerTypes`
instead of `EQUALITY_NOT_APPLICABLE_WARNING` we get
`EQUALITY_NOT_APPLICABLE`, because
`ProperEqualityChecksInBuilderInferenceCalls`
is already active by default.

This change also replaces the notion of a representative superclass
with the least upper bound.
This makes complex types like
intersection/flexible transparent to
RULES1-based compatibility checks.
One way to look at it is to think
that this is an automatic way of handling
type parameters: automatic picking of
"interesting" bounds, and checking them against one another.

Note that `TypeIntersector.intersectTypes`
for `Int` and `T` where `T` is a type parameter
may return both `{Int & T}` or `null`
depending on `T`-s bounds. At the same time,
for type parameters `T` and `K` it will
always return `{T & K}`.

`ConeTypeIntersector.intersectTypes`, on the
other hand, will always return `{Int & T}`
irrespectively of the bounds. Meaning, the two
intersectors differ in corner cases.

`lowerBoundIfFlexible` call in `isLiterallyTypeParameter` is backed by
the `equalityOfFlexibleTypeParameters` test.

^KT-35134 #fixed-in-k2
^KT-22499 #fixed-in-k2
^KT-46383 #fixed-in-k2
2023-03-31 15:01:50 +00:00
Mikhail Glukhikh a43a16b25b Delay ForbidInferringPostponedTypeVariableIntoDeclaredUpperBound to 2.0
#KT-57395 Fixed
Related to KT-47986
2023-03-20 11:11:41 +00:00
Nikolay Lunyak bcfafc601e Add EnumEntries to minimal-stdlib-for-tests
This change allows to revert adding `WITH_STDLIB` directive
to tests which happened at `a9343aeb`.

Co-authored-by: Alexander Udalov <Alexander.Udalov@jetbrains.com>
2023-03-02 10:23:38 +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
Dmitriy Novozhilov 88efa6bfb6 Update tests after switching to LV 1.9 2023-01-30 09:29:57 +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
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
Ilya Kirillov 644d1bf0d0 [FIR] ignore tests which fail because of resolve contracts violation 2022-12-12 16:21:07 +00:00
Dmitriy Novozhilov 1b27d60307 [FIR] Support @OnlyInputTypes annotation
^KT-54807 Fixed
2022-11-22 15:46:17 +00:00
Dmitriy Novozhilov 22c21ca4df [FIR] Replace uninferred type variables and stub types during delegate inference 2022-11-03 08:30:07 +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
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
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 3ed87c29c7 [FE 1.0] Substituted possible fixed type variables after completion in accordance with @OverloadResolutionByLambdaReturnType
^KT-48031 Fixed
2022-07-04 12:05:57 +00:00
Victor Petukhov 9e8ef56cca [FE 1.0] Imitate having builder inference annotation while trying resolve with a builder inference
^KT-52892 Fixed
2022-06-21 15:02:31 +02:00
Victor Petukhov fa7809cd80 [FE] Remove BuilderInference annotation from tests 2022-06-21 15:01:56 +02:00
Ivan Kochurkin fd2b4fd497 [FIR] Fix false positive USELESS_CAST on stub types, ^KT-50293 Fixed 2022-06-17 23:26:18 +00:00
Victor Petukhov b472ccd358 [FE 1.0] Introduce deprecation of inferred type variable into a declared upper bound within a builder inference call 2022-05-31 14:13:29 +00:00