psalm
psalm copied to clipboard
Crash when returning undefined templated class with no docblock
https://psalm.dev/r/3f50a48d4c
Adding a docblock fixes it, even if the docblock doesn't specify the template: https://psalm.dev/r/31efc1de51
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
Seems fixed :)