Commit Graph

167 Commits

Author SHA1 Message Date
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
Dmitriy Novozhilov 89c42e20c9 [FIR] Consistently use _function_ instead of _functional_ in names of classes and functions 2023-02-02 08:24:52 +00:00
Dmitriy Novozhilov d1b797ed97 [FIR] Generify resolution and inference of arguments of functional types 2023-02-02 08:24:50 +00:00
Dmitriy Novozhilov 6a343e7bff [FIR] Resolve forks in constraint system after analysis of postponed lambda
When constraint system has forks in it usually we solve all of them before
  starting full completion of corresponding call. But if some call with
  forks was a last statement of postponed lambda, we will never call
  completion for it with FULL mode. Instead of it we complete it in PARTIAL
  mode and then just merge its constraint storage into storage of outer
  call. So all forks from this inner call just remain unresolved inside
  outer system without this fix

^KT-55966 Fixed
2023-02-01 15:02:02 +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
Mikhail Glukhikh 29ad5f981c Extract EmptyIntersectionTypeKind.isDefinitelyEmpty to a property 2022-12-09 15:00:41 +00:00
Dmitriy Novozhilov f3da26946b [FIR] Change priority of K2_VISIBILITY_ERROR CandidateApplicability
In K1 analogue of `K2_VISIBILITY_ERROR` is `K1_RUNTIME_ERROR`, so
  candidates with `K2_VISIBILITY_ERROR` should win over innaplicable
  candidates with `INAPPLICABLE`, `INAPPLICABLE_ARGUMENTS_MAPPING_ERROR`
  or `INAPPLICABLE_WRONG_RECEIVER` applicability

This is needed to allow resolution to invisible symbols (and later
  suppress error with `@Suppress("INVISIBLE_SYMBOL", "INVISIBLE_REFERENCE")`

^KT-55026 Fixed
^KT-55234
2022-12-09 12:02:05 +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
Nikolay Lunyak 7147b7d17b [FIR] KT-55033: Split runTransaction into smaller functions
^KT-55033 Fixed

Merge-request: KT-MR-7779
Merged-by: Nikolay Lunyak <Nikolay.Lunyak@jetbrains.com>
2022-11-25 09:12:15 +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 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 c958c79362 Minor cleanup at ConstraintInjector.kt 2022-11-24 17:29:29 +00:00
Denis.Zharkov 02b2927921 Clarify naming around inference fork points
^KT-43296 In Progress
2022-11-24 17:29:28 +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
Jinseong Jeon c79d65536b Gracefully handle erroneous super type during local type approximation
^KTIJ-23528 Fixed
2022-11-22 20:16:40 +01:00
Dmitriy Novozhilov 32f6b71525 [FE] Add ability to configure PublicDeclaration type approximation configuration
This configuration allows to choose what to do with local and anonymous types
2022-11-22 15:46:18 +00:00
Dmitriy Novozhilov d39c019051 [FE] Add toString to NewConstraintError 2022-10-19 11:09:30 +00:00
Dmitriy Novozhilov d423782fac [FE 1.0] Remove usages of safeAs and cast from most of FE 1.0 modules:
- :core:descriptors
- :core:descriptors.jvm
- :core:deserialization
- :compiler:cli
- :compiler:frontend
- :compiler:frontend:cfg
- :compiler:frontend.java
- :compiler:frontend.common.jvm
- :compiler:psi
- :compiler:resolution
- :compiler:resolution.common
- :compiler:resolution.common.jvm
- :kotlin-reflect-api
2022-10-12 13:58:56 +00:00
Mikhail Glukhikh e9bb0f4fda Resolution: extract projections from captured flexible type properly
#KT-54100 Fixed
Related to KT-54196, KT-54198
2022-09-28 15:29:43 +00:00
Mikhail Glukhikh ed21011183 NewConstraintSystemImpl: remove redundant suppressions 2022-09-19 19:12:20 +00:00
Mikhail Glukhikh 3e58c54da9 Add docs to CandidateApplicability, remove DSL_SCOPE_VIOLATION 2022-07-27 15:29:48 +00:00
Mikhail Glukhikh d0c518013a Document&use CandidateApplicability.shouldStopResolve/isSuccess properly 2022-07-27 15:29:47 +00:00
Mikhail Glukhikh 0611f3b8e7 CandidateApplicability: add K1/K2 prefixes when applicable 2022-07-27 15:29:44 +00:00
Mikhail Glukhikh 8e9e8302f7 CandidateApplicability: merge INAPPLICABLE_MODIFIER into CONVENTION_ERROR 2022-07-27 15:29:43 +00:00
Mikhail Glukhikh 32a73968de Stop tower resolve in K2 in more similar manner with K1 2022-07-27 15:29:41 +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
Victor Petukhov 867ad24c86 [FE] Show causing types in the INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION diagnostic 2022-05-27 15:14:24 +00:00
Victor Petukhov 6a34b184ac [FE] Introduce warnings on possible empty intersection types, and improve errors reporting in general
^KT-52361 Fixed
2022-05-27 15:14:23 +00:00
Victor Petukhov e133ee3765 [FE] Cache checking intersection type emptiness results 2022-05-27 15:14:23 +00:00
Victor Petukhov 02a430875f [FE 1.0] Don't fail candidates which were marked with compatibility resolve previously
^KT-52431 Fixed
^KT-52393 Fixed
2022-05-27 15:14:22 +00:00
Victor Petukhov c25e07119c [FE 1.0] Skip improper constraints while determining READY_FOR_FIXATION_DECLARED_UPPER_BOUND_WITH_SELF_TYPES type variable readiness
^KT-51148 Fixed
2022-05-27 13:56:32 +00:00
Dmitriy Novozhilov de842817e8 [FE] Move ExpectActualCompatibility to :core:compiler.common module 2022-05-20 13:33:03 +00:00
Denis.Zharkov c018270462 Support DNN types in approximator
Mostly, it's relevant to FIR since there we started loading
type parameter based types as (T & Any..T?)
2022-05-19 16:54:06 +00:00
Denis.Zharkov f70ae2df3a FIR: Refine inference constraints when type variable in flexible position
That issue might be fixed via changing
TypeVariableMarker.shouldBeFlexible at ConeConstraintSystemUtilContext
but this and some other tricks have been added because of incorrect
handling of constraints where type variable has a flexible bound

^KT-51168 Fixed
2022-05-19 16:53:59 +00:00
Victor Petukhov 6027c2a9aa [FE] Substitute fixed type variables with inferred stub types
Actually, a type variable might be fixed into a stub type. Such stub type should be substituted before sub calls completion

^KT-51988 Fixed
2022-05-09 12:38:37 +00:00
Victor Petukhov e0a1f1c405 [FE] Review fixes 2022-04-27 19:50:24 +00:00
Victor Petukhov 47d6236a2d [FIR] Support determining emptiness of an intersection type with type parameters' types 2022-04-27 19:50:23 +00:00
Victor Petukhov 5bfe6cd20a [FE] Implement discussed rules to report empty intersection errors 2022-04-27 19:50:22 +00:00
Victor Petukhov b96708c3e2 [FE] Support reporting INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION for empty intersection types with type parameters 2022-04-27 19:50:21 +00:00
Victor Petukhov 9e9e0211eb [FE] Check if type variable is fixed into an empty intersection type and report resolution warnings/errors if needed (completion stage)
^KT-51221 Fixed
2022-04-27 19:50:18 +00:00
Victor Petukhov b5933c70e2 [FE 1.0] Refactor error utils: split error entities and introduce error type and error scope kinds 2022-03-23 21:13:33 +00:00
Simon Ogorodnik 7fa13f758f Make constraint system fail hard on registering existing variable 2022-03-18 12:14:00 +00:00
Victor Petukhov fd6500c167 [FE 1.0] Set a fixation priority for self type variables less than any of ready for fixation kinds
^KT-51040 Fixed
^KT-49838
2022-02-14 15:43:53 +03:00
Ivan Kochurkin 635166c969 [FIR] Get rid of excess allocations in FlatSignature 2022-02-07 17:22:00 +03:00
Dmitriy Novozhilov 52b72a7dac [FIR] Implement Int -> Long conversions for literals and operators over them
^KT-38895
^KT-50996 Fixed
^KT-51000 Fixed
^KT-51003 Fixed
^KT-51018 Fixed
2022-02-07 13:36:36 +03:00
Simon Ogorodnik 83ff0946fe Inference. Remove chain inference stubs from fixed variables constraints 2022-01-22 09:02:02 +03:00
Mikhail Glukhikh e8be9d4861 FIR: support don't use builder inference if possible
In this commit we upgrade FIR builder inference logic from
the compiler version to 1.7. FIR-based compiler now works with
"don't use builder inference" flag always ON and supports switching
the flag "use builder inference only if needed". To do it,
ContraintSystemCompleter (FIR) and KotlinConstraintSystemCompleter (FE 1.0)
are made similar with extracting some common parts into
ConstraintSystemCompletionContext.

Test status: one BB test fails after this commit (KT-49285).
Also we have a crush in DFA logic in FIR bootstrap test and somehow
questionable behavior in FIR diagnostic test. However,
two BB tests were fixed, the 3rd case from KT-49925 were also fixed.

#KT-49925 Fixed
2022-01-20 23:46:36 +03:00
Dmitriy Novozhilov fbab32c4dd [FIR] Remove redundant nullability from findFunctionalTypesInConstraints return type 2022-01-20 11:25:46 +03:00
Pavel Kirpichenkov b4c854429f [MPP] Permit const actual properties for non-const expects
It's safe as not having const is more restrictive, therefore can be
allowed in common. Otherwise, it's not possible to declare an expect
declaration for a platform property with `const` modifier in common

KT-18856
2022-01-19 13:22:47 +03:00
Denis.Zharkov a33d9df0cd NI: Support forking inference with heuristics
Mostly, it only affects FIR

It partially allows to consider several variance of constraints like
A<Int> & A<T> <: A<X_var> that are mostly brought by smart casts

^KT-49542 Fixed
^KT-50489 Relates
2022-01-11 20:45:55 +03:00