Skip to content
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

Unset seems to reset the array types #5223

Closed
alexander-schranz opened this issue Jun 28, 2021 · 12 comments · Fixed by phpstan/phpstan-src#1559
Closed

Unset seems to reset the array types #5223

alexander-schranz opened this issue Jun 28, 2021 · 12 comments · Fixed by phpstan/phpstan-src#1559
Labels
Milestone

Comments

@alexander-schranz
Copy link

alexander-schranz commented Jun 28, 2021

Bug report

When an unset is called on a typed array the types seems to get lost or replaced by other types.

Code snippet that reproduces the problem

https://phpstan.org/r/7f6452ee-c77f-49b0-af7f-d5cca60acef3

Expected output

The example should output no errors.

Did PHPStan help you today? Did it make you happy in any way?

Yes! It does a great Job 👍, thank you.

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Jul 11, 2021
@phpstan-bot
Copy link
Contributor

@alexander-schranz After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
 15: No error to ignore is reported on line 15.
-19: Parameter #1 $filters of method HelloWorld::test() expects array('categoryKeys' => array<string>, 'tagNames' => array<string>), array<string, array<string>> given.
+19: Parameter #1 $filters of method HelloWorld::test() expects array('categoryKeys' => array<string>, 'tagNames' => array<string>), array<non-empty-string, array<string>> given.
Full report
Line Error
15 No error to ignore is reported on line 15.
19 Parameter #1 $filters of method HelloWorld::test() expects array('categoryKeys' => array<string>, 'tagNames' => array<string>), array<non-empty-string, array<string>> given.

@phpstan-bot
Copy link
Contributor

@alexander-schranz After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
 15: No error to ignore is reported on line 15.
-19: Parameter #1 $filters of method HelloWorld::test() expects array('categoryKeys' => array<string>, 'tagNames' => array<string>), array<string, array<string>> given.
+19: Parameter #1 $filters of method HelloWorld::test() expects array('categoryKeys' => array<string>, 'tagNames' => array<string>), array<literal-string&non-empty-string, array<string>> given.
Full report
Line Error
15 No error to ignore is reported on line 15.
19 Parameter #1 $filters of method HelloWorld::test() expects array('categoryKeys' => array<string>, 'tagNames' => array<string>), array<literal-string&non-empty-string, array<string>> given.

@phpstan-bot
Copy link
Contributor

@alexander-schranz After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
 15: No error to ignore is reported on line 15.
-19: Parameter #1 $filters of method HelloWorld::test() expects array('categoryKeys' => array<string>, 'tagNames' => array<string>), array<string, array<string>> given.
+19: Parameter #1 $filters of method HelloWorld::test() expects array('categoryKeys' => array<string>, 'tagNames' => array<string>), array<literal-string&non-empty-string, array<string>> given.
Full report
Line Error
15 No error to ignore is reported on line 15.
19 Parameter #1 $filters of method HelloWorld::test() expects array('categoryKeys' => array<string>, 'tagNames' => array<string>), array<literal-string&non-empty-string, array<string>> given.

@phpstan-bot
Copy link
Contributor

@alexander-schranz After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-15: No error to ignore is reported on line 15.
-19: Parameter #1 $filters of method HelloWorld::test() expects array('categoryKeys' => array<string>, 'tagNames' => array<string>), array<string, array<string>> given.
+41: Method HelloWorld::test() is unused.
Full report
Line Error
41 Method HelloWorld::test() is unused.

@phpstan-bot
Copy link
Contributor

@alexander-schranz After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
 15: No error to ignore is reported on line 15.
-19: Parameter #1 $filters of method HelloWorld::test() expects array('categoryKeys' => array<string>, 'tagNames' => array<string>), array<string, array<string>> given.
+19: Parameter #1 $filters of method HelloWorld::test() expects array{categoryKeys: array<string>, tagNames: array<string>}, array<literal-string&non-empty-string, array<string>> given.
Full report
Line Error
15 No error to ignore is reported on line 15.
19 Parameter #1 $filters of method HelloWorld::test() expects array{categoryKeys: array<string>, tagNames: array<string>}, array<literal-string&non-empty-string, array<string>> given.

@phpstan-bot
Copy link
Contributor

@alexander-schranz After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-15: No error to ignore is reported on line 15.
-19: Parameter #1 $filters of method HelloWorld::test() expects array('categoryKeys' => array<string>, 'tagNames' => array<string>), array<string, array<string>> given.
+19: Parameter #1 $filters of method HelloWorld::test() expects array{categoryKeys: array<string>, tagNames: array<string>}, array<literal-string&non-empty-string, array<string>> given.
+15: No error to ignore is reported on line 15.
Full report
Line Error
19 Parameter #1 $filters of method HelloWorld::test() expects array{categoryKeys: array<string>, tagNames: array<string>}, array<literal-string&non-empty-string, array<string>> given.
15 No error to ignore is reported on line 15.

@phpstan-bot
Copy link
Contributor

@alexander-schranz After the latest commit in 1.6.x, PHPStan now reports different result with your code snippet:

@@ @@
-15: No error to ignore is reported on line 15.
-19: Parameter #1 $filters of method HelloWorld::test() expects array('categoryKeys' => array<string>, 'tagNames' => array<string>), array<string, array<string>> given.
+17: Offset 'something' does not exist on array<'categoryKeys'|'tagNames', array<string>>.
+19: Parameter #1 $filters of method HelloWorld::test() expects array{categoryKeys: array<string>, tagNames: array<string>}, array<'categoryKeys'|'tagNames', array<string>> given.
Full report
Line Error
17 `Offset 'something' does not exist on array<'categoryKeys'
19 `Parameter #1 $filters of method HelloWorld::test() expects array{categoryKeys: array, tagNames: array}, array<'categoryKeys'

@alexander-schranz
Copy link
Author

An unset of an unknown key seems now convert array{categoryKeys: array<string>, tagNames: array<string>} into array<'categoryKeys'|'tagNames', array<string>>.

If a unset on an known key is done it is what I expected: array{categoryKeys: array<string>, tagNames: array<string>, helloWorld: array<string>} into array{categoryKeys: array<string>, tagNames: array<string>}.

Think an unset of unknown key should just do nothing.

https://phpstan.org/r/b7f06da3-f7eb-47b8-a507-c3d2efc73730

@phpstan-bot
Copy link
Contributor

@alexander-schranz After the latest push in 1.8.x, PHPStan now reports different result with your code snippet:

@@ @@
-15: No error to ignore is reported on line 15.
-19: Parameter #1 $filters of method HelloWorld::test() expects array('categoryKeys' => array<string>, 'tagNames' => array<string>), array<string, array<string>> given.
+17: Offset 'something' does not exist on array{categoryKeys: array<string>, tagNames: array<string>}.
Full report
Line Error
17 Offset 'something' does not exist on array{categoryKeys: array<string>, tagNames: array<string>}.

@phpstan-bot
Copy link
Contributor

@alexander-schranz After the latest push in 1.8.x, PHPStan now reports different result with your code snippet:

@@ @@
 15: Dumped type: array{categoryKeys: array<string>, tagNames: array<string>, helloWorld: array<string>}
 17: Dumped type: array{categoryKeys: array<string>, tagNames: array<string>}
-19: Dumped type: array<'categoryKeys'|'tagNames', array<string>>
-23: Offset 'something' does not exist on array<'categoryKeys'|'tagNames', array<string>>.
-25: Parameter #1 $filters of method HelloWorld::test() expects array{categoryKeys: array<string>, tagNames: array<string>}, array<'categoryKeys'|'tagNames', array<string>> given.
+19: Dumped type: array{categoryKeys: array<string>, tagNames: array<string>}
+23: Offset 'something' does not exist on array{categoryKeys: array<string>, tagNames: array<string>}.
Full report
Line Error
15 Dumped type: array{categoryKeys: array<string>, tagNames: array<string>, helloWorld: array<string>}
17 Dumped type: array{categoryKeys: array<string>, tagNames: array<string>}
19 Dumped type: array{categoryKeys: array<string>, tagNames: array<string>}
23 Offset 'something' does not exist on array{categoryKeys: array<string>, tagNames: array<string>}.

@ondrejmirtes
Copy link
Member

/cc @herndlm This one deserves a regression test, it looks fixed by your unset PR :) Thank you.

I think NodescopeResolverTest file with as many assertType calls as possible would work fine.

herndlm added a commit to herndlm/phpstan-src that referenced this issue Jul 26, 2022
herndlm added a commit to herndlm/phpstan-src that referenced this issue Jul 26, 2022
ondrejmirtes pushed a commit to phpstan/phpstan-src that referenced this issue Jul 26, 2022
* Regression test

Closes phpstan/phpstan#5223
@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants