phpstan: First-class callable error since PHPStan 1.8.3

Bug report

Since PHPStan 1.8.3, we are getting an error when trying to analyze a class with a first-class callable.

Code snippet that reproduces the problem

<?php declare(strict_types = 1);

class HelloWorld
{
	public function test(): void
	{
		$closure = (static fn (): string => 'evaluated Closure')(...);
	}
}

Note that the error is not triggered in the PHPStan playground.

Stack trace

 -- ---------------------------------------------------------------------------------------------------------------------------------------------------------------- 
     Error                                                                                                                                                           
 -- ---------------------------------------------------------------------------------------------------------------------------------------------------------------- 
     Internal error: Internal error: assert(!$this->isFirstClassCallable()) in file /Users/leofeyer/Temp/phpstan/HelloWorld.php                                      
                                                                                                                                                                     
     Post the following stack trace to https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md:                                                         
     #0 phar:///Users/leofeyer/Temp/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/CallLike.php(37): assert(false,      
     'assert(!$this->...')                                                                                                                                           
     #1 phar:///Users/leofeyer/Temp/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Parser/ArrowFunctionArgVisitor.php(15): PhpParser\Node\Expr\CallLike->getArgs()  
     #2 phar:///Users/leofeyer/Temp/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(113):                        
     PHPStan\Parser\ArrowFunctionArgVisitor->enterNode(Object(PhpParser\Node\Expr\FuncCall))                                                                         
     #3 phar:///Users/leofeyer/Temp/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(133):                        
     PhpParser\NodeTraverser->traverseNode(Object(PhpParser\Node\Expr\Assign))                                                                                       
     #4 phar:///Users/leofeyer/Temp/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(196):                        
     PhpParser\NodeTraverser->traverseNode(Object(PhpParser\Node\Stmt\Expression))                                                                                   
     #5 phar:///Users/leofeyer/Temp/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(105):                        
     PhpParser\NodeTraverser->traverseArray(Array)                                                                                                                   
     #6 phar:///Users/leofeyer/Temp/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(196):                        
     PhpParser\NodeTraverser->traverseNode(Object(PhpParser\Node\Stmt\ClassMethod))                                                                                  
     #7 phar:///Users/leofeyer/Temp/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(105):                        
     PhpParser\NodeTraverser->traverseArray(Array)                                                                                                                   
     #8 phar:///Users/leofeyer/Temp/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(196):                        
     PhpParser\NodeTraverser->traverseNode(Object(PhpParser\Node\Stmt\Class_))                                                                                       
     #9 phar:///Users/leofeyer/Temp/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(85):                         
     PhpParser\NodeTraverser->traverseArray(Array)                                                                                                                   
     #10 phar:///Users/leofeyer/Temp/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Parser/RichParser.php(77): PhpParser\NodeTraverser->traverse(Array)             
     #11 phar:///Users/leofeyer/Temp/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Parser/RichParser.php(52): PHPStan\Parser\RichParser->parseString('<?php        
     declare(s...')                                                                                                                                                  
     #12 phar:///Users/leofeyer/Temp/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Parser/PathRoutingParser.php(61):                                               
     PHPStan\Parser\RichParser->parseFile('/Users/leofeyer...')                                                                                                      
     #13 phar:///Users/leofeyer/Temp/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Parser/CachedParser.php(44):                                                    
     PHPStan\Parser\PathRoutingParser->parseFile('/Users/leofeyer...')                                                                                               
     #14 phar:///Users/leofeyer/Temp/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/FileAnalyser.php(86):                                                  
     PHPStan\Parser\CachedParser->parseFile('/Users/leofeyer...')                                                                                                    
     #15 phar:///Users/leofeyer/Temp/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Command/WorkerCommand.php(147):                                                 
     PHPStan\Analyser\FileAnalyser->analyseFile('/Users/leofeyer...', Array, Object(PHPStan\Rules\Registry), Object(PHPStan\Collectors\Registry), NULL)              
     #16 phar:///Users/leofeyer/Temp/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(97):                 
     PHPStan\Command\WorkerCommand->PHPStan\Command\{closure}(Array)                                                                                                 
     #17 phar:///Users/leofeyer/Temp/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/clue/ndjson-react/src/Decoder.php(110):                                      
     _PHPStan_3bfe2e67c\Evenement\EventEmitter->emit('data', Array)                                                                                                  
     #18 phar:///Users/leofeyer/Temp/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(97):                 
     _PHPStan_3bfe2e67c\Clue\React\NDJson\Decoder->handleData(Array)                                                                                                 
     #19 phar:///Users/leofeyer/Temp/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/react/stream/src/Util.php(62):                                               
     _PHPStan_3bfe2e67c\Evenement\EventEmitter->emit('data', Array)                                                                                                  
     #20 phar:///Users/leofeyer/Temp/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(97):                 
     _PHPStan_3bfe2e67c\React\Stream\Util::_PHPStan_3bfe2e67c\React\Stream\{closure}('{"action":"anal...')                                                           
     #21 phar:///Users/leofeyer/Temp/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/react/stream/src/DuplexResourceStream.php(154):                              
     _PHPStan_3bfe2e67c\Evenement\EventEmitter->emit('data', Array)                                                                                                  
     #22 phar:///Users/leofeyer/Temp/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/react/event-loop/src/StreamSelectLoop.php(201):                              
     _PHPStan_3bfe2e67c\React\Stream\DuplexResourceStream->handleData(Resource id #3286)                                                                             
     #23 phar:///Users/leofeyer/Temp/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/react/event-loop/src/StreamSelectLoop.php(173):                              
     _PHPStan_3bfe2e67c\React\EventLoop\StreamSelectLoop->waitForStreamActivity(NULL)                                                                                
     #24 phar:///Users/leofeyer/Temp/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Command/WorkerCommand.php(107):                                                 
     _PHPStan_3bfe2e67c\React\EventLoop\StreamSelectLoop->run()                                                                                                      
     #25 phar:///Users/leofeyer/Temp/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Command/Command.php(259):                                    
     PHPStan\Command\WorkerCommand->execute(Object(_PHPStan_3bfe2e67c\Symfony\Component\Console\Input\ArgvInput),                                                    
     Object(_PHPStan_3bfe2e67c\Symfony\Component\Console\Output\ConsoleOutput))                                                                                      
     #26 phar:///Users/leofeyer/Temp/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(865):                                        
     _PHPStan_3bfe2e67c\Symfony\Component\Console\Command\Command->run(Object(_PHPStan_3bfe2e67c\Symfony\Component\Console\Input\ArgvInput),                         
     Object(_PHPStan_3bfe2e67c\Symfony\Component\Console\Output\ConsoleOutput))                                                                                      
     #27 phar:///Users/leofeyer/Temp/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(259):                                        
     _PHPStan_3bfe2e67c\Symfony\Component\Console\Application->doRunCommand(Object(PHPStan\Command\WorkerCommand),                                                   
     Object(_PHPStan_3bfe2e67c\Symfony\Component\Console\Input\ArgvInput), Object(_PHPStan_3bfe2e67c\Symfony\Component\Console\Output\ConsoleOutput))                
     #28 phar:///Users/leofeyer/Temp/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(157):                                        
     _PHPStan_3bfe2e67c\Symfony\Component\Console\Application->doRun(Object(_PHPStan_3bfe2e67c\Symfony\Component\Console\Input\ArgvInput),                           
     Object(_PHPStan_3bfe2e67c\Symfony\Component\Console\Output\ConsoleOutput))                                                                                      
     #29 phar:///Users/leofeyer/Temp/phpstan/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(124): _PHPStan_3bfe2e67c\Symfony\Component\Console\Application->run()   
     #30 phar:///Users/leofeyer/Temp/phpstan/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(125): _PHPStan_3bfe2e67c\{closure}()                                    
     #31 /Users/leofeyer/Temp/phpstan/vendor/phpstan/phpstan/phpstan(8): require('phar:///Users/l...')                                                               
     #32 /Users/leofeyer/Temp/phpstan/vendor/bin/phpstan(120): include('/Users/leofeyer...')                                                                         
     #33 {main}                                                                                                                                                      
     Child process error (exit code 1):                                                                                                                              
 -- ---------------------------------------------------------------------------------------------------------------------------------------------------------------- 

It does work with PHPStan 1.8.2, so maybe it is related to https://github.com/phpstan/phpstan-src/pull/1628?

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 17 (7 by maintainers)

Most upvoted comments

I have an ARM Mac and I can reproduce the issue in your repo 🎉

It seems to be a Mac ARM issue as it does not occur on Windows, Ubuntu and the macos-latest runner on GitHub, which does not yet use the latest hardware (see https://github.com/actions/runner-images/issues/2187).

@herndlm Does it make sense to reopen the issue or do you still think that #8072 will fix it?

@leofeyer check my comments there. It kind of explains why the error differs. It should indeed be the same since the error is environment dependent