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

234 Commits

Author SHA1 Message Date
orklah
994c927b6a
Merge pull request #6445 from TysonAndre/negate-in_array-v2
Fix false positive ParadoxicalCondition in negation of in_array
2021-09-20 16:49:15 +02:00
orklah
edff17134d improve test 2021-09-19 19:30:00 +02:00
orklah
d9d9fa67a6 remove faulty test 2021-09-19 19:29:59 +02:00
Tyson Andre
f4f989d1e5 Use different in-array-* check for non-literals
Negating this would not contradict the original condition if the
variables were different. A string can be in one array of strings but
not be in a different array of strings.
2021-09-06 21:48:08 -04:00
Tyson Andre
f69a255611 Fix false positive ParadoxicalCondition in negation of in_array
For #6439
2021-09-06 21:15:04 -04:00
Bruce Weirdan
5dfd157d72
Merge pull request #6420 from orklah/ternary-override-type
Ternary override type when reassigning
2021-09-04 21:58:32 +03:00
Bruce Weirdan
b710aab148
Merge pull request #6419 from TysonAndre/in_array-fix 2021-09-04 21:56:36 +03:00
orklah
e2b594820e fix test 2021-09-04 20:27:25 +02:00
orklah
0825f220fe allow ternary to override previous type when reassigning 2021-09-04 20:22:06 +02:00
Tyson Andre
58e7ae1809 Also support non-literal types in strict in_array() check
Modified approach to #6396 by orklah

Fixes #6333

Co-Authored-By: orklah <ronan_morin@hotmail.com>
2021-09-04 12:34:49 -04:00
orklah
ea50e5db4d add test 2021-09-04 14:19:49 +02:00
orklah
861d2187dd fix tests 2021-09-04 14:17:55 +02:00
Bruce Weirdan
a4b6fbcbdf
Simplified InArrayTest a bit 2021-08-13 01:27:28 +03:00
Alexandr Zolotukhin
3d61f6ca65 Add more tests 2021-08-05 16:42:52 +03:00
Alexandr Zolotukhin
c51f0f4fbf Add tests with needle/haystack value of union types which intersect partially 2021-08-03 21:09:59 +03:00
Alexandr Zolotukhin
586e8a157e Fix tests with loose types. Fix return type in the reconciler. 2021-08-03 19:34:35 +03:00
Alexandr Zolotukhin
e278b4fd93 Add failing test cases 2021-08-03 17:29:28 +03:00
Jack Robertson
c8574a6347 Simplify FQNs 2021-07-26 13:56:15 +01:00
Jack Robertson
8bec5fc743 Add expected behaviour tests 2021-07-26 08:50:12 +01:00
ElisDN
61b78e117f Fix negative numbers 2021-07-08 19:17:31 +03:00
Bruce Weirdan
76be96ce53
Drop FakeFileProvider from tests folder
And use Psalm\Internal\Provider\FakeFileProvider
2021-07-02 03:57:57 +03:00
Andrey Klimenko
3ad3375777
Fix generic destruction in assertion (#5888) 2021-06-04 15:33:37 -04:00
Andrey Klimenko
e5e397a6c5
Type negation in generic context (#5879)
* Type negation in generic context

* Fix cs
2021-06-03 01:06:25 -04:00
orklah
f62b83a190
Assert intersection type when two variables are compared (#5774) 2021-05-18 16:14:58 -04:00
Matt Brown
787c0f30d6 Fix #5784 - only real-asserted variables from context knowledge
Any assertions added in the addNestedAssertions method should not illegitimise current knowledge
2021-05-17 15:11:27 -05:00
orklah
1bb4a05725
NullsafeMethodCall makes the variable not null for the rest of the scope (#5771) 2021-05-14 19:21:01 -04:00
Matthew Brown
859b4a2caa Fix #5725 – don’t transform non-docblock types unnecessarily 2021-05-09 12:03:42 -04:00
Matt Brown
3a87f18b5a Fix #5685 - properly negate complex conditionals 2021-05-01 20:00:01 -04:00
Matt Brown
4f5c205c57 Improve error message for #5489 2021-04-25 16:02:00 -04:00
Bruce Weirdan
933822e400 Do not consider isset checks on static properties as redundant (#5525)
* Do not consider isset checks on static properties as redundant

Unlike normal properties, static properties do not have a prescribed
initialization sequence, so they can always be uninitialized (or unset).
Thus `isset()` checks on them are never redundant.

Fixes vimeo/psalm#5489

* Fix issue with nullable is_static
2021-04-25 15:53:07 -04:00
Matthew Brown
85a0ef0456
Revert "Do not consider isset checks on static properties as redundant (#5525)" (#5670)
This reverts commit cd002e6a87.
2021-04-25 15:46:13 -04:00
Matt Brown
642f2f435c Fix #5640 - improve handling of assignments in conditional 2021-04-18 16:16:54 -04:00
orklah
bb88cff28a
Int and Float can be reconciled with Numeric (#5611) 2021-04-09 23:59:59 -04:00
3b3065c881
Allow variable keys with array_key_exists (#5606)
* Allow variable keys with array_key_exists

* Switch to elseif
2021-04-09 11:29:45 -04:00
AndrolGenhald
518d0af895
Strict int/float comparison for conditional types, improve range return type (#5601) 2021-04-09 11:28:48 -04:00
orklah
5f4a21190f
Numeric can be Falsy (#5598) 2021-04-07 22:02:13 -04:00
Matt Brown
7080bc3bff Fix #5578 - variables always set in conditionals should be combined 2021-04-06 11:11:40 -04:00
Bruce Weirdan
cd002e6a87
Do not consider isset checks on static properties as redundant (#5525)
* Do not consider isset checks on static properties as redundant

Unlike normal properties, static properties do not have a prescribed
initialization sequence, so they can always be uninitialized (or unset).
Thus `isset()` checks on them are never redundant.

Fixes vimeo/psalm#5489

* Fix issue with nullable is_static
2021-03-30 11:56:08 -04:00
AndrolGenhald
d4590711d6
Fix object-like array keys when combining string and automatic keys (fixes #5427). (#5428)
* Fix object-like array keys (fixes #5427).

* Fix incorrect return types for tests.

* Fix false positive list with literal int key.
2021-03-19 21:44:44 -04:00
orklah
2777b62d0b
String can be reconciled with Scalar (#5402) 2021-03-16 13:46:23 -04:00
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