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

3896 Commits

Author SHA1 Message Date
Matt Brown
ff325b3e70 Fix #5141 - combine numeric-string and non-empty-string to non-empty-string 2021-02-03 17:40:41 -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
0eed186edf Fix #5140 - always replace closure return types, whether or not a matching input type is present 2021-02-01 21:40:30 -05:00
Matt Brown
0f2a07a9a3 Fix #5137 – support @psalm-flow in methods 2021-01-31 22:40:48 -05:00
Matt Brown
c1d868f950 Fix #5127 - delay transformation of base classes based on inheritance until later 2021-01-31 12:33:07 -05:00
Barney Laurance
0cd5442c47
Enforce property type invariance (#5131)
* Implement NonInvariantChildProperty detection

See https://github.com/vimeo/psalm/issues/4184

* Delete test cases with 'parentSetsWiderTypeInConstructor'

As I understand it these are not valid test cases. They
emit NonInvariantPropertyType issues which seems correct - the property
type variation is I think a latent bug in the sample code.

* Reduce shortcode for NonInvariantPropertyType to 1+max used shortcode on master
2021-01-31 11:32:24 -05:00
Joe Hoyle
a3dcc52e9a
Track references on global variables (#5122)
* Track references on global variables

Add global type references to the type map, and fix up unused detection on global variables.

* Add null assertions

* PHPCS
2021-01-28 18:58:02 -05:00
Joe Hoyle
5759472168
Add constant fetch to reference map (#5115)
* Add constant fetch to reference map

To support showing constant types on hover of constant references, we need to add them to the ref map.

* Fix root constants

* PHPCBF
2021-01-28 11:18:28 -05:00
Matt Brown
359a0166e3 Fix #4631 - prevent reusing named params 2021-01-27 22:53:55 -05:00
Matt Brown
4807d38507 Fix using std library functions 2021-01-27 22:28:33 -05:00
Matt Brown
dd11e541a7 Fix #4010 – don’t create interface intersections unless there’s no overlap 2021-01-27 12:48:32 -05:00
Matt Brown
3c58220f3a Fix #5097 - memoise more things during null coalesce 2021-01-26 23:10:57 -05:00
Matt Brown
76269658ca Fix #5107 - treat function-bound templated parameters the same
Previously they were treated differently depending on whether or not they were inside a method
2021-01-26 22:43:42 -05:00
Joe Hoyle
c946242683
Completions for array keys and type literals (#5105)
* Add completions for known array keys

* Use dynamic gap value

* Provide completions for known type contexts

* Fix formatting

* Remove trailing comma

* PHPCS fixes

* Remove support for literal floats

* Fix test for floats
2021-01-26 21:34:46 -05:00
Matt Brown
62a5a74640 Fix #5108 - prevent crash on 0 type 2021-01-26 14:06:43 -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
Bruce Weirdan
3209ef76fe
Remove ReflectionType::getName(), move ReflectionType::isBuiltin() (#5090)
* Remove ReflectionType::getName(), move ReflectionType::isBuiltin()

* `ReflectionType::getName()` was never there: https://3v4l.org/1iZt4
* `ReflectionType::isBuiltin()` was moved to
`ReflectionNamedType::isBuiltin()` in PHP 8

Fixes vimeo/psalm#5089

* Fix test

* Mark test as php 8.0 only
2021-01-24 13:31:10 -05:00
Bruce Weirdan
0489dd1fd8
Use separate exit code to indicate Psalm finding issues (#5087)
* Use separate exit code to indicate Psalm finding issues

This will allow to distinguish successful run that found some issues
from crashes.

* Fix e2e test expectations

* Documented exit statuses
2021-01-24 13:30:35 -05:00
Joe Hoyle
531cd36767
Support completions on class references (#5085)
* Support compleitions on class references

This provides completions on class references (as opposed to initiated objects via the type map), so you can do `MyClass::` and get completitions for static methods and constants etc.

* Only provide completions for references that don't exist
2021-01-24 13:29:21 -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
Joe Hoyle
ba43e6d0f3
Remove file map cache when re-analyzing files (#5084)
* Remove file map cache when re-analyzing files

When the project is re-analyzed under the single thread condition (not using a process pool), the filemaps are not cleared before re-analyzing files. This means that file maps only get appended to. If you delete the contents of a file via the LSP, the file map will still be populated with all the old values for example.

In doing this I had to write a few more tests to check my assumptions too, so adding those additional tests.

* Rename test

* Formatting

* Formatting again!
2021-01-22 16:05:28 -05:00
Adrien LUCAS
6f1f680b2d
Add option to dump taint graph (#5080)
* Add option to dump taint graph

* Fix types

* Simplify types

Co-authored-by: Matthew Brown <github@muglug.com>
2021-01-22 16:04:15 -05:00
Matt Brown
6f30399189 Fix #5070 – fix static return type inference in static methods 2021-01-22 09:58:09 -05:00
Matthew Brown
28d2795e59 Fix #5078 - when unpacking with missing array item, Use the param’s default type if param has one 2021-01-22 00:20:51 -05:00
Bruce Weirdan
d659957b88
Resolve class aliases when accessing properties (#5068)
* Resolve class aliases when accessing properties

* Moved Properties::getClasslikeStorage() to ClassLikes::getStorageFor()
2021-01-21 19:38:17 -05:00
Bruce Weirdan
d296c4bb9a
Add missing dataflow population in array spreads (#5059)
Fixes vimeo/psalm#5057
2021-01-20 17:42:11 -05:00
81b75a7884
Check iterator types on yield from (#5042)
* Check iterator types on yield from

* Switch to NodeAbstract

* Make Foo iterable
2021-01-20 17:41:15 -05:00
Matt Brown
f1107ab4d9 Fix #5049 - assertion of !empty on bool makes true 2021-01-19 17:19:47 -05:00
Matt Brown
2f58c6afc8 Fix #5020 - remove previous catch var assertions when assigning inside catch 2021-01-17 14:28:28 -05:00
Matt Brown
bca58863ad Fix #5017 - handle combining literal and non-empty strings 2021-01-17 12:22:29 -05:00
Matt Brown
4378bec917 Fix #5025 - prevent crash in assert function during reflection 2021-01-17 12:08:19 -05:00
orklah
72c21c5fa6
Calculate more literal values (#5032)
* try to calculate more literal values

* add test

* improve test
2021-01-17 10:55:32 -05:00
Matt Brown
ef0d19ed9f Fix #5029 - remember staticness of types when combining 2021-01-16 01:12:18 -05:00
orklah
7a40443ffb
don't throw InvalidArrayOffset when dealing with templates (#5019) 2021-01-14 16:35:06 -05:00
Matt Brown
ef4afd72bc Unset should change array with keyed offsets 2021-01-13 18:10:59 -05:00
Matt Brown
d10a06837d Fix #5001 - update variables after context after type change from empty
Empty is the invalid state, and some old logic here was causing a bug
2021-01-13 11:35:52 -05:00
Marco Pivetta
a53cc23809
#4997 added more precise type inference for count() returning 0 or positive-int on known arrays (#4999)
* #4997 added more precise stub for `count()` returning `0` or `positive-int` on known types

* #4997 updated `count()` to support `\SimpleXmlElement` and `\ResourceBundle` counting, as well as handling hardcoded 2-element-arrays cases

This patch:

 * adds support for `count(\SimpleXmlElement)` (https://www.php.net/manual/en/simplexmlelement.count.php)
 * adds support for `count(\ResourceBundle)` (https://www.php.net/manual/en/resourcebundle.count.php)
 * removes usage of global constants from stub (not supported - see https://www.php.net/manual/en/function.count.php)
 * adds support for identifying fixed-element-count arrays, for example `count(callable&array)`, which is always `2`

* #4997 adapted `FunctionCallReturnTypeFetcher` to infer `TPositiveInt` for `count(TNonEmptyArray)` and `count(TNonEmptyList)`

* The `FunctionCallReturnTypeFetcher` is responsible for defining the precise type of a `\count(T)`
expression when given a `T`, so we baked the whole type resolution for `positive-int`, `0` and
`positive-int|0` directly in there.

While this complicates things, it is also true that it is not possible right now (for the stubs)
to provide the level of detail around `count()` that is required by the type inference system
for such a complex function with so many different semantics.
2021-01-13 09:48:38 -05:00
Ben Davies
53afd2857d
Split unit test over multiple jobs in GitHub Actions, lowering the total run time (#4985)
* Split unit test over multiple jobs in GitHub Actions, lowering the total run time

* rename FileManipulationTest to FileManipulationTestCase so it does not run as a standalone Test
2021-01-11 17:30:33 -05:00
Matt Brown
4faa6bb320 Fix #4976 - improve type narrowing 2021-01-11 17:14:23 -05:00
Matt Brown
951afcf4af Fix #4982 - ensure destructuring assignments are seen inside a loop 2021-01-11 12:46:02 -05:00
Matt Brown
104647745b Fix #4955 - catch invalid passing class constant where templated class string expected 2021-01-11 00:28:44 -05:00
Bruce Weirdan
7007000a68
Allow Attribute::IS_REPEATABLE (#4971)
This allows Attribute::IS_REPEATABLE to be specified as attribute flag.

Fixes vimeo/psalm#4892, vimeo/psalm#4970
2021-01-10 21:55:06 -05:00
Matt Brown
59bea26bb8 Add non-emptiness check 2021-01-10 21:54:49 -05:00
Matt Brown
e299e914f8 Fix #4958 - honour template as inheritance when comparing template types 2021-01-09 18:58:29 -05:00
Matt Brown
6ef0f2e63e Fix #4943
Prevent input types becoming part of the inferred generic params when a match is found
2021-01-09 18:08:02 -05:00
Adrien LUCAS
493c57eedf
Trigger dispatch even when only legacy hooks (#4962) 2021-01-08 19:51:26 -05:00
Adrien LUCAS
d1398f2b12
Avoid false positives for taint specialized calls even when not using a variable (#4948) 2021-01-07 16:39:51 -05:00
Matt Brown
603ecadbb7 Fix #4945 - use assertion string for scalar templated assertions 2021-01-07 10:27:35 -05:00
orklah
0e17a3354f
add stubs for standard iterators (#4725)
* add stubs for standard iterators

* Apply suggestions from code review cc @weirdan

Co-authored-by: Bruce Weirdan <weirdan@gmail.com>

* complete stub + delete code made redundant by stubs + fix some syntax in stubs

* fix parse error

Co-authored-by: Bruce Weirdan <weirdan@gmail.com>
2021-01-07 10:07:07 -05:00
Adrien LUCAS
0f5886746f
Taint specialized calls even when not using a variable (#4940) 2021-01-06 14:14:52 -05:00
Matt Brown
7ffea7c425 Fix #4917 - allow array_reduce to be called with a single arg 2021-01-06 12:59:51 -05:00
orklah
665170eadb
add ArrayAccess to SimpleXmlElement (#4934)
* add ArrayAccess to SimpleXmlElement

* add test
2021-01-06 09:44:12 -05:00
orklah
f9fccb2b2d
implement DTO for plugins (#4881)
* implement DTO for plugins

* introduce EventHandler + reintroduce legacy API for plugins
2021-01-06 09:05:53 -05:00
orklah
bcc378bd20
handle concatenation with int parts (#4938) 2021-01-06 09:01:53 -05:00
Matthew Brown
13497b8d2b Break out parent and implemented class checks 2021-01-05 17:49:55 -05:00
orklah
c47230c690
Infer result of modulo 1 operation statically (#4926) 2021-01-03 16:56:04 +00:00
Lukas Bestle
2d17b744ce
SARIF report: Include help links (#4924) 2021-01-03 01:45:21 +00:00
Lukas Bestle
245a331be3
Full support for $this in @var annotations (#4922)
Fixes #4916.
2021-01-03 01:44:35 +00:00
Matthew Brown
2898e556e4 Fix test 2020-12-29 16:52:59 +00:00
Matthew Brown
7764a4ce6c Fix #4912 - detect mismatching property type 2020-12-29 16:37:03 +00:00
Matthew Brown
ddd99970a9 Fix #4901 - simplify mapping of template types within class 2020-12-29 12:24:33 +00:00
orklah
1d9987e0ed
fix phpdoc (#4905) 2020-12-29 11:42:41 +00:00
orklah
09fb141e49
Document lowercase-string when possible (#4904)
* document lowercase-string

* fix missing strtolower
2020-12-29 11:42:12 +00:00
orklah
3684ceff4c
Illegal offset (#4865)
* Illegal offset access

* add tests

* fix tests
2020-12-26 10:33:49 +00:00
Fran Moreno
fcd9dcb9b5
Allow by reference parameters in method docblock (#4873) 2020-12-21 17:11:34 +00:00
Bruce Weirdan
89ff4282df
Allow assertions on static class properties (#4833)
* Minimal implementation for assertions on static properties

* Added inheritance tests

* Add support for `ClassName::$var`

* Import strpos() to keep phpcs happy

* Add support for conditional assertions on static properties
2020-12-21 17:05:44 +00:00
Matt Brown
6eae582763 Prevent mixed array offset in array creation
Fixes #4846
2020-12-16 08:18:18 -05:00
Matt Brown
05e319a6ed Fix #4827 - don’t eradicate double after int check 2020-12-14 23:08:07 -05:00
Matt Brown
4b12cd9e18 Fix #4837 - bind correct static class when checking mixin types 2020-12-14 22:51:32 -05:00
Matt Brown
e43f2259ea Fix #4839 - undefined possibly set in by-reference should be treated as such 2020-12-14 16:57:48 -05:00
Matt Brown
fbaaf05f48 Fix psl inheritance stuff cc @azjezz 2020-12-13 16:58:03 -05:00
2e3s
d8d6811ed4
Memoize private inferred mutation-free methods (#4832) 2020-12-12 10:26:14 -05:00
Matt Brown
cc1c643168 Fix #4829 – don’t crash when yielding non-existent class 2020-12-11 10:04:28 -05:00
Matt Brown
a27c674cee Add test for #4825 2020-12-10 13:51:49 -05:00
Matt Brown
2a92025737 Union types if stmt already has one 2020-12-10 01:40:20 -05:00
Matt Brown
b7a7e2fb87 Fix get magic property checks 2020-12-10 01:29:07 -05:00
Matt Brown
37659445f0 Improve accuracy of optional example 2020-12-10 01:12:58 -05:00
Matt Brown
e6dad6e65f Be smarter when choosing inherited param types
Ref #4803
2020-12-10 00:15:37 -05:00
Matt Brown
beefa2aea3 Fix #4817 - allow optional inference 2020-12-09 19:32:56 -05: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
524084a64c Tighten up rules arouund when mutation-free methods get memoised 2020-12-08 16:39:06 -05:00
Matt Brown
be3f30ff1d Fix #4812 - reconcile array assertion on template as type correctly 2020-12-08 14:17:37 -05:00
Matt Brown
1e0bcc1876 Fix #4803 - always derive method params the same way 2020-12-08 11:27:51 -05:00
Matt Brown
387ab14bda Use better stubs for Serializable and SoapClient 2020-12-08 11:27:51 -05:00
2e3s
e46c68b1e5
Overwrite memoized return type after sum-type candidate is calculated (#4805)
* Overwrite memoized return type after sum-type candidate is calculated

* Fix mismatched types

* Fix code style
2020-12-08 09:35:11 -05:00
Matt Brown
91ee4aeca3 Fix #4797 - sanitise assertion output of template result 2020-12-07 19:11:56 -05:00
Matt Brown
8a76a43d8c Fix #4798 - improve conversion from type back to PhpParser node 2020-12-07 14:39:58 -05:00
Matt Brown
f5dd6e76f8 Fix #4802 - don’t clone context when analysing coalesce 2020-12-07 14:30:57 -05:00
Matt Brown
e702e472fc Support simple list assignment in foreach
Ref #4741
2020-12-06 19:14:52 -05:00
Matt Brown
dff2943096 Fix #4794 - invvalidate dependent types when their variables change 2020-12-06 18:16:22 -05:00
Matt Brown
9c0e9a3d7e Taint all when conditional return is used
Ref #4792
2020-12-06 11:24:48 -05:00
Matt Brown
4d1aae43f9 Fix #4778 - remove already-initialized properties when checking initialisation 2020-12-06 11:07:59 -05:00
Matt Brown
cec8d7138f Fix #4782 - don’t replace closure types with upper bounds when replacing class param types 2020-12-05 11:58:55 -05:00
Matt Brown
3f155792a7 Allow nested specialisation 2020-12-04 15:44:29 -05:00
Matt Brown
fd67d41120 Fix #4769 – don’t use unique ids for new generated nodes 2020-12-04 15:44:29 -05:00
Bruce Weirdan
c27cd3d472
Fix windows builds (#4775)
* Choco now offers PHP 8 only

* Bump build deps to allow PHP 8 builds

* Bump slevomat

* Disable coverage to allow paratest

* Bump dummy project version to allow testing on PHP 8
2020-12-04 15:11:14 -05:00
Matt Brown
4a0e2f543e Fix implicit void closure not getting recognised 2020-12-04 13:16:05 -05:00
Matt Brown
fb88145780 Fix #4767 - rescan directly-affected class-interface relationships 2020-12-04 01:19:51 -05:00