Commit Graph

336 Commits

Author SHA1 Message Date
Denis.Zharkov 9fa0f51a61 K2: Fix false-negative RETURN_TYPE_MISMATCH
^KT-53987 Fixed
^KT-55932 Fixed
2023-02-15 08:13:42 +00:00
Mikhail Glukhikh 5a9e8b3c0a FE: add tests for KT-53966 (positive/negative) 2023-02-08 17:40:20 +00:00
Dmitriy Novozhilov e9204521a9 [FIR] Properly create type ref for error type in various places 2023-02-06 08:09:56 +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
Mikhail Glukhikh aafde418cc K2: store imported static qualifiers in dispatch receiver field
This is a partial revert of commit 104fd4c1
#KT-55116 Fixed
2023-01-26 15:27:55 +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
pyos 9f17b5de97 FIR CFA: add edges according to constructor delegation 2023-01-26 13:12:11 +00:00
pyos 8aa50e9446 FIR CFA: add edges from maybe-throwing statements to catch/finally 2023-01-26 09:50:24 +00:00
Ilya Kirillov 6204e43f3f [FIR] fix resolve contract violation from FirTypeParameter.eraseToUpperBound
^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 5a08d8da8d FIR: don't check annotations on returnTypeRefs that are not of real kind
This fixes an exception in FirAnnotationChecker where we tried to report
repeated annotations on implicit type refs that have no source.
2023-01-13 12:54:18 +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 e86b87fe0b Test: FIR CFA: fix the names of some nodes 2023-01-10 15:40:52 +02:00
pyos 0dd949bb36 FIR DFA: route data flow through anonymous objects
^KT-44515 Fixed
2023-01-10 15:40:50 +02:00
pyos 17ee8f3a7b FIR CFA: put primary constructor before other class members 2023-01-10 15:40:50 +02:00
pyos c6e9afb788 FIR CFA: remove class initializer part nodes
Instead, attach subgraphs directly to the class enter node.
2023-01-10 15:40:50 +02:00
pyos 54f32a6fba Test: FIR CFA: index nodes in rendering order 2023-01-10 15:40:49 +02:00
pyos a9397b7b23 Test: FIR CFA: don't output two node fill colors 2023-01-10 15:40:49 +02:00
pyos 4bb7b1ac9f FIR DFA: use class enter node as data flow source for members
Also fix graphs for enums with specialized entries - since we don't
create property subgraphs for FirEnumEntry, there is no body to insert
AnonymousObjectEnterNode, AnonymousObjectExitNode, and
AnonymousObjectExpressionExitNode into.
2023-01-10 15:40:49 +02:00
pyos cb8cb1f610 FIR CFA: attach accessors and nested classes as class subgraphs 2023-01-10 15:40:48 +02:00
pyos 74758278d7 FIR CFA: attach method graphs to class exit node
Even for non-local classes. This ensures that the CFG edges in this case
will only go to a subgraph, not to an unrelated graph.
2023-01-10 15:40:48 +02:00
pyos aadea0e26f FIR CFA: properly visit subgraphs in checkers
Interpretation: a graph A is a subgraph of B if information available at
nodes of A depends on the paths taken in B. For example, local classes
are subgraphs of a graph in which they are declared, and members of
those classes are subgraphs of the local class itself - because these
members can reference captured values.

Consequences:

 * if graph G is a subgraph of node N, then G is a subgraph of N's
   owner;
 * `ControlFlowAnalysisDiagnosticComponent` will only visit root graphs;
 * `graph.traverse` will ignore subgraph boundaries, as if all subgraphs
   are inlined into one huge root graph;
 * if a control flow checker needs information from a declaration to
   which a graph is attached, it must look at subgraphs explicitly.

For example, consider the `callsInPlace` checker. When a function
has a `callsInPlace` contract and a local declaration, the checker must
visit that local declaration to ensure it does not capture the allegedly
called-in-place argument - hence `graph.traverse` will look at the
nodes. However, the local declaration can also be a function with its
own `callsInPlace` contracts, so the checker should also run for it in
isolation. If that sounds quadratic, that's because unfortunately it is.
2023-01-10 15:40:48 +02:00
pyos e7e5569539 FIR CFA: do not remove provideDelegate subgraphs when rolling back
The receiver of the provideDelegate call is the same FirExpression as
the delegate itself, so there's only one copy of the nodes in the first
place; trying to remove subgraphs completely detaches objects inside it
from the parent graph, which is not great for checkers.

Note that currently if provideDelegate is not selected, there will be a
stray FunctionCallExit node in the control flow graph. This commit *does
not change that*. It has been there for a while. Don't @ me. I'll try to
fix that. No promises.
2023-01-10 15:40:47 +02:00
pyos ef2fa01a8d FIR CFA: remove redundant "uncaught exception path" edges
These are not real, and in fact tricked the compiler into thinking some
blocks that do not terminate do somehow terminate.
2023-01-10 15:40:47 +02:00
pyos faf0129a5d Test: FIR CFA: sort edges by style & target node id 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
Mikhail Glukhikh 1344a9b1bb ConeTypeIntersector: preserve raw & dynamic types as is 2023-01-04 18:29:34 +00:00
Yan Zhulanow d652dc620c [FE] Preserve legacy contract description calls in bodies
^KT-55231 Fixed
^KTIJ-21012 Fixed
2022-12-26 11:46:58 +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
pyos 664a70ec13 FIR DFA: split flow for postponed lambdas from a single node
This removes the need for hacks around the order in which function
call arguments are visited, fixes called-in-place lambda arguments
for augmented assignment operators, and makes CFG dumps a bit prettier.
2022-12-08 10:19:34 +00:00
pyos d66be3f82d FIR CFG: do not assume all arguments to inline funs are called in place
Only values for non-noinline, non-crossinline, functional type
parameters qualify.
2022-12-08 10:19:32 +00:00
pyos c4c05f5248 FIR CFG: remove ordering from control flow through in-place lambdas
Old graph:

  arg -> lambda enter -> ... -> lambda exit -> lambda enter -> ... ->
   -> lambda exit -> call

New graph:

  arg -+-> lambda enter -> ... -> lambda exit -+-> call
       \-> lambda enter -> ... -> lambda exit -/
2022-12-08 10:19:31 +00:00
pyos 8a68eac5f1 FIR DFA: add a union node for property delegates
The delegate is resolved in context-dependent mode and thus can be an
incomplete call; if there is no `provideDelegate` method to complete it,
the result is effectively `val x$delegate = y.id()` where `id` is
`fun <T> id(x: T) = x`, except we don't get a real node for `id` so the
DFA edges from lambdas in `y` go who knows where.
2022-12-08 10:19:30 +00:00
pyos a9be27e330 FIR CFG: add union nodes
Quick quiz:

 Q: In a CFG, what does `a -> b -> c -> d` mean?
 A: `a`, then `b`, then `c`, then `d`.

 Q: In a CFG, what does `a -> b -> d; a -> c -> d` mean?
 A: `a`, then `b` or `c`, then `d`.

 Q: So how do you encode "a, then (b, then c) or (c, then b), then d`?
 A: You can't.

Problem is, you need to, because that's what `a; run2({ b }, { c }); d`
does when `run2` has a contract that it calls both its lambda arguments
in-place: `shuffle(listOf(block1, block2)).forEach { it() }` is a
perfectly valid implementation for it, as little sense as that makes.

So that's what union nodes solve. When a node implements
`UnionNodeMarker`, its inputs are interpreted as "all visited in some
order" instead of the normal "one of the inputs is visited".

Currently this is used for data flow. It *should* also be used for
control flow, but it isn't. But it should be. But that's not so easy.

BTW, `try` exit is NOT a union node; although lambdas in one branch can
be completed according to types' of lambdas in another, data does not
flow between the branches anyway (since we don't know how much of the
`try` executed before jumping into `catch`, and `catch`es are mutually
exclusive) so a `try` expression is more like `when` than a function
call with called-in-place-exactly-once arguments. The fact that
`exitTryExpression` used `processUnionOfArguments` in a weird way
should've hinted at that, but now we know for certain.
2022-12-08 10:19:29 +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
Steven Schäfer a7ba081d22 FIR: Fix interface delegation ABI
- Unifies the name of the `$$delegate_<n>` field between K1 and K2.
- Make the `$$delegate_<n>` field private
2022-12-02 21:54:18 +00:00
Vladislav Grechko cd6e865fb3 Improve support of 'lateinit' modifier
- Allow 'lateinit' for inline classes which underlying type
is suitable for 'lateinit'

- K2: report all problems related to 'lateinit' modifier

^KT-55052: Fixed
2022-11-24 19:47:21 +00:00
Dmitriy Novozhilov 1b42298025 [FIR] Implement IMPLICIT_NOTHING_*_TYPE diagnostics 2022-11-22 15:46:19 +00:00
pyos ea1caf0955 FIR DFA: do not generate nodes (and flows) for contracts on calls
The code was already duplicated between FirDataFlowAnalyzer and
FirReturnsImpliesAnalyzer, so might as well use the latter to slightly
speed up the former.
2022-11-22 15:44:37 +00:00
Nikolay Lunyak 267ce1d892 [FIR] KT-54220: Don't crash on unsigned integers when no stdlib present
^KT-54220 Fixed
2022-11-15 09:02:33 +02:00
Mikhail Glukhikh 4dc7b6dddc K2: fix/universalize logic to determine that member is from Java 2022-11-11 13:30:40 +00:00
Mikhail Glukhikh 104fd4c14d K2: don't use dispatch receiver to store imported static qualifiers
Related to KT-53441
2022-11-11 13:30:38 +00:00
Mikhail Glukhikh f070401bb5 K2: fix visibility checks for static overrides via imported from static
#KT-53441 In Progress
2022-11-11 13:30:35 +00:00
Mikhail Glukhikh 62ba1277bb K2: don't duplicate custom annotations in types #KT-54275 Fixed 2022-10-10 06:20:39 +00:00
Mikhail Glukhikh d491eba629 K2: add reproducer for KT-54275 2022-10-10 06:20:39 +00:00
Mikhail Glukhikh 85965d74f6 K2: fix implicit body resolve in case delegated property is on the path
#KT-54212 Fixed
2022-09-29 10:55:14 +02:00
Mikhail Glukhikh 75a29434bd K2: add reproducer of KT-54212 2022-09-29 10:55:04 +02:00