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

93 Commits

Author SHA1 Message Date
orklah
bbcf50396d
Merge pull request #10189 from boesing/feature/inherited-assertions-v2
Inherited assertions v2
2023-09-28 23:07:15 +02:00
Maximilian Bösing
3e100b15d9
bugfix: allow object assertions for mixed
Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
2023-09-15 20:19:54 +02:00
Maximilian Bösing
56b719b1e6
qa: remove unnecessary lines from tests
Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
2023-09-10 22:17:30 +02:00
Maximilian Bösing
f6f7c20f36
qa: extend inherited assertion test
Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
2023-09-10 22:17:29 +02:00
Maximilian Bösing
5e520e6bff
bugfix: properly inherit assertions from parents or implemented interfaces
Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
2023-08-28 01:12:28 +02:00
Maximilian Bösing
5948559a31
feature: introducing proper handling of value-of in combination with backed enums
This introduces both:
- a bugfix for a regression introduced by `31eaf83c4` which prevents backed enums are incorrectly identified as literals
- an additional feature so that `value-of` can be used with backed enums to assert any of the enum cases values

Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
2023-08-25 23:58:53 +02:00
Maximilian Bösing
2d84b06cfa
qa: introduce failing test
Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
2023-06-23 20:44:33 +02:00
kkmuffme
1f2db5f31c Allow if/false assert for same variable to allow array/list distinction
Fix https://github.com/vimeo/psalm/issues/9037
2023-06-01 01:08:06 +02:00
klimick
38c93db889 More closed inheritance assertion tests 2023-05-27 18:55:27 +03:00
klimick
b7b20771c0 Add closed inheritance assertion tests 2023-05-27 13:40:23 +03:00
Jack Worman
f41da745d1 UnsupportedPropertyReferenceUsage 2023-05-12 14:12:12 -05:00
andrew
948ece9dea Fix string negation to never 2023-05-04 15:34:18 +03:00
efb5aed879 Avoid wrong assertions when working with objects returned by methods 2023-04-20 13:00:28 +02:00
Maximilian Bösing
1d4f496d0d
feature: introduce value-of in assertions
Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
2023-04-01 14:57:20 +02:00
Bruce Weirdan
1a5a9d2242
Fix asserted property mangling
Fixes vimeo/psalm#9505
2023-03-13 02:15:21 -04:00
Matthew Brown
d450b40da8
Remove some logic that didn't need to be there (#9209)
* Remove check to see what breaks

* Simplify following logic

* Add tests from @kkmuffme‘s branch

* Reduce scope of fix

* Clean up logic a little

* Add failing test

* Improvements

* Fix for non-Paradoxical Condition result
2023-02-03 21:08:16 -05: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
Jack Worman
1c19260cdd Require trailing commas 2022-12-18 13:20:31 -06:00
Jack Worman
643542346b Add codesniffer rules and expand php-cs-fixer to bin and test 2022-12-14 13:29:09 -06:00
cca276768e
List refactoring v5 (#8820)
* Squash

* Remove BC break

* Suppress

* Possibly fix

* Fixes

* Fix test

* Trigger build

* Update psl

* Update psl

* Fixes

* Fixes

* Cleanup

* fix

* Fix build

* Do not consider never when getting the max count

* Add assertion

* Cleanup

* Fix

* Cleanup
2022-12-13 21:40:19 +01:00
Matthew Brown
8d36bdc3ed
Make array shapes strict by default (#8701)
* Make array shapes strict by default

* Fix PSL tests
2022-11-11 20:14:21 -05:00
1986c8b4a8
Add support for strict arrays, fix type alias intersection, fix array_is_list assertion on non-lists (#8395)
* Immutable CodeLocation

* Remove excess clones

* Remove external clones

* Remove leftover clones

* Fix final clone issue

* Immutable storages

* Refactoring

* Fixes

* Fixes

* Fix

* Fix

* Fixes

* Simplify

* Fixes

* Fix

* Fixes

* Update

* Fix

* Cache global types

* Fix

* Update

* Update

* Fixes

* Fixes

* Refactor

* Fixes

* Fix

* Fix

* More caching

* Fix

* Fix

* Update

* Update

* Fix

* Fixes

* Update

* Refactor

* Update

* Fixes

* Break one more test

* Fix

* FIx

* Fix

* Fix

* Fix

* Fix

* Improve performance and readability

* Equivalent logic

* Fixes

* Revert

* Revert "Revert"

This reverts commit f9175100c8452c80559234200663fd4c4f4dd889.

* Fix

* Fix reference bug

* Make default TypeVisitor immutable

* Bugfix

* Remove clones

* Partial refactoring

* Refactoring

* Fixes

* Fix

* Fixes

* Fixes

* cs-fix

* Fix final bugs

* Add test

* Misc fixes

* Update

* Fixes

* Experiment with removing different property

* revert "Experiment with removing different property"

This reverts commit ac1156e077fc4ea633530d51096d27b6e88bfdf9.

* Uniform naming

* Uniform naming

* Hack hotfix

* Clean up $_FILES ref #8621

* Undo hack, try fixing properly

* Helper method

* Remove redundant call

* Partially fix bugs

* Cleanup

* Change defaults

* Fix bug

* Fix (?, hope this doesn't break anything else)

* cs-fix

* Review fixes

* Bugfix

* Bugfix

* Improve logic

* Add support for list{} and callable-list{} types, properly implement array_is_list assertions (fixes #8389)

* Default to sealed arrays

* Fix array_merge bug

* Fixes

* Fix

* Sealed type checks

* Properly infer properties-of and get_object_vars on final classes

* Fix array_map zipping

* Fix tests

* Fixes

* Fixes

* Fix more stuff

* Recursively resolve type aliases

* Fix typo

* Fixes

* Fix array_is_list assertion on keyed array

* Add BC docs

* Fixes

* fix

* Update

* Update

* Update

* Update

* Seal arrays with count assertions

* Fix #8528

* Fix

* Update

* Improve sealed array foreach logic

* get_object_vars on template properties

* Fix sealed array assertion reconciler logic

* Improved reconciler

* Add tests

* Single source of truth for test types

* Fix tests

* Fixup tests

* Fixup tests

* Fixup tests

* Update

* Fix tests

* Fix tests

* Final fixes

* Fixes

* Use list syntax only when needed

* Fix tests

* Cs-fix

* Update docs

* Update docs

* Update docs

* Update docs

* Update docs

* Document missing types

* Update docs

* Improve class-string-map docs

* Update

* Update

* I love working on psalm :)

* Keep arrays unsealed by default

* Fixup tests

* Fix syntax mistake

* cs-fix

* Fix typo

* Re-import missing types

* Keep strict types only in return types

* argc/argv fixes

* argc/argv fixes

* Fix test

* Comment-out valinor code, pinging @romm pls merge https://github.com/CuyZ/Valinor/pull/246 so we can add valinor to the psalm docs :)
2022-11-05 22:34:42 +01:00
748a74bb2c Merge remote-tracking branch 'origin/4.x' into HEAD 2022-10-16 13:41:27 +02:00
kkmuffme
b701c7074b fix tests for detailed $_SERVER 2022-09-15 19:39:02 +02:00
kkmuffme
5c39e66b15 fix tests 2022-09-15 19:38:51 +02:00
e19589117d
Fix unit test 2022-07-27 17:56:41 +02:00
Maximilian Bösing
7e033d8051
bugfix: do not extend the type - only narrow down
Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
2022-06-12 19:20:38 +02:00
Maximilian Bösing
92b4bf1f01
qa: use dedicated variable for asserting a specific value
Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
2022-06-12 02:58:08 +02:00
Maximilian Bösing
083da24551
qa: add more specific unit test(s) for the oneOf detection
Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
2022-06-12 02:53:04 +02:00
Maximilian Bösing
a9daa3ba02
qa: add failing test for one-of assertion
Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
2022-06-09 00:26:06 +02:00
orklah
b72f0564bc fix refining lowercase string and non-empty-string together 2022-04-05 21:05:23 +02:00
AndrolGenhald
57b99be519 Improve reference support for assertions, array offsets, and properties. 2022-01-26 12:55:47 -06:00
Matthew Brown
b49682a485 Simplify issue suppression in tests 2022-01-13 14:38:17 -05:00
Matthew Brown
f439d6550b
Ensure that all entries in test arrays have explicit keys (#7386)
* Transformation that updates assertions

* Simplify transformation

* Ensure that all tests have keys

* Fix a few remaining keys
2022-01-13 13:49:37 -05:00
orklah
18ab5a099f
Merge pull request #7309 from orklah/emptyStringKeyedArray
fix empty string not quoted in keyed array offset
2022-01-06 09:37:28 +01:00
orklah
a6a0769402 fix test 2022-01-05 22:39:13 +01:00
orklah
72216f9354 fix test 2022-01-05 22:36:22 +01:00
orklah
e7bc6f273a don't crash when pushing a template to in_array 2022-01-05 22:33:20 +01:00
orklah
7e2b9d0fab fix empty string in keyed array offset 2022-01-05 22:26:35 +01:00
AndrolGenhald
1b9f57f214 Fix directory separator cross-platform issue. 2021-12-30 16:29:40 -06:00
AndrolGenhald
dd631c0c85 Skip reference tests, allow assertions on magic properties (fixes #6770). 2021-12-30 16:23:59 -06:00
AndrolGenhald
cb9231b62f Add failing tests for reference property mutation. 2021-12-30 14:44:03 -06:00
AndrolGenhald
3ac497c811 Allow assertions on mutable object properties.
All of the functionality is already there, we just have to not prevent it.
2021-12-30 14:07:55 -06:00
orklah
fb97980bf9 fix test 2021-12-26 19:27:13 +01:00
orklah
f7b6c4e1b6 escape more special chars in keyed array names that won't be read by the parser 2021-12-26 19:27:13 +01:00
orklah
bb687aebba add test 2021-12-15 00:51:59 +01:00
ralila
8fb2e0f885 Handle some partials 2021-12-04 21:55:53 +01:00
Maximilian Bösing
dac82e95dc
qa: re-enable skipped test for class constant assertions
Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
2021-11-15 18:49:51 +01:00
Aleksandr Zhuravlev
b664850cdc Added support of asserting properties of objects out of scope 2021-10-17 21:29:25 +13:00
Aleksandr Zhuravlev
657f8e22ed Made the test marked 7.4 2021-10-14 22:05:40 +13:00