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 Psalm error - Could not get class storage for class-string-map #9401

Closed
ptomulik opened this issue Feb 25, 2023 · 8 comments · Fixed by #9418
Closed

Internal Psalm error - Could not get class storage for class-string-map #9401

ptomulik opened this issue Feb 25, 2023 · 8 comments · Fixed by #9418

Comments

@ptomulik
Copy link
Contributor

https://psalm.dev/r/dd5e1b7f63

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/dd5e1b7f63
<?php

interface FooInterface{}
final class Foo{}

class Container
{
    /**
     * @psalm-var class-string-map<T, T>
     */
    public array $instances = [];
      
 	/**
     * @psalm-param class-string-map<T,T> $instances
     */
    public function setInstances(array $instances)
    {
        $this->instances = $instances;
    }
}
Psalm encountered an internal error:

/vendor/vimeo/psalm/src/Psalm/Internal/Provider/ClassLikeStorageProvider.php: Could not get class storage for class-string-map

@orklah
Copy link
Collaborator

orklah commented Feb 25, 2023

Seems triggered by the missing template declaration:
https://psalm.dev/r/f35c5ac83a

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/f35c5ac83a
<?php

interface FooInterface{}
final class Foo{}

/**
 * @template T
 */
class Container
{
    /**
     * @psalm-var class-string-map<T, T>
     */
    public array $instances = [];
      
 	/**
     * @psalm-param class-string-map<T,T> $instances
     */
    public function setInstances(array $instances)
    {
        $this->instances = $instances;
    }
}
Psalm output (using commit c0e757c):

ERROR: InvalidDocblock - 14:5 - class-string-map<T, T> is not a valid type (Unrecognised as type in /var/www/vhosts/psalm.dev/httpdocs/src/somefile.php:11)

ERROR: InvalidDocblock - 17:21 - Unrecognised as type in docblock for Container::setInstances

INFO: MissingReturnType - 19:21 - Method Container::setInstances does not have a return type, expecting void

@ptomulik
Copy link
Contributor Author

Well, no errors for __construct():

https://psalm.dev/r/b68a5f859b

vs errors for another method:

https://psalm.dev/r/86230c33fd

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/b68a5f859b
<?php

class Container
{
    /**
     * @psalm-var class-string-map<T, T>
     */
    public array $instances = [];
      
 	/**
     * @psalm-param class-string-map<T,T> $instances
     */
    public function __construct(array $instances)
    {
        $this->instances = $instances;
    }
}
Psalm output (using commit c0e757c):

No issues!
https://psalm.dev/r/86230c33fd
<?php

class Container
{
    /**
     * @psalm-var class-string-map<T, T>
     */
    public array $instances = [];
      
 	/**
     * @psalm-param class-string-map<T,T> $instances
     */
    public function setInstances(array $instances)
    {
        $this->instances = $instances;
    }
}
Psalm encountered an internal error:

/vendor/vimeo/psalm/src/Psalm/Internal/Provider/ClassLikeStorageProvider.php: Could not get class storage for class-string-map

@ptomulik
Copy link
Contributor Author

Seems triggered by the missing template declaration: https://psalm.dev/r/f35c5ac83a

Does it need template declaration? I thought class-string-map acts as a template by itself

https://psalm.dev/docs/annotating_code/type_syntax/utility_types/#class-string-mapt-as-foo-t

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/f35c5ac83a
<?php

interface FooInterface{}
final class Foo{}

/**
 * @template T
 */
class Container
{
    /**
     * @psalm-var class-string-map<T, T>
     */
    public array $instances = [];
      
 	/**
     * @psalm-param class-string-map<T,T> $instances
     */
    public function setInstances(array $instances)
    {
        $this->instances = $instances;
    }
}
Psalm output (using commit c0e757c):

ERROR: InvalidDocblock - 14:5 - class-string-map<T, T> is not a valid type (Unrecognised as type in /var/www/vhosts/psalm.dev/httpdocs/src/somefile.php:11)

ERROR: InvalidDocblock - 17:21 - Unrecognised as type in docblock for Container::setInstances

INFO: MissingReturnType - 19:21 - Method Container::setInstances does not have a return type, expecting void

@orklah
Copy link
Collaborator

orklah commented Feb 25, 2023

mmh, I may be wrong then, I don't use it often

ptomulik added a commit to ptomulik/psalm that referenced this issue Feb 26, 2023
ptomulik added a commit to ptomulik/psalm that referenced this issue Feb 26, 2023
ptomulik added a commit to ptomulik/psalm that referenced this issue Feb 26, 2023
ptomulik added a commit to ptomulik/psalm that referenced this issue Feb 26, 2023
ptomulik added a commit to ptomulik/psalm that referenced this issue Feb 26, 2023
ptomulik added a commit to ptomulik/psalm that referenced this issue Feb 26, 2023
@ptomulik ptomulik mentioned this issue Feb 26, 2023
orklah added a commit that referenced this issue Feb 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants