-
Notifications
You must be signed in to change notification settings - Fork 36
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
Update ComponentModel\Container stub for component-model 3.1.0 #142
base: 2.0.x
Are you sure you want to change the base?
Conversation
ed45fb8
to
11e9969
Compare
There is no |
Looks like this is recognized properly, as I no longer get 173 Parameter #1 $array of function array_filter expects array, Iterator<int|string, Nette\ComponentModel\IComponent> given. But for some reason it now thinks it returns the union of both branches: 173 Parameter #1 $array of function array_filter expects array, array<int|string, Nette\ComponentModel\IComponent>|Iterator<int|string, Nette\ComponentModel\IComponent> given. (This is with PHPStan 1.11.1.) |
I tried to reproduce it in Playground but it does not fail there: https://phpstan.org/r/50c723fc-6a84-4ca3-945d-fdc4fc5f9fbc Possibly this is some difference in how stubs are handled? |
5113331
to
9407aa9
Compare
1d686e4
to
05abeb2
Compare
Okay, added tests, which reproduce the issue when I force the 1) PHPStan\Type\Nette\ComponentModelContainerDynamicReturnTypeExtensionTest::testFileAsserts with data set "/home/jtojnar/Projects/phpstan-nette/tests/Type/Nette/data/componentModelContainer31.php:16" ('type', '/home/jtojnar/Projects/phpsta...31.php', 'array<int|string, Nette\Compo...onent>', 'array<int|string, Nette\Compo...onent>', 16)
Expected type array<int|string, Nette\ComponentModel\IComponent>, got type array<int|string, Nette\ComponentModel\IComponent>|Iterator<int|string, Nette\ComponentModel\IComponent> in /home/jtojnar/Projects/phpstan-nette/tests/Type/Nette/data/componentModelContainer31.php on line 16.
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'array<int|string, Nette\ComponentModel\IComponent>'
+'array<int|string, Nette\ComponentModel\IComponent>|Iterator<int|string, Nette\ComponentModel\IComponent>'
phar:///home/jtojnar/Projects/phpstan-nette/vendor/phpstan/phpstan/phpstan.phar/src/Testing/TypeInferenceTestCase.php:81
/home/jtojnar/Projects/phpstan-nette/tests/Type/Nette/ComponentModelContainerDynamicReturnTypeExtensionTest.php:35
2) PHPStan\Type\Nette\ComponentModelContainerDynamicReturnTypeExtensionTest::testFileAsserts with data set "/home/jtojnar/Projects/phpstan-nette/tests/Type/Nette/data/componentModelContainer31.php:17" ('type', '/home/jtojnar/Projects/phpsta...31.php', 'array<int|string, Nette\Forms...ainer>', 'array<int|string, Nette\Compo...onent>', 17)
Expected type array<int|string, Nette\Forms\Container>, got type array<int|string, Nette\ComponentModel\IComponent>|Iterator<int|string, Nette\ComponentModel\IComponent> in /home/jtojnar/Projects/phpstan-nette/tests/Type/Nette/data/componentModelContainer31.php on line 17.
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'array<int|string, Nette\Forms\Container>'
+'array<int|string, Nette\ComponentModel\IComponent>|Iterator<int|string, Nette\ComponentModel\IComponent>'
phar:///home/jtojnar/Projects/phpstan-nette/vendor/phpstan/phpstan/phpstan.phar/src/Testing/TypeInferenceTestCase.php:81
/home/jtojnar/Projects/phpstan-nette/tests/Type/Nette/ComponentModelContainerDynamicReturnTypeExtensionTest.php:35
3) PHPStan\Type\Nette\ComponentModelContainerDynamicReturnTypeExtensionTest::testFileAsserts with data set "/home/jtojnar/Projects/phpstan-nette/tests/Type/Nette/data/componentModelContainer31.php:18" ('type', '/home/jtojnar/Projects/phpsta...31.php', 'Iterator<int|string, Nette\Co...onent>', 'array<int|string, Nette\Compo...onent>', 18)
Expected type Iterator<int|string, Nette\ComponentModel\IComponent>, got type array<int|string, Nette\ComponentModel\IComponent>|Iterator<int|string, Nette\ComponentModel\IComponent> in /home/jtojnar/Projects/phpstan-nette/tests/Type/Nette/data/componentModelContainer31.php on line 18.
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'Iterator<int|string, Nette\ComponentModel\IComponent>'
+'array<int|string, Nette\ComponentModel\IComponent>|Iterator<int|string, Nette\ComponentModel\IComponent>'
phar:///home/jtojnar/Projects/phpstan-nette/vendor/phpstan/phpstan/phpstan.phar/src/Testing/TypeInferenceTestCase.php:81
/home/jtojnar/Projects/phpstan-nette/tests/Type/Nette/ComponentModelContainerDynamicReturnTypeExtensionTest.php:35
4) PHPStan\Type\Nette\ComponentModelContainerDynamicReturnTypeExtensionTest::testFileAsserts with data set "/home/jtojnar/Projects/phpstan-nette/tests/Type/Nette/data/componentModelContainer31.php:19" ('type', '/home/jtojnar/Projects/phpsta...31.php', 'Iterator<int|string, Nette\Fo...ainer>', 'array<int|string, Nette\Compo...onent>', 19)
Expected type Iterator<int|string, Nette\Forms\Container>, got type array<int|string, Nette\ComponentModel\IComponent>|Iterator<int|string, Nette\ComponentModel\IComponent> in /home/jtojnar/Projects/phpstan-nette/tests/Type/Nette/data/componentModelContainer31.php on line 19.
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'Iterator<int|string, Nette\Forms\Container>'
+'array<int|string, Nette\ComponentModel\IComponent>|Iterator<int|string, Nette\ComponentModel\IComponent>'
phar:///home/jtojnar/Projects/phpstan-nette/vendor/phpstan/phpstan/phpstan.phar/src/Testing/TypeInferenceTestCase.php:81
/home/jtojnar/Projects/phpstan-nette/tests/Type/Nette/ComponentModelContainerDynamicReturnTypeExtensionTest.php:35
5) PHPStan\Type\Nette\ComponentModelContainerDynamicReturnTypeExtensionTest::testFileAsserts with data set "/home/jtojnar/Projects/phpstan-nette/tests/Type/Nette/data/componentModelContainer31.php:20" ('type', '/home/jtojnar/Projects/phpsta...31.php', 'array<int|string, Nette\Compo...onent>', 'mixed', 20)
Expected type array<int|string, Nette\ComponentModel\IComponent>|Iterator<int|string, Nette\ComponentModel\IComponent>, got type mixed in /home/jtojnar/Projects/phpstan-nette/tests/Type/Nette/data/componentModelContainer31.php on line 20.
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'array<int|string, Nette\ComponentModel\IComponent>|Iterator<int|string, Nette\ComponentModel\IComponent>'
+'mixed'
phar:///home/jtojnar/Projects/phpstan-nette/vendor/phpstan/phpstan/phpstan.phar/src/Testing/TypeInferenceTestCase.php:81
/home/jtojnar/Projects/phpstan-nette/tests/Type/Nette/ComponentModelContainerDynamicReturnTypeExtensionTest.php:35 And it seems to work just fine in the playground: |
3b24c68
to
44ed7d8
Compare
That version changes the return type to array when `$deep` argument is `false` (default): nette/component-model@7f613ee It also deprecates the arguments but we cannot add deprecated annotation to those. nette/component-model@4e0946a
44ed7d8
to
6b07d51
Compare
Also note that the CI currently does not test component-model 3.1.0 due to package and PHP version conflicts. I had to force it locally:
|
That version changes the return type to array when
$deep
argument isfalse
(default):nette/component-model@7f613ee
It also deprecates the arguments but we cannot add deprecated annotation to those.
nette/component-model@4e0946a