New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
array_pop/array_shift false positive #2851
Comments
Not sure why is this still happening - /cc @cs278 |
Reverting phpstan/phpstan-src@b1fd47b results in an error at the if statement:
Which makes sense as the |
There's most likely a bug in handling the |
Hah think I've just found this again. https://phpstan.org/r/eff591cd-41f7-4e5e-a236-f000f32236d5 Presumably this |
@cs278 After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
5: Method HelloWorld::sayHello() has parameter $input with no value type specified in iterable type iterable.
18: Dumped type: array{0: 1|(literal-string&non-empty-string)|false, 1: 1|'x'|'y', 2?: 'x'|'y', 3?: 'y'}
20: Call to function assert() with false will always evaluate to false.
-20: Strict comparison using === between array{0: 1|(literal-string&non-empty-string)|false, 1: 1|'x'|'y', 2?: 'x'|'y', 3?: 'y'} and array{} will always evaluate to false.
-21: Call to function assert() with false will always evaluate to false.
-21: Strict comparison using === between int<1, max> and 0 will always evaluate to false.
+20: Strict comparison using === between array{0: 1|(literal-string&non-empty-string)|false, 1: 1|'x'|'y', 2?: 'x'|'y', 3?: 'y'} and array{} will always evaluate to false. Full report
|
@dereuromark After the latest commit in 1.6.x, PHPStan now reports different result with your code snippet: @@ @@
- 6: Comparison operation ">" between 1|2 and 0 is always true.
+ 6: Comparison operation ">" between int<1, 2> and 0 is always true.
13: Unreachable statement - code above always terminates. Full report
|
Another one I discovered today due to the changes to DateTime::modify https://phpstan.org/r/213421a3-bdf9-4ee1-93b9-6e3cc368021a It seems after an array_shift the whole static array is lost but IMO it should be able to retain the values as a union of static strings? |
@cs278 After the latest push in 1.8.x, PHPStan now reports different result with your code snippet: @@ @@
5: Method HelloWorld::sayHello() has parameter $input with no value type specified in iterable type iterable.
-18: Dumped type: array{0: 1|(literal-string&non-empty-string)|false, 1: 1|'x'|'y', 2?: 'x'|'y', 3?: 'y'}
+18: Dumped type: array{0: 1|(literal-string&non-falsy-string)|false, 1: 1|'x'|'y', 2?: 'x'|'y', 3?: 'y'}
20: Call to function assert() with false will always evaluate to false.
-20: Strict comparison using === between array{0: 1|(literal-string&non-empty-string)|false, 1: 1|'x'|'y', 2?: 'x'|'y', 3?: 'y'} and array{} will always evaluate to false.
-21: Call to function assert() with false will always evaluate to false.
-21: Strict comparison using === between int<1, max> and 0 will always evaluate to false.
+20: Strict comparison using === between array{0: 1|(literal-string&non-falsy-string)|false, 1: 1|'x'|'y', 2?: 'x'|'y', 3?: 'y'} and array{} will always evaluate to false. Full report
|
@Seldaek After the latest push in 1.8.x, PHPStan now reports different result with your code snippet: @@ @@
7: Dumped type: array{'+1week', '+1months', '+6months', '+17months'}
- 9: Expected type array<0|1|2|3, '+1week'|'+1months'|'+6months'|'+17months'>, actual: array<0|1|2|3, literal-string&non-empty-string>
+ 9: Expected type array<0|1|2|3, '+1week'|'+1months'|'+6months'|'+17months'>, actual: array<0|1|2|3, literal-string&non-falsy-string>
10: Cannot call method modify() on DateTimeImmutable|false. Full report
|
@dereuromark After the latest push in 1.8.x, PHPStan now reports different result with your code snippet: @@ @@
- 6: Comparison operation ">" between 1|2 and 0 is always true.
-13: Unreachable statement - code above always terminates.
+No errors |
@cs278 After the latest push in 1.8.x, PHPStan now reports different result with your code snippet: @@ @@
5: Method HelloWorld::sayHello() has parameter $input with no value type specified in iterable type iterable.
-18: Dumped type: array{0: 1|(literal-string&non-empty-string)|false, 1: 1|'x'|'y', 2?: 'x'|'y', 3?: 'y'}
-20: Call to function assert() with false will always evaluate to false.
-20: Strict comparison using === between array{0: 1|(literal-string&non-empty-string)|false, 1: 1|'x'|'y', 2?: 'x'|'y', 3?: 'y'} and array{} will always evaluate to false.
-21: Call to function assert() with false will always evaluate to false.
-21: Strict comparison using === between int<1, max> and 0 will always evaluate to false.
+18: Dumped type: array{0?: 1|(literal-string&non-falsy-string)|false, 1?: 1|'x'|'y', 2?: 'x'|'y', 3?: 'y'} Full report
|
closes phpstan/phpstan#6013 closes phpstan/phpstan#2851 closes phpstan/phpstan#6008
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Bug report
array_* false positive
Code snippet that reproduces the problem
https://phpstan.org/r/172e2161-c350-4466-8867-de074489c34f
Expected output
No error
The text was updated successfully, but these errors were encountered: