psalm icon indicating copy to clipboard operation
psalm copied to clipboard

Crash when returning undefined templated class with no docblock

Open AndrolGenhald opened this issue 1 year ago • 1 comments

https://psalm.dev/r/3f50a48d4c

Adding a docblock fixes it, even if the docblock doesn't specify the template: https://psalm.dev/r/31efc1de51

AndrolGenhald avatar Sep 12 '22 15:09 AndrolGenhald

I found these snippets:

https://psalm.dev/r/3f50a48d4c
<?php

class Foo
{
    /** @var Bar<string> */
    private Bar $baz;
    
    public function __construct()
    {
        $this->baz = new Bar("baz");
    }
    
    public function getBar(): Bar
    {
        return $this->baz;
    }
}
Psalm encountered an internal error:

/vendor/vimeo/psalm/src/Psalm/Internal/Provider/ClassLikeStorageProvider.php: Could not get class storage for bar
https://psalm.dev/r/31efc1de51
<?php

class Foo
{
    /** @var Bar<string> */
    private Bar $baz;
    
    public function __construct()
    {
        $this->baz = new Bar("baz");
    }
    
    /** @return Bar */
    public function getBar(): Bar
    {
        return $this->baz;
    }
}
Psalm output (using commit afe85fa):

ERROR: UndefinedDocblockClass - 6:13 - Docblock-defined class, interface or enum named Bar does not exist

ERROR: UndefinedClass - 10:26 - Class, interface or enum named Bar does not exist

INFO: MixedAssignment - 10:9 - Unable to determine the type that $this->baz is being assigned to

ERROR: UndefinedClass - 14:31 - Class, interface or enum named Bar does not exist

INFO: MixedInferredReturnType - 13:17 - Could not verify return type 'Bar' for Foo::getBar

psalm-github-bot[bot] avatar Sep 12 '22 15:09 psalm-github-bot[bot]

Seems fixed :)

orklah avatar Oct 21 '22 23:10 orklah