CodeIgniter / phpstan-codeigniter

CodeIgniter extensions and rules for PHPStan
https://codeigniter.com/
MIT License
15 stars 0 forks source link

bug: Internal error: assert(count($classTypes) === 1) while analysing file #31

Open sanchawebo opened 1 day ago

sanchawebo commented 1 day ago

PHP Version

8.2

PHPStan CodeIgniter Version

1.5.1

PHPStan Version

2.0.3

What happened?

Trying to run phpstan with this extension and getting an Internal error: assert(count($classTypes) === 1) while analysing file. Running it with verbose settings i get this stack trace which i assume is linked to this extension as phpstan worked before.

Minimum Reproduction Script

/PATH_TO_PROJECT/vendor/codeigniter/phpstan-codeigniter/src/Type/ModelFindReturnTypeExtension.php(68)                                                                                                              
     #0 /PATH_TO_PROJECT/vendor/codeigniter/phpstan-codeigniter/src/Type/ModelFindReturnTypeExtension.php(68): assert(false, 'assert(count($c...')                                                                         
     #1 /PATH_TO_PROJECT/vendor/codeigniter/phpstan-codeigniter/src/Type/ModelFindReturnTypeExtension.php(105):                                                                                                            
     CodeIgniter\PHPStan\Type\ModelFindReturnTypeExtension->getClassReflection(Object(PhpParser\Node\Expr\MethodCall), Object(PHPStan\Analyser\MutatingScope))                                                                                   
     #2 /PATH_TO_PROJECT/vendor/codeigniter/phpstan-codeigniter/src/Type/ModelFindReturnTypeExtension.php(98):                                                                                                             
     CodeIgniter\PHPStan\Type\ModelFindReturnTypeExtension->getTypeFromFindAll(Object(PhpParser\Node\Expr\MethodCall), Object(PHPStan\Analyser\MutatingScope))                                                                                   
     #3 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/src/Type/TypeTraverser.php(48):                                                                                                                        
     CodeIgniter\PHPStan\Type\ModelFindReturnTypeExtension->CodeIgniter\PHPStan\Type\{closure}(Object(PHPStan\Type\MixedType), Array)                                                                                                            
     #4 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/src/Type/TypeTraverser.php(38): PHPStan\Type\TypeTraverser->mapInternal(Object(PHPStan\Type\MixedType))                                                
     #5 /PATH_TO_PROJECT/vendor/codeigniter/phpstan-codeigniter/src/Type/ModelFindReturnTypeExtension.php(81): PHPStan\Type\TypeTraverser::map(Object(PHPStan\Type\MixedType), Object(Closure))                            
     #6 /PATH_TO_PROJECT/vendor/codeigniter/phpstan-codeigniter/src/Type/ModelFindReturnTypeExtension.php(53):                                                                                                             
     CodeIgniter\PHPStan\Type\ModelFindReturnTypeExtension->getTypeFromFind(Object(PhpParser\Node\Expr\MethodCall), Object(PHPStan\Analyser\MutatingScope))                                                                                      
     #7 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(3713):                                                                                                                  
     CodeIgniter\PHPStan\Type\ModelFindReturnTypeExtension->getTypeFromMethodCall(Object(PHPStan\Reflection\Type\UnionTypeMethodReflection), Object(PhpParser\Node\Expr\MethodCall), Object(PHPStan\Analyser\MutatingScope))                     
     #8 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(1493): PHPStan\Analyser\MutatingScope->methodCallReturnType(Object(PHPStan\Type\UnionType), 'find',                     
     Object(PhpParser\Node\Expr\MethodCall))                                                                                                                                                                                                     
     #9 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(1499): PHPStan\Analyser\MutatingScope->PHPStan\Analyser\{closure}()                                                     
     #10 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(549): PHPStan\Analyser\MutatingScope->resolveType('$model->find($p...', Object(PhpParser\Node\Expr\MethodCall))        
     #11 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(1509): PHPStan\Analyser\MutatingScope->getType(Object(PhpParser\Node\Expr\MethodCall))                                 
     #12 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(549): PHPStan\Analyser\MutatingScope->resolveType('$model?->find($...',                                                
     Object(PhpParser\Node\Expr\NullsafeMethodCall))                                                                                                                                                                                             
     #13 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(762): PHPStan\Analyser\MutatingScope->getType(Object(PhpParser\Node\Expr\NullsafeMethodCall))                          
     #14 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(549): PHPStan\Analyser\MutatingScope->resolveType('$produkt['data'...', Object(PhpParser\Node\Expr\Assign))            
     #15 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(1751): PHPStan\Analyser\MutatingScope->getType(Object(PhpParser\Node\Expr\Assign))                                 
     #16 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(688): PHPStan\Analyser\NodeScopeResolver->findEarlyTerminatingExpr(Object(PhpParser\Node\Expr\Assign),             
     Object(PHPStan\Analyser\MutatingScope))                                                                                                                                                                                                     
     #17 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(422): PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\Expression),                  
     Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))                                                                                                                                         
     #18 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(796): PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Node\Stmt\If_), Array,                 
     Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))                                                                                                                                         
     #19 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(422): PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\If_),                         
     Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))                                                                                                                                         
     #20 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(613): PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Node\Stmt\ClassMethod), Array,         
     Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))                                                                                                                                         
     #21 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(4512): PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\ClassMethod),                
     Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))                                                                                                                                         
     #22 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(4528): PHPStan\Analyser\NodeScopeResolver->processNodesForCalledMethod(Object(PhpParser\Node\Stmt\Class_),         
     '/PATH_TO_PROJECT...', Object(PHPStan\Reflection\ResolvedMethodReflection), Object(Closure))                                                                                                                                                 
     #23 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(4524): PHPStan\Analyser\NodeScopeResolver->processNodesForCalledMethod(Array, '/PATH_TO_PROJECT...',                
     Object(PHPStan\Reflection\ResolvedMethodReflection), Object(Closure))                                                                                                                                                                       
     #24 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(4528): PHPStan\Analyser\NodeScopeResolver->processNodesForCalledMethod(Object(PhpParser\Node\Stmt\Namespace_),     
     '/PATH_TO_PROJECT...', Object(PHPStan\Reflection\ResolvedMethodReflection), Object(Closure))                                                                                                                                                 
     #25 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(4450): PHPStan\Analyser\NodeScopeResolver->processNodesForCalledMethod(Array, '/PATH_TO_PROJECT...',                
     Object(PHPStan\Reflection\ResolvedMethodReflection), Object(Closure))                                                                                                                                                                       
     #26 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(2041):                                                                                                             
     PHPStan\Analyser\NodeScopeResolver->processCalledMethod(Object(PHPStan\Reflection\ResolvedMethodReflection))                                                                                                                                
     #27 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(1802): PHPStan\Analyser\NodeScopeResolver->processExprNode(Object(PhpParser\Node\Stmt\Expression),                 
     Object(PhpParser\Node\Expr\MethodCall), Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\ExpressionContext))                                                                                                
     #28 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(3839): PHPStan\Analyser\NodeScopeResolver->PHPStan\Analyser\{closure}(Object(PHPStan\Analyser\MutatingScope))      
     #29 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(1787): PHPStan\Analyser\NodeScopeResolver->processAssignVar(Object(PHPStan\Analyser\MutatingScope),                
     Object(PhpParser\Node\Stmt\Expression), Object(PhpParser\Node\Expr\Variable), Object(PhpParser\Node\Expr\MethodCall), Object(Closure), Object(PHPStan\Analyser\ExpressionContext), Object(Closure), true)                                   
     #30 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(691): PHPStan\Analyser\NodeScopeResolver->processExprNode(Object(PhpParser\Node\Stmt\Expression),                  
     Object(PhpParser\Node\Expr\Assign), Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\ExpressionContext))                                                                                                    
     #31 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(422): PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\Expression),                  
     Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))                                                                                                                                         
     #32 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(903): PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Node\Stmt\Foreach_), Array,            
     Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))                                                                                                                                         
     #33 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(422): PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\Foreach_),                    
     Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))                                                                                                                                         
     #34 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(613): PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Node\Stmt\ClassMethod), Array,         
     Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))                                                                                                                                         
     #35 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(422): PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\ClassMethod),                 
     Object(PHPStan\Analyser\MutatingScope), Object(PHPStan\Node\ClassStatementsGatherer), Object(PHPStan\Analyser\StatementContext))                                                                                                            
     #36 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(751): PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Node\Stmt\Class_), Array,              
     Object(PHPStan\Analyser\MutatingScope), Object(PHPStan\Node\ClassStatementsGatherer), Object(PHPStan\Analyser\StatementContext))                                                                                                            
     #37 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(422): PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\Class_),                      
     Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))                                                                                                                                         
     #38 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(721): PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Node\Stmt\Namespace_), Array,          
     Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))                                                                                                                                         
     #39 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(390): PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\Namespace_),                  
     Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))                                                                                                                                         
     #40 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/FileAnalyser.php(162): PHPStan\Analyser\NodeScopeResolver->processNodes(Array, Object(PHPStan\Analyser\MutatingScope), Object(Closure))  
     #41 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/src/Command/WorkerCommand.php(136): PHPStan\Analyser\FileAnalyser->analyseFile('/PATH_TO_PROJECT...', Array, Object(PHPStan\Rules\LazyRegistry),       
     Object(PHPStan\Collectors\Registry), NULL)                                                                                                                                                                                                  
     #42 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/EventEmitterTrait.php(111): PHPStan\Command\WorkerCommand::PHPStan\Command\{closure}(Array)                            
     #43 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/vendor/clue/ndjson-react/src/Decoder.php(117): _PHPStan_e6dc705b2\Evenement\EventEmitter->emit('data', Array)                                         
     #44 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/EventEmitterTrait.php(111): _PHPStan_e6dc705b2\Clue\React\NDJson\Decoder->handleData(Array)                            
     #45 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/vendor/react/stream/src/Util.php(62): _PHPStan_e6dc705b2\Evenement\EventEmitter->emit('data', Array)                                                  
     #46 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/EventEmitterTrait.php(111):                                                                                            
     _PHPStan_e6dc705b2\React\Stream\Util::_PHPStan_e6dc705b2\React\Stream\{closure}('{"action":"anal...')                                                                                                                                       
     #47 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/vendor/react/stream/src/DuplexResourceStream.php(168): _PHPStan_e6dc705b2\Evenement\EventEmitter->emit('data', Array)                                 
     #48 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/vendor/react/event-loop/src/StreamSelectLoop.php(201): _PHPStan_e6dc705b2\React\Stream\DuplexResourceStream->handleData(Resource id #6559)            
     #49 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/vendor/react/event-loop/src/StreamSelectLoop.php(173): _PHPStan_e6dc705b2\React\EventLoop\StreamSelectLoop->waitForStreamActivity(NULL)               
     #50 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/src/Command/WorkerCommand.php(96): _PHPStan_e6dc705b2\React\EventLoop\StreamSelectLoop->run()                                                         
     #51 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Command/Command.php(259):                                                                                                      
     PHPStan\Command\WorkerCommand->execute(Object(_PHPStan_e6dc705b2\Symfony\Component\Console\Input\ArgvInput), Object(_PHPStan_e6dc705b2\Symfony\Component\Console\Output\ConsoleOutput))                                                     
     #52 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(870):                                                                                                          
     _PHPStan_e6dc705b2\Symfony\Component\Console\Command\Command->run(Object(_PHPStan_e6dc705b2\Symfony\Component\Console\Input\ArgvInput), Object(_PHPStan_e6dc705b2\Symfony\Component\Console\Output\ConsoleOutput))                          
     #53 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(261):                                                                                                          
     _PHPStan_e6dc705b2\Symfony\Component\Console\Application->doRunCommand(Object(PHPStan\Command\WorkerCommand), Object(_PHPStan_e6dc705b2\Symfony\Component\Console\Input\ArgvInput),                                                         
     Object(_PHPStan_e6dc705b2\Symfony\Component\Console\Output\ConsoleOutput))                                                                                                                                                                  
     #54 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(157):                                                                                                          
     _PHPStan_e6dc705b2\Symfony\Component\Console\Application->doRun(Object(_PHPStan_e6dc705b2\Symfony\Component\Console\Input\ArgvInput), Object(_PHPStan_e6dc705b2\Symfony\Component\Console\Output\ConsoleOutput))                            
     #55 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(114): _PHPStan_e6dc705b2\Symfony\Component\Console\Application->run()                                                                     
     #56 phar:///PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(115): _PHPStan_e6dc705b2\{closure}()                                                                                                      
     #57 /PATH_TO_PROJECT/vendor/phpstan/phpstan/phpstan(8): require('phar:///Users/m...')                                                                                                                                 
     #58 /PATH_TO_PROJECT/vendor/bin/phpstan(119): include('/PATH_TO_PROJECT...')                                                                                                                                           
     #59 {main}             

Expected Output

Posting this here in case it can improve this library

paulbalandan commented 1 day ago

Hi, thanks for the report. Can you show the code that causes the error?