1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-12 09:19:40 +01:00
Commit Graph

194 Commits

Author SHA1 Message Date
Matt Brown
f8cbb229f6 Fix #5236 - improve reconciliation of interfaces when unioned with class 2021-02-24 00:05:12 -05:00
Matt Brown
fe9eb6d91e Make test reconciler names better 2021-02-23 22:37:26 -05:00
Alberto Piai
144bb37f76
Fix array_key_exists() with all int literal keys (#5197)
When checking code like the following:

```
<?php

function checkNegated(string $key): void {
    $arr = [
        0 => "foo",
        1 => "bar",
    ];

    if (!array_key_exists($key, $arr)) {
        printf("not found\n");
    }
}

function check(string $key): void {
    $arr = [
        0 => "foo",
        1 => "bar",
    ];

    if (array_key_exists($key, $arr)) {
        printf("found\n");
    }
}
```

the `if` in `checkNegated` would cause:

```
ERROR: RedundantCondition - 9:10 - Type string for $key is never =int(0)
```

This happens when the array keys are all int literals, but the "needle"
is a string.

`array_key_exists()` uses a loose equality comparison, but the generated
assertions for this specific case
(`AssertionFinder::getArrayKeyExistsAssertions`) was generating strict
equality clauses. This commit fixes it by changing the generated clause
from `=` to `~`.
2021-02-12 17:00:38 -05:00
Matt Brown
a0420fb704 Add non-falsy-string to allow more accurate checks 2021-02-03 17:19:48 -05:00
Matt Brown
03665b9646 Revert "Correct Psalm’s concept of string emptiness"
This reverts commit 331ce8ead4.

It was too hasty
2021-02-03 01:09:58 -05:00
Matt Brown
331ce8ead4 Correct Psalm’s concept of string emptiness
It contrasted with PHP’s idea
2021-02-02 23:07:51 -05:00
Matt Brown
0624098865 Ensure getId() output can always be parsed as a type
Ref #5105
2021-01-25 23:41:51 -05:00
orklah
b61831345c
only transform a Keyed array into callable-array if there's two elements (#5086)
* only transform a Keyed array into callable-array if there's two elements in array

* add tests
2021-01-22 16:14:29 -05:00
Matt Brown
f1107ab4d9 Fix #5049 - assertion of !empty on bool makes true 2021-01-19 17:19:47 -05:00
Matt Brown
ef4afd72bc Unset should change array with keyed offsets 2021-01-13 18:10:59 -05:00
Matt Brown
4faa6bb320 Fix #4976 - improve type narrowing 2021-01-11 17:14:23 -05:00
Lukas Bestle
245a331be3
Full support for $this in @var annotations (#4922)
Fixes #4916.
2021-01-03 01:44:35 +00:00
Matt Brown
9423324d65 Fix #4791 - only generate special has-array-key assertions for unknown key types 2020-12-08 19:45:47 -05:00
Matt Brown
f5dd6e76f8 Fix #4802 - don’t clone context when analysing coalesce 2020-12-07 14:30:57 -05:00
orklah
62d5ea83a1
Allow int casts if the type comes from calculation (#4768) 2020-12-03 23:15:07 -05:00
Matt Brown
bef9ab37e6 Fix #4759 – don’t generate assertion when assigning to same-named variable 2020-12-03 09:42:26 -05:00
Matt Brown
6f916553a8 Ref #4753 - allow int literals to inform key type 2020-12-02 17:13:45 -05:00
Matt Brown
e2bb02e93c Don’t suggest a potential value that’s undefined
Fixes #4754
2020-12-02 14:49:30 -05:00
Matt Brown
b64eb6d716 Break out array_key_exists tests 2020-12-02 14:42:16 -05:00
Matt Brown
7bd4d969a4 Ensure that strict empty handling always happens 2020-12-01 22:50:21 -05:00
Matt Brown
5a200ca442 Fix assertions on unions 2020-12-01 21:12:03 -05:00
Matt Brown
61e374f33b Fix null array access complaints 2020-12-01 20:10:48 -05:00
Matt Brown
e7f9ce6da0 Break out RedundantCast issues 2020-12-01 17:25:45 -05:00
Matt Brown
7295e28e20 Fix #4743 - simplify assertions generated from array_key_exists check 2020-11-30 22:10:17 -05:00
Matthew Brown
60ac109c01
Add RedundantPropertyInitializationCheck (#4732)
* Add RedundantPropertyInitializationCheck

* add documentation for RedundantPropertyInitializationCheck (#4734)

Co-authored-by: orklah <orklah@users.noreply.github.com>
2020-11-29 11:57:20 -05:00
Matt Brown
53c5e52ef2 Fix #3017 - use correct keys when converting list to array 2020-11-27 20:05:16 -05:00
orklah
b60182c514
better fix for reconciling iterable and object (#4712) 2020-11-27 09:10:55 -05:00
Matt Brown
b224970281 Fix generic ArrayAccess creation cc @orklah 2020-11-26 10:00:03 -05:00
orklah
f7cfdaabd7
Allow reconciling between object and iterable (#4706)
* Allow reconciling between object and iterable

* add tests
2020-11-26 09:25:49 -05:00
Matt Brown
f3e0201a99 Treat $a ?? $b identically to isset($a) ? $a : $b 2020-11-25 14:34:05 -05:00
Matt Brown
d40d63f180 Fix #4699 - treat isset like !== null when variable is defined 2020-11-25 14:04:55 -05:00
orklah
b6a3282589
Detect redundant cast (#4695)
* detect redundant cast

* fix redundant cast issues

* fix redundant cast in tests
2020-11-25 12:04:48 -05:00
Matt Brown
41af653bd4 Add support for some dependent types 2020-11-24 14:50:35 -05:00
Matt Brown
1cead18760 Fix #4637 - prevent regression when negating function call with === false 2020-11-20 09:56:53 -05:00
Matt Brown
de49892525 Fix #4626 - array_key_exists should infer type for first arg where possible 2020-11-19 15:40:27 -05:00
Matt Brown
ff3fff56d4 Simplify assertion negations, centralising as much as possible
Now the flag passed to scrapeAssertions just determines the errors emitted
2020-11-19 14:32:49 -05:00
Matt Brown
7803cc228b Revert "Fix #4624 - allow in_array to work with list arrays"
This reverts commit 08ae85a735.
2020-11-19 12:49:26 -05:00
Matt Brown
08ae85a735 Fix #4624 - allow in_array to work with list arrays 2020-11-19 09:26:41 -05:00
Matt Brown
324e9d11c3 Fix tests 2020-11-08 11:04:39 -05:00
Matt Brown
dccf236d16 Fix #4503 - don’t ignore assertions on possibly-null mixed 2020-11-08 10:06:39 -05:00
Matt Brown
9daa534656 Ensure we flush out re-assigned vars also referenced
Fixes #4488
2020-11-06 12:51:41 -05:00
Matt Brown
3cde617ecc Put assignment-in-conditional tests in their own file 2020-11-06 12:41:00 -05:00
Matt Brown
91d9dc3759 Fix overeager inference 2020-11-03 16:44:24 -05:00
Matt Brown
8dd5dc5b72 Improve algebra handling a little better 2020-10-26 16:34:56 -04:00
Matt Brown
94e26b2257 Empty checks variables are really falsy checks 2020-10-24 12:46:27 -04:00
Matt Brown
a832d77d73 Add logic to weed out unnecessary clauses 2020-10-24 11:31:36 -04:00
Matt Brown
f72e2d7de5 Fix #4374 - prevent paradox and allow Psalm to understand more assignments in conditionals 2020-10-20 14:43:05 -04:00
Matt Brown
fe294a4dc0 Don’t overwrite true flag 2020-10-18 01:24:36 -04:00
Matt Brown
0897abf5cb Be more explicit about negation 2020-10-18 00:39:43 -04:00
Matt Brown
3c29ffd0b7 Ignore just-coerced vars 2020-10-17 23:35:24 -04:00