Commit Graph

404 Commits

Author SHA1 Message Date
Denis.Zharkov a4c5e1bc87 K2: Unwrap fake overrides before using them as DFA identifiers
It's necessary because even for stable a.b.c.d we can't guarantee that
this reference will always point to the same symbol because
different capture type instantiations generate different scopes
with different resulting symbol instances.
2023-02-15 08:13:53 +00:00
Denis.Zharkov 2b3f34cc52 K2: Fix false-positive type equality for different captured types
This is mostly a revert of 2f61a2f56f
There, we erroneously assumed that we may take captured types as equal
if they are based on the same-typed projections.

Each instance of capturing defines its own captured type,
that should not be equal to any other type captured in other place.

Initial motivation was brought by FP Ultimate, where a piece of code
from the new test was found that started working differently after
recent changes.

The most obvious consequence is the change in addAllProjection.fir.kt:
one cannot use an instance as an argument when expected type
is captured type based on the same instance.

Otherwise, it would lead to CCE if we allowed to put arbitrary charsequences
to the list that initially was a MutableList<String>

All other test data changes (but addAllProjection.fir.kt and differentCapturedTypes.kt)
are irrelevant and will be fixed in the subsequent commits
2023-02-15 08:13:52 +00:00
Denis.Zharkov 9fa0f51a61 K2: Fix false-negative RETURN_TYPE_MISMATCH
^KT-53987 Fixed
^KT-55932 Fixed
2023-02-15 08:13:42 +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
Dmitriy Novozhilov d01a2c7271 [Test] Add test for KT-45814
^KT-45814 Can't reproduce
2023-01-31 07:53:10 +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 fbd0908f0c FIR DFA: add smartcast invalidation for init block assignments 2023-01-10 15:40:51 +02:00
pyos c185bf60f8 Add a test for data flow with reassignments in local classes 2023-01-10 15:40:51 +02:00
pyos 1aae586238 FIR DFA: don't erase statements when entering non-call-in-place lambda
Instead, rely on the variable assignment analyzer to properly restrict
smart casts. This makes error messages more consistent, but otherwise
should have no effect.
2023-01-10 15:40:51 +02:00
pyos 0dd949bb36 FIR DFA: route data flow through anonymous objects
^KT-44515 Fixed
2023-01-10 15:40:50 +02:00
Ilya Kirillov 644d1bf0d0 [FIR] ignore tests which fail because of resolve contracts violation 2022-12-12 16:21:07 +00:00
Dmitriy Novozhilov 44fd9ddf85 [Test] Add test for KT-55338 2022-12-08 10:19:36 +00:00
pyos a3768b9185 FIR DFA: don't propagate reassignments of loop-scoped vars to outside 2022-12-08 10:19:36 +00:00
pyos 02fedeb9ed FIR DFA: revalidate reassigned variables after loops
If a certain type statement is true on loop entry and all continue
paths, then it is also true on exit if the condition did not reassign
the variable.

^KT-7676 tag fixed-in-k2
2022-12-08 10:19:27 +00:00
pyos f9745bd3f1 FIR DFA: make continue jump to condition entry, not loop entry
It's also not a backwards jump in do-while, unless it's in the loop's
condition, which is a stupid "feature" IMO. As you can probably tell
from the comments added in this commit.
2022-12-08 10:19:26 +00:00
Dmitriy Novozhilov 46928eaa0b [FIR] Unconditionally enable BooleanElvisBoundSmartCasts feature in K2
^KT-54694 Fixed
^KT-26357
2022-11-29 12:25:45 +00:00
pyos 5cc08fb314 FIR DFA: check for reassignments of LHS when handling ?..
`x?.y != null` does not imply that `x != null` if e.g. an argument to
`y` has reassigned `x` in the meantime.

The same is true for `x == y` and `functionWithContract(x, y)`, but
those are somewhat harder to implement since there is no easy way to
find the last node of a certain argument.

^KT-55096
2022-11-22 15:44:38 +00:00
pyos edaca59d83 FIR DFA: fork flow everywhere
In theory, forking persistent flows should be cheap because of object
reuse, so the proposal here is to start from scratch and prove
redundancy of forks on a case-by-case basis. Something something better
safe than sorry.

^KT-28333 tag fixed-in-k2
^KT-28489 tag fixed-in-k2
2022-11-22 15:44:32 +00:00
pyos 757921e63e FIR DFA: remove exactNotType
Literally not used for anything anymore. What a waste of CPU time.

...and safeCallBreakInsideDoWhile is broken again. Oh well.
2022-11-22 15:44:31 +00:00
pyos 1ff968eca2 FIR DFA: extract approveStatementsInsideFlow(variable notEq null)
I'm not sure how this fixes a test. Magic!
2022-11-22 15:44:29 +00:00
pyos 6a2d74e211 FIR DFA: generate type implications on all null comparisons 2022-11-22 15:44:28 +00:00
pyos 2ae06a8d46 FIR DFA: when removing a variable, move type statements about dependents
val c = C("...")
  val d = c
  if (c.x == null) return
  c.x.length // c.x has type String
  d.x.length // d.x -> c.x through d -> c
  c = C(null) // remove alias d -> c
  d.x.length // info from c.x moved to d.x

^KT-54824 Fixed
2022-11-22 15:44:26 +00:00
pyos ceb1607057 FIR DFA: when breaking aliasing, keep the rest of the group together
var a = ...
  var b = a
  var c = a
  a = ...
  // b and c still aliased
2022-11-22 15:44:25 +00:00
pyos 33363ba1fc Add more variable aliasing tests 2022-11-22 15:44:23 +00:00
pyos 20871dd555 FIR DFA: update assignment indices when joining flows 2022-11-03 13:33:11 +00:00
pyos 639a454d6c FIR DFA: when joining flows, clear reassigned vars with no statements
For example:

    val c = C("...")
    val x = c.x // alias to variable for c.x, which depends on c
    if (x == null) return
    // now c.x has type Any
    c = C(null)
    // c has been reassigned => info for c.x is no longer valid;
    // c itself has never had any statements made about it, but
    // we must still call removeAllAboutVariable to clear the
    // dependents
2022-11-03 13:33:10 +00:00
pyos 0781cd12d4 FIR DFA: copy logic statements to aliases before removing variables
^KT-54744 Fixed
2022-11-03 13:33:09 +00:00
pyos 31eaa211b7 Add test for KT-54744 2022-11-03 13:33:09 +00:00
pyos ee921412fc FIR: intersect return types of declarations in intersection scopes
^KT-54378 Fixed
2022-10-14 08:25:26 +00:00
pyos 2ec264cfa2 FIR CFG: filter out variables declared inside lambdas more eagerly 2022-10-12 11:56:02 +00:00
pyos 46d7b66e59 FIR CFG: remove liveness analysis from lambda reassignment analyzer
Handling try/catch and break/continue is too hard here, and failing to
do that properly can create incorrect smartcast. Better be conservative
and assume all code is live.
2022-10-07 08:56:05 +00:00
pyos 3160470201 Minor: change a test to be more precise 2022-10-07 08:56:04 +00:00
pyos a9ae1fcdf9 FIR CFG: handle loops and try/catch when analyzing smartcasts in lambdas
See KT-50092
2022-10-07 08:56:04 +00:00
pyos d054617b8e FIR CFG: handle reassignments with explicit receivers more precisely
When a looping control structure has a reassignment with an explicit
receiver, we don't need to erase its smartcast info as it has to be a
non-local property and is thus automatically unstable anyway. However,
we should still do that upon reaching the assignment itself for slightly
more precise error messages (as the property not just "could be"
reassigned, but *has been* reassigned already).
2022-10-07 08:56:03 +00:00
pyos 77c2601382 Add a test where a local variable has the same name as a property 2022-10-07 08:56:02 +00:00
Victor Petukhov 42e71f8c53 Remove explicit enabling the new type inference from test data 2022-07-22 16:03:52 +00:00
pyos 06c7572ee5 FIR CFG: process called-in-place lambdas as loops 2022-07-11 18:11:30 +03:00
Ilya Chernikov bb996c1b27 Switch kotlin version to 1.8
with appropriate fixes in testdata, tests and other
places.
2022-06-29 10:20:30 +02:00
Jinseong Jeon a2da690afd Test: add java source files as JavaSourceRoot
so that those can be properly populated in SingleJavaRootsIndex
2022-06-16 22:14:17 +02:00
pyos 25f66b4e0e FIR CFG: mark variables touched by not-in-place lambdas in all scopes 2022-06-15 20:05:49 +00:00
pyos 526e46cffc FIR: fix some errors in local variable assignment analyzer
* wrong method was called from FirDataFlowAnalyzer.exitFunctionCall;
 * map from function to affected properties should be keyed by symbol,
   not FirFunction, as the latter may change;
 * arguments of `return` and assignment statements should be visited,
   as they may contain lambdas.
2022-06-10 09:43:48 +03:00
pyos 9968fa252a FIR: fork flow on function entry, restore receivers on exit
^KT-52680 Fixed
2022-06-10 09:42:02 +03:00
Dmitriy Novozhilov 6e2402620f [FIR] Fix collecting member candidates on receiver with smartcast
^KT-51460 Fixed
^KT-51827
2022-04-07 12:18:48 +00:00
Ivan Kochurkin 3566b7fe02 [FIR] Fix smartcast after elvis with escaping lambda, ^KT-44510 Fixed 2022-04-05 15:50:48 +00:00
Ivan Kochurkin e9b9322672 [FIR] Track inc and dec operator calls in preliminary loop visitor, ^KT-44879 Fixed 2022-04-05 15:50:46 +00:00
Ivan Kochurkin 48dbb9ceb9 [FIR] Fix resolving of refs with implicit this in lambdas in smartcasts 2022-04-05 15:50:43 +00: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 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
Victor Petukhov 0518b84b0b [FE] Remove unused SoundSmartcastFromLoopConditionForLoopAssignedVariables language feature 2022-02-16 18:41:52 +03:00