Commit Graph

363 Commits

Author SHA1 Message Date
Kirill Rakhman 251827c9aa [FIR] Don't approximate captured types
This fixes some type argument mismatch errors caused by a captured type
being approximated and then captured again.
Some places need to be adapted to work with captured types that
previously only worked with approximated types.

#KT-62959 Fixed
2024-01-17 08:20:05 +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
Kirill Rakhman 9ea4afe7c8 [FIR] Fix isValidTypeParameterFromOuterDeclaration check for local class
This fixes an IllegalArgumentException when
symbolProvider.getClassLikeSymbolByClassId is called with a local
class ID.

#KT-63656 Fixed
2023-11-23 14:24:47 +00:00
Evgeniy.Zhelenskiy 9383d0bfa4 [FIR] Check type arguments in inner/outer local classes as in K1
^KT-59922 ^KT-59951
2023-11-20 20:04:45 +00:00
Ilya Chernikov 1ad4f19181 Fix default positioning strategy handling
that causes flaky tests because the default positioning strategy
was dependent on the order of the reported messages.
The code led to it was introduced in an attempt to extract common
PSI-independent strategy because PSI is leaking into the abstract
diagnostic infrastructure. The approach is definitely problematic,
but to fix it now, the leaking dependency to the psi-based module
is introduced. This should be fixed in the future by introducing
better abstractions.
Fixes flaky tests touched in the commit.
#KT-63002 fixed
2023-11-06 21:21:16 +00:00
Dmitriy Novozhilov e473b52da7 [Test] Add additional test for KT-21463 2023-11-01 17:39:33 +00:00
Ilya Chernikov 1d461684ae LT: make where clause with errors parsing same as with PSI
- do not fail on the missing terms
- propagate invalid name to avoid reporting dangling constraints

#KT-58455 fixed
2023-10-27 18:22:28 +00:00
Nikolay Lunyak a68a2409d3 [FIR] Remove the applicability filtering when reporting diagnostics
In case we don't want to introduce any new
abstractions like "user relevance for
applicability", we can just remove the
filtering.

^KT-62541 Fixed
2023-10-19 09:27:45 +00:00
Ivan Kochurkin 319fb967ec [FIR] Add TYPE_ARGUMENTS_FOR_OUTER_CLASS_WHEN_NESTED_REFERENCED diagnostics
Report TYPE_ARGUMENTS_FOR_OUTER_CLASS_WHEN_NESTED_REFERENCED instead of
WRONG_NUMBER_OF_TYPE_ARGUMENTS where it's appropriate

^KT-59393 Fixed

Simplify FirTypeResolverImpl
2023-10-03 19:49:56 +00:00
Ivan Kochurkin 8d27af5b0d [FIR] Fix reporting of TYPE_ARGUMENTS_NOT_ALLOWED instead of WRONG_NUMBER_OF_TYPE_ARGUMENTS 2023-10-03 19:49:56 +00:00
Ivan Kochurkin 42e5e43302 [FIR] Refactor FirTypeResolverImpl.resolveUserType
Fix IndexOutOfBoundsException on an attempt to cast an element

to inner class with type parameter

^KT-60921 Fixed
2023-10-03 19:49:56 +00:00
Ivan Kochurkin 4b9e15dfa8 [FIR] Fix missing RETURN_TYPE_MISMATCH for labeled return statements
in lambda functions, ^KT-59907 Fixed

(cherry picked from commit 8e72f60996)
2023-09-21 12:52:31 +00:00
Ivan Kochurkin 063835488f Revert "[FIR] Fix missing RETURN_TYPE_MISMATCH for labeled return statements"
This reverts commit 8e72f60996

Since some intellij tests are failing
2023-09-20 12:29:41 +02:00
Ivan Kochurkin 8e72f60996 [FIR] Fix missing RETURN_TYPE_MISMATCH for labeled return statements
in lambda functions, ^KT-59907 Fixed
2023-09-20 09:06:37 +00:00
Kirill Rakhman 36c0c2c76b [FIR] Fix false negative TYPE_PARAMETER_AS_REIFIED_ARRAY
... in presence of typealiases.

#KT-61921
2023-09-18 12:13:02 +00:00
Kirill Rakhman b41e5abcfa [FIR] Fix bounds check for inner classes of generic outer classes
#KT-61068 Fixed
#KT-35566
2023-09-06 15:15:07 +00:00
Kirill Rakhman 10f7989af6 [FIR] Report UNRESOLVED_REFERENCE on the first unresolved qualifier
#KT-55471 Fixed
2023-09-04 08:05:07 +00:00
Brian Norman e8b4550173 [FIR] Add checker for finite bounds validation
Added a new FIR based checker for both FINITE_BOUNDS_VIOLATION and
FINITE_BOUNDS_VIOLATION_IN_JAVA errors. Implementation copied from the
existing descriptor based checker with some minor changes.

#KT-59378 Fixed
2023-08-11 21:13:58 +00:00
Nikolay Lunyak a41273b966 [FIR] Properly add the outer type parameters
Looks like a type.

^KT-59393 Fixed
(because other differences are related to
nested typealiases)
2023-08-04 11:20:39 +00:00
Nikolay Lunyak 4bba93f633 [FIR] Implement PROTECTED_CONSTRUCTOR_NOT_IN_SUPER_CALL
^KT-59382 Fixed
2023-08-04 11:20:39 +00:00
Brian Norman e10a9263d0 [FIR] Only inherit class type parameters if inner class
Nested classes which are not inner class should not be able to access
type parameters of the outer class. Make sure access is not available
when resolving super types.

#KT-54748 Fixed
2023-05-31 16:25:51 +00:00
Dmitrii Gridin 72def186a3 [LL FIR] rework transformers, so transformers resolve only a specific set of declarations
The change is needed for the parallel resolution (^KT-55750), so we can resolve the declaration
under a lock that is specific to this declaration.
Previously, if LL FIR was resolving some FirClass, LL FIR  resolved all its children too, and it had no control over what parts of the FIR tree were modified.
The same applied to the designation path, sometimes the classes on the designation path
might be unexpectedly (and without lock) modified.

This commit introduces LLFirResolveTarget, which specifies which exact declarations should be resolved during the lazy resolution of the declaration.
All elements outside the declarations specified for resolve in LLFirResolveTarget, should not be modified.

The logic of lazy transformers is the following:
- Go to target declaration collecting all scopes from the file and containing classes
- Resolve only declarations that are specified by the LLFirResolveTarget, performing the resolve under a separate lock for each declaration

^KT-56543
^KT-57619 Fixed
2023-04-19 20:12:38 +00:00
Denis.Zharkov 55a58e54fe K2: Rework scopes for types with projection arguments for Out types
The only case when behavior is change is described at
 computeNonTrivialTypeArgumentForScopeSubstitutor

The idea is to avoid depending on the presence of @UnsafeVariance
and instead approximate captured types in covariant argument positions
before building substitution scopes

It's correct because for Captured(*) <: Supertype,
Out<Captured(*)> <: Out<Supertype> and when we've got @UnsafeVariance
value parameters at Out, it's ok to allow passing Supertype there.

^KT-57602 Fixed
^KT-54894 Fixed
2023-03-29 10:45:40 +00:00
Denis.Zharkov d9ca77f716 K2: Fix false-positive RETURN_TYPE_MISMATCH_ON_OVERRIDE
The reason was that `substitutorByMap` ignored the difference between
`T` and `T?`

^KT-57001 Fixed
2023-03-29 10:27:49 +00:00
Kirill Rakhman 1f0d56e157 [FIR] Make type parameters inaccessible for non-inner nested types
#KT-57209
2023-03-28 13:20:53 +00:00
Dmitrii Gridin 9a4a3d1f49 [LL FIR] introduce test with reversed resolve order
^KT-56543

Merge-request: KT-MR-9299
Merged-by: Dmitrii Gridin <dmitry.gridin@jetbrains.com>
2023-03-22 17:34:07 +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 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
Dmitriy Novozhilov aef9b129d2 [FIR] Add regression tests for number of issues fixed in K2
List of issues:
KT-4113,  KT-6822,  KT-7389,  KT-17817, KT-20223
KT-21463, KT-24503, KT-24737, KT-24779, KT-24901
KT-27261, KT-28668, KT-30497, KT-30756, KT-36958
KT-37365, KT-37490, KT-38288, KT-41038, KT-41721
KT-42136, KT-42169, KT-42449, KT-42715, KT-43553
KT-43603, KT-43846, KT-43936, KT-46288, KT-46301
KT-47373, KT-47484, KT-47490, KT-47495, KT-47750
KT-47815, KT-47870, KT-48975, KT-49024, KT-49045
KT-50134, KT-50160, KT-50550, KT-51045, KT-51143
KT-51796, KT-52262, KT-52424, KT-52860, KT-52934
KT-53086, KT-53494, KT-53671, KT-53752, KT-53819
KT-54478, KT-54518, KT-54931, KT-54990, KT-55138
KT-55379, KT-55555, KT-56243
2023-02-14 17:08:55 +00:00
Mikhail Glukhikh 1d309cbbb2 Fix test data accidentally broken in cab03404 (commit clash) 2023-02-01 10:18:19 +01: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
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 eb8ce449e3 [FIR] Don't lose flexible types during capturing from expression 2022-11-22 15:46:22 +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
Mikhail Glukhikh d8522a8967 FE: Add test for KT-53656 2022-09-06 17:57:02 +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 42e71f8c53 Remove explicit enabling the new type inference from test data 2022-07-22 16:03:52 +00:00
Ivan Kochurkin 81b1ed9ad4 [FIR] Fix false positive RETURN_TYPE_MISMATCH in intellij ultimate 2022-04-07 21:03:08 +03:00
Ivan Kochurkin c6f52893fb [FIR] Fix inconsistent RETURN_TYPE_MISMATCH and TYPE_MISMATCH reporting on functions and properties
^KT-51203 Fixed
2022-04-05 15:50:43 +00:00
Victor Petukhov 27fa632630 [FE 1.0] Update test data with new error type representation 2022-03-23 21:13:33 +00:00
Mikhail Glukhikh ebed224f82 FE 1.0: use TYPE_VARIANCE_CONFLICT deprecation factory 2022-03-03 12:57:04 +00:00
Mikhail Glukhikh 53d6ac24e5 Switch kotlin version to 1.7
* Change 1.6 to 1.7 constants
* Fix SAFE_CALL_WILL_CHANGE_NULLABILITY for testData
* Change EXPOSED_PROPERTY_TYPE_IN_CONSTRUCTOR_WARNING to EXPOSED_PROPERTY_TYPE_IN_CONSTRUCTOR_ERROR
* Change NON_EXHAUSTIVE_WHEN_STATEMENT to NO_ELSE_IN_WHEN
* Fix testData for SafeCallsAreAlwaysNullable
* Change T -> T & Any in test dumps
* Change INVALID_CHARACTERS_NATIVE_WARNING -> INVALID_CHARACTERS_NATIVE_ERROR
* TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM_WARNING -> TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM_ERROR
2022-02-25 11:46:27 +00:00
Vladimir Dolzhenko 918a91dbdf Escape special names with backticks in test data
#KT-51248
2022-02-10 21:20:47 +00:00
Ivan Kochurkin 3beb447e85 [FIR] Consider anonymous object declarations in classDeclarationsStack in transformers 2021-11-24 23:13:38 +03:00
Ivan Kylchik c7435ba760 Replace all occurrences of WITH_RUNTIME with WITH_STDLIB
We are going to deprecate `WITH_RUNTIME` directive. The main reason
behind this change is that `WITH_STDLIB` directive better describes
its meaning, specifically it will add kotlin stdlib to test's classpath.
2021-11-17 15:26:38 +03:00
Ivan Kochurkin f05436b939 [FIR] Fix false positive case of CANNOT_CHECK_FOR_ERASED
Restore CANNOT_CHECK_FOR_ERASED as error
2021-11-16 18:15:49 +03:00
Ivan Kochurkin 15c83abfd8 [FIR] Throw UNCHECKED_CAST instead of NO_TYPE_ARGUMENTS_ON_RHS closer to FE 1.0 2021-11-12 15:20:48 +03:00
Ivan Kochurkin d0a4ca199d [FIR] Add UNCHECKED_CAST
Regenerate diagnostics code
2021-11-12 15:20:45 +03:00