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

LanguageLevelTypeAware From phpstorm-stubs #7760

Closed
staabm opened this issue Aug 9, 2022 · 10 comments
Closed

LanguageLevelTypeAware From phpstorm-stubs #7760

staabm opened this issue Aug 9, 2022 · 10 comments
Labels
Milestone

Comments

@staabm
Copy link
Contributor

staabm commented Aug 9, 2022

Feature request

Could/should we take #LanguageLevelTypeAware from phpstorm stubs into account?

see e.g. https://github.com/DmitryTronin/phpstorm-stubs/blob/8bcaf58b0672ab9c3e835159c6944dc9181df94a/SPL/SPL_f.php#L150

function iterator_to_array(
  #[LanguageLevelTypeAware(['8.2' => 'Traversable|array'], default: 'Traversable')] $iterator,
  bool $preserve_keys = true
): array {}
@ondrejmirtes
Copy link
Member

Please false-positive/false-negative this would solve on phpstan.org/try.

@staabm
Copy link
Contributor Author

staabm commented Aug 9, 2022

For the above issue it would be, no error on line 10/11 for php 8.2+

We can achieve this also with existing signature mechanics though

https://phpstan.org/r/1570736d-c072-45a2-bad5-51ed6f41454a

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Aug 9, 2022
@genhoi
Copy link

genhoi commented Jul 25, 2023

Are there any plans to fix this problem?

@herndlm
Copy link
Contributor

herndlm commented Jul 25, 2023

If it's tagged as a bug then it is considered to be a bug and will be worked on at some point.

@ondrejmirtes
Copy link
Member

This is open-source - anyone can contribute a bugfix.

Are there any plans to fix this problem?

Honestly - if you really want this fixed then it's your job to fix it :)

@genhoi
Copy link

genhoi commented Jul 25, 2023

Honestly - if you really want this fixed then it's your job to fix it :)

Good suggestion, I'll try to make a fix this week

@phpstan-bot
Copy link
Contributor

@staabm After the latest push in 1.11.x, PHPStan now reports different result with your code snippet:

@@ @@
+PHP 8.2 (3 errors)
+==========
+
+ 8: Method HelloWorld::sayHello() has parameter $arr with no value type specified in iterable type array.
+ 8: Method HelloWorld::sayHello() has parameter $itOrArr with no value type specified in iterable type array.
+ 8: Method HelloWorld::sayHello() has parameter $itOrArr with no value type specified in iterable type array|Iterator.
+
+PHP 7.1 – 8.1 (5 errors)
+==========
+
  8: Method HelloWorld::sayHello() has parameter $arr with no value type specified in iterable type array.
  8: Method HelloWorld::sayHello() has parameter $itOrArr with no value type specified in iterable type array.
  8: Method HelloWorld::sayHello() has parameter $itOrArr with no value type specified in iterable type array|Iterator.
 10: Parameter #1 $iterator of function iterator_to_array expects Traversable, array given.
 11: Parameter #1 $iterator of function iterator_to_array expects Traversable, array|Iterator given.
Full report

PHP 8.2 (3 errors)

Line Error
8 Method HelloWorld::sayHello() has parameter $arr with no value type specified in iterable type array.
8 Method HelloWorld::sayHello() has parameter $itOrArr with no value type specified in iterable type array.
8 `Method HelloWorld::sayHello() has parameter $itOrArr with no value type specified in iterable type array

PHP 7.1 – 8.1 (5 errors)

Line Error
8 Method HelloWorld::sayHello() has parameter $arr with no value type specified in iterable type array.
8 Method HelloWorld::sayHello() has parameter $itOrArr with no value type specified in iterable type array.
8 `Method HelloWorld::sayHello() has parameter $itOrArr with no value type specified in iterable type array
10 Parameter #1 $iterator of function iterator_to_array expects Traversable, array given.
11 `Parameter #1 $iterator of function iterator_to_array expects Traversable, array

@ondrejmirtes
Copy link
Member

Fixed phpstan/phpstan-src#2625

I don't see any other function this would solve a problem for.

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 Dec 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants