Skip to content

Don't report "no value type specified in iterable type array&callable"#5565

Open
staabm wants to merge 6 commits intophpstan:2.1.xfrom
staabm:callable-array
Open

Don't report "no value type specified in iterable type array&callable"#5565
staabm wants to merge 6 commits intophpstan:2.1.xfrom
staabm:callable-array

Conversation

@staabm
Copy link
Copy Markdown
Contributor

@staabm staabm commented Apr 29, 2026

@phpstan-bot
Copy link
Copy Markdown
Collaborator

You've opened the pull request against the latest branch 2.2.x. PHPStan 2.2 is not going to be released for months. If your code is relevant on 2.1.x and you want it to be released sooner, please rebase your pull request and change its target to 2.1.x.

@staabm staabm changed the base branch from 2.2.x to 2.1.x April 29, 2026 06:28
@ondrejmirtes
Copy link
Copy Markdown
Member

Also we could improve IntersectionType getIterableKeyType and ValueType if the type is array and callable.

@VincentLanglet
Copy link
Copy Markdown
Contributor

Also we could improve IntersectionType getIterableKeyType and ValueType if the type is array and callable.

That's not enough, because it won't report
https://phpstan.org/r/c90e4fe4-2ce7-4be3-8529-ae517dd5c445

@VincentLanglet
Copy link
Copy Markdown
Contributor

closes phpstan/phpstan#14549

I opened the issue about the fact it doesn't report an error on the line

$this->call($task);

So the current state of this PR doesn't solve it @staabm

@ondrejmirtes
Copy link
Copy Markdown
Member

I'd be interested why the line isn't reported there, seems like deficiency of ConstantArrayType::accepts().

@staabm
Copy link
Copy Markdown
Contributor Author

staabm commented Apr 29, 2026

That's not enough, because it won't report

@VincentLanglet running https://phpstan.org/r/c90e4fe4-2ce7-4be3-8529-ae517dd5c445 locally I get a error on line 13 (even on 2.1.x)

➜  phpstan-src git:(2.1.x) ✗ php bin/phpstan analyze foo.php --debug 
Note: Using configuration file /Users/staabm/workspace/phpstan-src/phpstan.neon.dist.
/Users/staabm/workspace/phpstan-src/foo.php
 ------ -------------------------------------------------------------------------------------------------------------------------- 
  Line   foo.php                                                                                                                   
 ------ -------------------------------------------------------------------------------------------------------------------------- 
  6      Class MondayMorning must be abstract or final.                                                                            
         🪪  phpstan.finalClass                                                                                                    
         at foo.php:6                                                                                                              
  8      Method MondayMorning::foo() has parameter $task with no value type specified in iterable type array.                      
         🪪  missingType.iterableValue                                                                                             
         💡  See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type                                
         at foo.php:8                                                                                                              
  11     Dumped type: array&callable(): mixed                                                                                      
         🪪  phpstan.dumpType (non-ignorable)                                                                                      
         at foo.php:11                                                                                                             
  13     Parameter #1 $task of method MondayMorning::call() expects array{string, string, string}, array&callable(): mixed given.  
         🪪  argument.type                                                                                                         
         at foo.php:13                                                                                                             
 ------ -------------------------------------------------------------------------------------------------------------------------- 

@staabm
Copy link
Copy Markdown
Contributor Author

staabm commented Apr 29, 2026

ok its weird. the error is visible on level 7,8,9 - but not on level 10

https://phpstan.org/r/ad329e91-8e3f-49b4-a30f-d4b3f562d6f6

return $this->intersectTypes(static fn (Type $type): Type => $type->getIterableValueType());
$result = $this->intersectTypes(static fn (Type $type): Type => $type->getIterableValueType());
if ($this->isCallable()->yes() && $this->isArray()->yes()) {
return TypeCombinator::intersect($result, new UnionType([new ObjectWithoutClassType(), new StringType()]));
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do empty-callable strings exist? or can we make this non-empty?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

array&callable is not narrowed enough

4 participants