1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00
Commit Graph

5330 Commits

Author SHA1 Message Date
orklah
6353143eaf
Merge pull request #9021 from orklah/nonempty-reconcile
Non empty reconciliation
2022-12-29 22:35:12 +01:00
orklah
5bfb87c624
Merge pull request #9022 from Ocramius/fix/#8983-allow-large-union-types-in-array-type-inference
Better type inference and type checking for large union types used in array keys/values
2022-12-29 10:48:05 +01:00
orklah
790c30959d
Merge pull request #9016 from Ocramius/feature/#5039-more-refined-types-for-explode-core-function
Refined `explode()` types
2022-12-29 10:23:18 +01:00
Marco Pivetta
e6600fea21 Better type inference and type checking for large union types used in array keys/values
Fixes #8983

This patch adds a basic test showing that, when reaching a union type with 30 elements
or more, Psalm used to fail with an error, because the large union type got simplified
into a more general type as part of performance optimizations done in `TypeCombiner::combine()`.

This means that a type like `array<1|2|3|(etcetera...)|100, mixed>` was internally
simplified to `array<int, mixed>`, after reaching 30 elements or more, which in turn
led to problems and confusing errors when large union types are in play.

Such union types are relatively common in lookup-table-alike value objects.

By removing the hardcoded call-time limit of `30` types to be combined, we hereby
rely on the default `TypeCombiner::combine()` limit of `500` items, which is more
healthy.

This may come with some performance implications, but it is worth trying out, for
now.

Further parameters passed to `TypeCombiner::combine()` that were already matching
parameter default values were also omitted from the call-sites.
2022-12-29 10:05:23 +01:00
orklah
907729d83a remove useless imports 2022-12-29 01:00:06 +01:00
orklah
ee98fac581 use Atomic to create the types 2022-12-29 00:51:09 +01:00
orklah
5a002c448b fix non-empty reconciliation 2022-12-29 00:49:31 +01:00
orklah
9770e113c3
Merge pull request #9020 from orklah/isContainedbug
Is containedbug
2022-12-28 23:46:38 +01:00
orklah
a290729087 fix test 2022-12-28 23:33:28 +01:00
orklah
a8fd349e07 fix #7809 2022-12-28 23:29:33 +01:00
orklah
94f9d48bca
Merge pull request #9019 from mmcev106/prevent-erroneous-escapes
Prevent DB escaping functions from affecting non-sql taints
2022-12-28 21:32:12 +01:00
Mark McEver
53c3f1ebb3 Prevent other DB escaping functions from escaping non-sql taints 2022-12-28 14:19:01 -06:00
orklah
435acb823c
Merge pull request #9018 from orklah/TClosure
create proper TClosure instead of TNamedObject with a Closure value
2022-12-28 20:53:52 +01:00
orklah
fa4891ce58 create proper TClosure instead of TNamedObject with a Closure value 2022-12-28 20:42:59 +01:00
Mark McEver
69f31dcd4a Prevent mysqli escaping functions from escaping non-sql taints 2022-12-28 13:39:01 -06:00
orklah
58853c00f8 add test 2022-12-28 19:13:03 +01:00
Marco Pivetta
45f743f851 Adjusted assertDifferentTypeOfArray test to avoid intersecting incompatible string arrays
Getting one interesting failure caused by the `lowercase-string` refinement done before:

```
  There was 1 error:

  1) Psalm\Tests\AssertAnnotationTest::testValidCode with data set "assertDifferentTypeOfArray" ('<?php\n                    /*...ts[1];')
  Psalm\Exception\CodeException: DocblockTypeContradiction - src/somefile.php:21:21 - Cannot resolve types for $parts - docblock-defined type list{0: lowercase-string, 1?: lowercase-string} does not contain list{string, string}
```

Happens on this bit:

```php
           'assertDifferentTypeOfArray' => [
                'code' => '<?php
                    /**
                     * @psalm-assert list{string, string} $value
                     * @param mixed $value
                     */
                    function isStringTuple($value): void {
                        if (!is_array($value)
                            || !isset($value[0])
                            || !isset($value[1])
                            || !is_string($value[0])
                            || !is_string($value[1])
                        ) {
                            throw new \Exception("bad");
                        }
                    }

                    $s = "";

                    $parts = explode(":", $s, 2);

                    isStringTuple($parts);

                    echo $parts[0];
                    echo $parts[1];',
            ],
```

If I change this to:

```
@psalm-assert list{lowercase-string, lowercase-string} $value
```

Then everything works: I'm wondering if this error has to do with array intersections, and whether suppressing it suffices.

For now, changing the input string, so it is not a `lowercase-string`, is sufficient.
2022-12-28 17:57:33 +01:00
Marco Pivetta
c0c0116809 Using list{0: string, 1?: string} syntax for more precise array key types
Thanks to @orklah's feedback, the `explode()` return type is now much more precise too.

Ref: https://github.com/vimeo/psalm/pull/9016#discussion_r1058458616
2022-12-28 17:48:33 +01:00
Marco Pivetta
6341d7fef0 Adjusted existing tests to the new signature of explode()
Note how the signature became `array{0: string, 1?: string, 2?: string, array<int, string>}`,
which may be a side-effect of unions between a defined hashmap structure with array
keys, and `list<string>`.
2022-12-28 17:39:06 +01:00
orklah
dbcfe62c52
Merge pull request #8987 from jack-worman/Always_check_unused_methods_and_properties
Add @psalm-api annotation
2022-12-28 15:20:48 +01:00
orklah
d338b00cb7
Merge pull request #8999 from VincentLanglet/union
Preserve from_docblock in TypeCombiner
2022-12-28 10:08:12 +01:00
orklah
41ae518800
Merge pull request #9001 from fluffycondor/http_response_header-non-empty-list
Make `$http_response_header` a non-empty-list
2022-12-28 00:27:30 +01:00
Bruce Weirdan
52da29e389
Do not require return type on destructors in interfaces
Fixes vimeo/psalm#9008
2022-12-26 15:45:44 -04:00
Vincent Langlet
b1f1ca6d7e Try 2022-12-25 19:11:54 +01:00
Vincent Langlet
a8ef02db5a Real fix 2022-12-25 17:35:47 +01:00
fluffycondor
bfc00056e3 Add test 2022-12-25 11:50:09 +06:00
fluffycondor
032f01114e Fix test 2022-12-25 11:41:34 +06:00
Jack Worman
1bb9eb4cfc forbidden function bug and better get_defined_functions() signature 2022-12-24 12:34:40 -06:00
fluffycondor
69da58d578 Make http_response_header a non-empty-list of non-falsy-string 2022-12-25 00:02:58 +06:00
Vincent Langlet
ebd5727dec Update type 2022-12-24 13:38:02 +01:00
Vincent Langlet
723001d814 Failing test 2022-12-24 13:17:08 +01:00
Jack Worman
703a1e1698 @psalm-api 2022-12-23 16:13:46 -06:00
orklah
597957989c
Merge pull request #8990 from othercorey/verify-param-nullable
Verify nullable callmap parameters
2022-12-23 18:30:27 +01:00
Corey Taylor
d6eca8c056 Verify nullable callmap parameters 2022-12-23 06:04:35 -06:00
Emmanuel GUITON
164e279d08 Fixed object comparison that aims to improve nested template analysis (vimeo#8112). 2022-12-22 15:16:17 +01:00
Emmanuel Guiton
b138107bf3
Merge branch 'vimeo:master' into master 2022-12-22 15:15:46 +01:00
Jack Worman
8e5904d624 Fix get_object_vars on enums 2022-12-21 22:51:53 -06:00
orklah
898aa90436
Merge pull request #8967 from jack-worman/Remove_occurrences
Remove occurrences from error baseline
2022-12-21 20:31:56 +01:00
e2a5ef1eb5 Revert 2022-12-21 14:05:05 +01:00
Jack Worman
896799dff4 Remove occurrences 2022-12-21 06:45:45 -06:00
Emmanuel GUITON
3364bd97e1 Additional code style fixes (vimeo#8112). 2022-12-21 11:51:42 +01:00
Emmanuel Guiton
94adf78c16
Merge branch 'vimeo:master' into master 2022-12-21 10:56:47 +01:00
Jack Worman
b2ccf2487e Add Codebase to remaining events 2022-12-20 17:18:50 -06:00
orklah
91081f77fd
Merge pull request #8781 from weirdan/8758-optional-offsets-in-phpstorm-meta
Allow omitting argument offsets for map-type overrides in phpstorm.meta
2022-12-20 19:38:51 +01:00
3549162acc Update 2022-12-20 13:44:05 +01:00
02cd829b7d Fix bug 2022-12-20 13:28:47 +01:00
825f46f9dc Fix test 2022-12-19 22:23:31 +01:00
dc5a4576a5 Fix 2022-12-19 21:25:06 +01:00
194f71052c Add failing test 2022-12-19 21:11:10 +01:00
4fb5a615f1 Fix tests 2022-12-19 19:24:03 +01:00