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 on PHPStan 1.11.1 #11059

Open
muxx opened this issue May 18, 2024 · 4 comments
Open

Internal error on PHPStan 1.11.1 #11059

muxx opened this issue May 18, 2024 · 4 comments
Labels

Comments

@muxx
Copy link

muxx commented May 18, 2024

Bug report

Source code

<?php

namespace Intaro\CRMAppApiBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class ComplexityPass implements CompilerPassInterface
{
    public function process(ContainerBuilder $container): void
    {
         $configs = $container->getParameter('overblog_graphql_types.config');

        foreach ($configs as &$typeConfig) {
            if (!isset($typeConfig['config']['fields'])) {
                continue;
            }

            foreach ($typeConfig['config']['fields'] as &$field) {
                if (isset($field['complexity'])) {
                    continue;
                }

                $field['complexity'] = '@=childrenComplexity';
            }
        }
        unset($typeConfig, $field);

        $container->setParameter('overblog_graphql_types.config', $configs);
    }
}

Stack trace

    ## phar:///var/www/crm/vendor/phpstan/phpstan/phpstan.phar/src/Type/Constant/ConstantArrayType.php(196)                                      
     #0 phar:///var/www/crm/vendor/phpstan/phpstan/phpstan.phar/src/Type/Constant/ConstantArrayType.php(1371):                                    
     PHPStan\Type\Constant\ConstantArrayType->getAllArrays()                                                                                      
     #1 phar:///var/www/crm/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/InitializerExprTypeResolver.php(1106):                             
     PHPStan\Type\Constant\ConstantArrayType->getFiniteTypes()                                                                                    
     #2 phar:///var/www/crm/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(745):                                              
     PHPStan\Reflection\InitializerExprTypeResolver->resolveIdenticalType(Object(PHPStan\Type\Constant\ConstantArrayType),                        
     Object(PHPStan\Type\Constant\ConstantArrayType))                                                                                             
     #3 phar:///var/www/crm/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(596):                                              
     PHPStan\Analyser\MutatingScope->resolveType('$configs === []', Object(PhpParser\Node\Expr\BinaryOp\Identical))                               
     #4 phar:///var/www/crm/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/TypeSpecifier.php(1292):                                             
     PHPStan\Analyser\MutatingScope->getType(Object(PhpParser\Node\Expr\BinaryOp\Identical))                                                      
     #5 phar:///var/www/crm/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/TypeSpecifier.php(191):                                              
     PHPStan\Analyser\TypeSpecifier->resolveIdentical(Object(PhpParser\Node\Expr\BinaryOp\Identical), Object(PHPStan\Analyser\MutatingScope),     
     Object(PHPStan\Analyser\TypeSpecifierContext), Object(PhpParser\Node\Expr\BinaryOp\NotIdentical))                                            
     #6 phar:///var/www/crm/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/TypeSpecifier.php(402):                                              
     PHPStan\Analyser\TypeSpecifier->specifyTypesInCondition(Object(PHPStan\Analyser\MutatingScope),                                              
     Object(PhpParser\Node\Expr\BinaryOp\Identical), Object(PHPStan\Analyser\TypeSpecifierContext),                                               
     Object(PhpParser\Node\Expr\BinaryOp\NotIdentical))                                                                                           
     #7 phar:///var/www/crm/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/TypeSpecifier.php(193):                                              
     PHPStan\Analyser\TypeSpecifier->specifyTypesInCondition(Object(PHPStan\Analyser\MutatingScope), Object(PhpParser\Node\Expr\BooleanNot),      
     Object(PHPStan\Analyser\TypeSpecifierContext), Object(PhpParser\Node\Expr\BinaryOp\NotIdentical))                                            
     #8 phar:///var/www/crm/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(2867):                                             
     PHPStan\Analyser\TypeSpecifier->specifyTypesInCondition(Object(PHPStan\Analyser\MutatingScope),                                              
     Object(PhpParser\Node\Expr\BinaryOp\NotIdentical), Object(PHPStan\Analyser\TypeSpecifierContext))                                            
     #9 phar:///var/www/crm/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(868):                                          
     PHPStan\Analyser\MutatingScope->filterByTruthyValue(Object(PhpParser\Node\Expr\BinaryOp\NotIdentical))                                       
     #10 phar:///var/www/crm/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(431):                                         
     PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\Foreach_), Object(PHPStan\Analyser\MutatingScope),            
     Object(Closure), Object(PHPStan\Analyser\StatementContext))                                                                                  
     #11 phar:///var/www/crm/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(633):                                         
     PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Node\Stmt\ClassMethod), Array,                                         
     Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))                                          
     #12 phar:///var/www/crm/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(431):                                         
     PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\ClassMethod), Object(PHPStan\Analyser\MutatingScope),         
     Object(PHPStan\Node\ClassStatementsGatherer), Object(PHPStan\Analyser\StatementContext))                                                     
     #13 phar:///var/www/crm/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(744):                                         
     PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Node\Stmt\Class_), Array, Object(PHPStan\Analyser\MutatingScope),      
     Object(PHPStan\Node\ClassStatementsGatherer), Object(PHPStan\Analyser\StatementContext))                                                     
     #14 phar:///var/www/crm/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(431):                                         
     PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\Class_), Object(PHPStan\Analyser\MutatingScope),              
     Object(Closure), Object(PHPStan\Analyser\StatementContext))                                                                                  
     #15 phar:///var/www/crm/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(714):                                         
     PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Node\Stmt\Namespace_), Array, Object(PHPStan\Analyser\MutatingScope),  
     Object(Closure), Object(PHPStan\Analyser\StatementContext))                                                                                  
     #16 phar:///var/www/crm/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(399):                                         
     PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\Namespace_), Object(PHPStan\Analyser\MutatingScope),          
     Object(Closure), Object(PHPStan\Analyser\StatementContext))                                                                                  
     #17 phar:///var/www/crm/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/FileAnalyser.php(179):                                              
     PHPStan\Analyser\NodeScopeResolver->processNodes(Array, Object(PHPStan\Analyser\MutatingScope), Object(Closure))                             
     #18 phar:///var/www/crm/vendor/phpstan/phpstan/phpstan.phar/src/Command/WorkerCommand.php(137):                                              
     PHPStan\Analyser\FileAnalyser->analyseFile('/var/www/crm/sr...', Array, Object(PHPStan\Rules\LazyRegistry),                                  
     Object(PHPStan\Collectors\Registry), NULL)                                                                                                   
     #19 phar:///var/www/crm/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(97):              
     PHPStan\Command\WorkerCommand->PHPStan\Command\{closure}(Array)                                                                              
     #20 phar:///var/www/crm/vendor/phpstan/phpstan/phpstan.phar/vendor/clue/ndjson-react/src/Decoder.php(117):                                   
     _PHPStan_49641e245\Evenement\EventEmitter->emit('data', Array)                                                                               
     #21 phar:///var/www/crm/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(97):              
     _PHPStan_49641e245\Clue\React\NDJson\Decoder->handleData(Array)                                                                              
     #22 phar:///var/www/crm/vendor/phpstan/phpstan/phpstan.phar/vendor/react/stream/src/Util.php(62):                                            
     _PHPStan_49641e245\Evenement\EventEmitter->emit('data', Array)                                                                               
     #23 phar:///var/www/crm/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(97):              
     _PHPStan_49641e245\React\Stream\Util::_PHPStan_49641e245\React\Stream\{closure}('{"action":"anal...')                                        
     #24 phar:///var/www/crm/vendor/phpstan/phpstan/phpstan.phar/vendor/react/stream/src/DuplexResourceStream.php(154):                           
     _PHPStan_49641e245\Evenement\EventEmitter->emit('data', Array)                                                                               
     #25 phar:///var/www/crm/vendor/phpstan/phpstan/phpstan.phar/vendor/react/event-loop/src/StreamSelectLoop.php(201):                           
     _PHPStan_49641e245\React\Stream\DuplexResourceStream->handleData(Resource id #14763)                                                         
     #26 phar:///var/www/crm/vendor/phpstan/phpstan/phpstan.phar/vendor/react/event-loop/src/StreamSelectLoop.php(173):                           
     _PHPStan_49641e245\React\EventLoop\StreamSelectLoop->waitForStreamActivity(NULL)                                                             
     #27 phar:///var/www/crm/vendor/phpstan/phpstan/phpstan.phar/src/Command/WorkerCommand.php(98):                                               
     _PHPStan_49641e245\React\EventLoop\StreamSelectLoop->run()                                                                                   
     #28 phar:///var/www/crm/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Command/Command.php(259):                                 
     PHPStan\Command\WorkerCommand->execute(Object(_PHPStan_49641e245\Symfony\Component\Console\Input\ArgvInput),                                 
     Object(_PHPStan_49641e245\Symfony\Component\Console\Output\ConsoleOutput))                                                                   
     #29 phar:///var/www/crm/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(870):                                     
     _PHPStan_49641e245\Symfony\Component\Console\Command\Command->run(Object(_PHPStan_49641e245\Symfony\Component\Console\Input\ArgvInput),      
     Object(_PHPStan_49641e245\Symfony\Component\Console\Output\ConsoleOutput))                                                                   
     #30 phar:///var/www/crm/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(261):                                     
     _PHPStan_49641e245\Symfony\Component\Console\Application->doRunCommand(Object(PHPStan\Command\WorkerCommand),                                
     Object(_PHPStan_49641e245\Symfony\Component\Console\Input\ArgvInput),                                                                        
     Object(_PHPStan_49641e245\Symfony\Component\Console\Output\ConsoleOutput))                                                                   
     #31 phar:///var/www/crm/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(157):                                     
     _PHPStan_49641e245\Symfony\Component\Console\Application->doRun(Object(_PHPStan_49641e245\Symfony\Component\Console\Input\ArgvInput),        
     Object(_PHPStan_49641e245\Symfony\Component\Console\Output\ConsoleOutput))                                                                   
     #32 phar:///var/www/crm/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(124):                                                                
     _PHPStan_49641e245\Symfony\Component\Console\Application->run()                                                                              
     #33 phar:///var/www/crm/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(125): _PHPStan_49641e245\{closure}()                                 
     #34 /var/www/crm/vendor/phpstan/phpstan/phpstan(8): require('phar:///var/www...')                                                            
     #35 /var/www/crm/bin/phpstan(117): include('/var/www/crm/ve...')                                                                             
     #36 {main}       

Code snippet that reproduces the problem

No response

Expected output

I got this error after updating phpstan/phpstan (1.9.14 => 1.11.1). On previous version there aren't errors. phpstan level = 5

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

No response

Copy link

mergeable bot commented May 18, 2024

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

It will most likely be closed after manual review.

@muxx
Copy link
Author

muxx commented May 18, 2024

May be reason is in complexity of $configs variable. I tried to dump type with help of this variant

<?php

namespace Intaro\CRMAppApiBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class ComplexityPass implements CompilerPassInterface
{
    public function process(ContainerBuilder $container): void
    {
        $configs = $container->getParameter('overblog_graphql_types.config');
        \PHPStan\dumpType($configs);

//        foreach ($configs as $i => $typeConfig) {
//            if (!isset($typeConfig['config']['fields'])) {
//                continue;
//            }
//
//            foreach ($typeConfig['config']['fields'] as $j => $field) {
//                if (isset($field['complexity'])) {
//                    continue;
//                }
//
//                $configs[$i]['config']['fields'][$j]['complexity'] = '@=childrenComplexity';
//            }
//        }

        $container->setParameter('overblog_graphql_types.config', $configs);
    }
}

And I got output as in attachment

@muxx
Copy link
Author

muxx commented May 18, 2024

type_dump.txt

@ondrejmirtes
Copy link
Member

Could you give me your value from overblog_graphql_types.config as a PHP array source code? So that I could try to simulate it in an analysable code example. Thanks.

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

2 participants