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

Internal error for redefined FILTER_* constants #10483

Open
dhaeckel opened this issue Jan 25, 2024 · 8 comments
Open

Internal error for redefined FILTER_* constants #10483

dhaeckel opened this issue Jan 25, 2024 · 8 comments
Labels
Milestone

Comments

@dhaeckel
Copy link

Bug report

PHPStan Crashes, when a directory named plugins is configured in paths, seems to stem from the symfony console. Happens even when a path is given as cli arg. Following are a minimal neon file and the stracktrace.

parameters:
	paths:
		- plugins
	level: 0

phar:///vendor/phpstan/phpstan/phpstan.phar/src/Type/Php/FilterFunctionReturnTypeHelper.php(185)

 #0 phar:///vendor/phpstan/phpstan/phpstan.phar/src/Type/Php/FilterFunctionReturnTypeHelper.php(199): PHPStan\Type\Php\FilterFunctionReturnTypeHelper->getConstant()                                    
 #1 phar:///vendor/phpstan/phpstan/phpstan.phar/src/Type/Php/FilterFunctionReturnTypeHelper.php(124): PHPStan\Type\Php\FilterFunctionReturnTypeHelper->determineExactType()                             
 #2 phar:///vendor/phpstan/phpstan/phpstan.phar/src/Type/Php/FilterVarDynamicReturnTypeExtension.php(35): PHPStan\Type\Php\FilterFunctionReturnTypeHelper->getType()                                    
 #3 phar:///vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(1553): PHPStan\Type\Php\FilterVarDynamicReturnTypeExtension->getTypeFromFunctionCall()                                   
 #4 phar:///vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(575): PHPStan\Analyser\MutatingScope->resolveType()                                                                      
 #5 phar:///vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(2518): PHPStan\Analyser\MutatingScope->getType()                                                                     
 #6 phar:///vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(1674): PHPStan\Analyser\NodeScopeResolver->getFunctionThrowPoint()                                                   
 #7 phar:///vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(1362): PHPStan\Analyser\NodeScopeResolver->processExprNode()                                                             
 #8 phar:///vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(575): PHPStan\Analyser\MutatingScope->resolveType()                                                                      
 #9 phar:///vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(781): PHPStan\Analyser\MutatingScope->getType()                                                                          
 #10 phar:///vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(575): PHPStan\Analyser\MutatingScope->resolveType()                                                                     
 #11 phar:///vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(1567): PHPStan\Analyser\MutatingScope->getType()                                                                    
 #12 phar:///vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(626): PHPStan\Analyser\NodeScopeResolver->findEarlyTerminatingExpr()                                                
 #13 phar:///vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(370): PHPStan\Analyser\NodeScopeResolver->processStmtNode()                                                         
 #14 phar:///vendor/phpstan/phpstan/phpstan.phar/src/Analyser/FileAnalyser.php(166): PHPStan\Analyser\NodeScopeResolver->processNodes()                                                                 
 #15 phar:///vendor/phpstan/phpstan/phpstan.phar/src/Command/WorkerCommand.php(132): PHPStan\Analyser\FileAnalyser->analyseFile()                                                                       
 #16 phar:///vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(97): PHPStan\Command\WorkerCommand->PHPStan\Command\{closure}()                         
 #17 phar:///vendor/phpstan/phpstan/phpstan.phar/vendor/clue/ndjson-react/src/Decoder.php(117): _PHPStan_11268e5ee\Evenement\EventEmitter->emit()                                                       
 #18 phar:///vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(97): _PHPStan_11268e5ee\Clue\React\NDJson\Decoder->handleData()                         
 #19 phar:///vendor/phpstan/phpstan/phpstan.phar/vendor/react/stream/src/Util.php(62): _PHPStan_11268e5ee\Evenement\EventEmitter->emit()                                                                
 #20 phar:///vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(97): _PHPStan_11268e5ee\React\Stream\Util::_PHPStan_11268e5ee\React\Stream\{closure}()  
 #21 phar:///vendor/phpstan/phpstan/phpstan.phar/vendor/react/stream/src/DuplexResourceStream.php(154): _PHPStan_11268e5ee\Evenement\EventEmitter->emit()                                               
 #22 phar:///vendor/phpstan/phpstan/phpstan.phar/vendor/react/event-loop/src/StreamSelectLoop.php(201): _PHPStan_11268e5ee\React\Stream\DuplexResourceStream->handleData()                              
 #23 phar:///vendor/phpstan/phpstan/phpstan.phar/vendor/react/event-loop/src/StreamSelectLoop.php(173): _PHPStan_11268e5ee\React\EventLoop\StreamSelectLoop->waitForStreamActivity()                    
 #24 phar:///vendor/phpstan/phpstan/phpstan.phar/src/Command/WorkerCommand.php(98): _PHPStan_11268e5ee\React\EventLoop\StreamSelectLoop->run()                                                          
 #25 phar:///vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Command/Command.php(259): PHPStan\Command\WorkerCommand->execute()                                                              
 #26 phar:///vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(870): _PHPStan_11268e5ee\Symfony\Component\Console\Command\Command->run()                                       
 #27 phar:///vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(261): _PHPStan_11268e5ee\Symfony\Component\Console\Application->doRunCommand()                                  
 #28 phar:///vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(157): _PHPStan_11268e5ee\Symfony\Component\Console\Application->doRun()                                         
 #29 phar:///vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(124): _PHPStan_11268e5ee\Symfony\Component\Console\Application->run()                                                                      
 #30 phar:///vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(125): _PHPStan_11268e5ee\{closure}()                                                                                                       
 #31 /vendor/phpstan/phpstan/phpstan(8): require('phar:///...')                                                                                                                                  
 #32 {main}

Code snippet that reproduces the problem

No response

Expected output

No Internal Error

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

No response

Copy link

mergeable bot commented Jan 25, 2024

This bug report is missing a link to reproduction at phpstan.org/try.

It will most likely be closed after manual review.

@ondrejmirtes
Copy link
Member

This has nothing to do with the "plugins" name. Some code in that directory simply crashes PHPStan.

You can figure out which file does it by running PHPStan with -vvv --debug. When you figure out which file causes it, make it smaller until it's no longer reproducible. Then you know what to paste into phpstan.org/try, it should crash the playground with an internal error too :)

@dhaeckel
Copy link
Author

Thanks for the quick reply, I was able to find the code just as you said. In this case there are some filter constants that are redefinded with a different type, see https://phpstan.org/r/7f3666b1-2b89-4de3-9271-7023e25dbb53. Still wasn't able to reproduce the error in the sandbox, so I assume there might be something else in play on my machine. Closing this issue, as it is not reproducable

@ondrejmirtes
Copy link
Member

Maybe it's not reproducible in the playground, but you might have some luck creating a small reproducing repository. Don't give up, I want PHPStan to be usable for you 😊

@ondrejmirtes ondrejmirtes reopened this Jan 26, 2024
@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Jan 26, 2024
@ondrejmirtes ondrejmirtes changed the title Crash when having a directory "plugins" in paths Internal error for redefined FILTER_* constants Jan 26, 2024
@staabm
Copy link
Contributor

staabm commented Mar 1, 2024

the example in https://phpstan.org/r/7f3666b1-2b89-4de3-9271-7023e25dbb53 does not run into internal errors on my machine.

@dhaeckel would be great if you could provide a small repository which reproduces your problem

@ondrejmirtes
Copy link
Member

@staabm We don't need a repository, it's obvious how to reproduce this.

@staabm
Copy link
Contributor

staabm commented Mar 1, 2024

I have a wild guess. @dhaeckel has a php version which has ext-filter disabled.

the example at https://phpstan.org/r/7f3666b1-2b89-4de3-9271-7023e25dbb53 shows that constants will be re-defined with wrong types, e.g. FILTER_VALIDATE_INT with a false value. our code expects a int-typed value.

@ondrejmirtes
Copy link
Member

@staabm You need to find a constant that's used in the Filter extension that was introduced in a later version of PHP. Then on earlier version introduce the same constant via a bootstrap file but with a wrong type. Boom, the assumption is broken.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants