psalm / psalm-plugin-symfony

Psalm Plugin for Symfony
MIT License
228 stars 53 forks source link

Psalm false-positive on NodeDefinition #174

Open VincentLanglet opened 3 years ago

VincentLanglet commented 3 years ago

Hi @seferov

The following code

    public function getConfigTreeBuilder(): TreeBuilder
    {
        $treeBuilder = new TreeBuilder('sonata_doctrine_orm_admin');
        $rootNode = $treeBuilder->getRootNode();
        \assert($rootNode instanceof ArrayNodeDefinition);

        $rootNode
            ->children()
                ->scalarNode('entity_manager')->defaultNull()->end()
                ->arrayNode('audit') // The error is here
                    ->addDefaultsIfNotSet()
                    ->children()
                        ->booleanNode('force')->defaultTrue()->end()
                    ->end()
                ->end()
            ->end();

        return $treeBuilder;
    }

Is returning a psalm error because arrayNode is called on possibly null value.

Indeed end() might return null, but not here, because of the ->children() call. Do you think there is a way to avoid this false positive ?

seferov commented 3 years ago

@VincentLanglet hi,

I think it is hard avoid it by just creating stubs. Correct parent node should be set for each child node builder as a parent. I have no idea for now.

seferov commented 3 years ago

@VincentLanglet can you check if it is working as expected with v2.3.0? it might be fixed with https://github.com/psalm/psalm-plugin-symfony/pull/170

VincentLanglet commented 3 years ago

Nope, the issue is still here.