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

Can't delcare variable type by comment #2178

Closed
pawelkg opened this issue Sep 27, 2019 · 6 comments
Closed

Can't delcare variable type by comment #2178

pawelkg opened this issue Sep 27, 2019 · 6 comments

Comments

@pawelkg
Copy link

pawelkg commented Sep 27, 2019

This example shouldn't show error: https://psalm.dev/r/f7478fba75
Psalm should respect variable declaration via @var tag.

@andrew-demb
Copy link
Contributor

Use /** @var myClass $myClass */ instead /* @var myClass $myClass */

@pawelkg
Copy link
Author

pawelkg commented Sep 27, 2019

In my version of Psalm it's still showing errors. My version is: Psalm 3.5.2@648dda67ed7aca1d4ea243258f0ee7f2844ac60a
I test it on Psalm dev-master@4823ec54d41fdddf4c8588ffa821baed1d9992e6 and no changes

@andrew-demb
Copy link
Contributor

I added new * and psalm now doesn't show any error.
https://psalm.dev/r/82e7755db4

Psalm output (using commit 4823ec5):
No issues!

@muglug
Copy link
Collaborator

muglug commented Sep 27, 2019

Yeah /* isn’t a valid docblock

@muglug muglug closed this as completed Sep 27, 2019
@pawelkg
Copy link
Author

pawelkg commented Sep 27, 2019

OK. I fix it to /** but I still have error.
My code is:

$restrictionRelationship = $this->restriction
            ->getAttribute('relationship');

        if (null !== $restrictionRelationship) {
            /** @var \Wszetko\Sitemap\Items\DataTypes\StringType $restrictionRelationship */
            $restrictionRelationship
                ->setConversion('lower')
                ->setAllowedValues('allow, deny');
        }

getAttribute() method have return type is AbstractDataType but in this case it's return StringType (like in docblock; StringType extends AbstractDataType). And my result is:

ERROR: UndefinedMethod - src\Items\Video.php:323:19 - Method Wszetko\Sitemap\Items\DataTypes\AbstractDataType::setconversion does not exist
                ->setConversion('lower')

And by the way, it's change in message my method name to lowercase (setconversion) and it should be 'setConversion'.

@muglug
Copy link
Collaborator

muglug commented Sep 27, 2019

OH currently @var doesn't work above method calls (ticketed in #1916).

You can fix in your example by putting the @var above the assignment:

/** @var ?\Wszetko\Sitemap\Items\DataTypes\StringType */
$restrictionRelationship = $this->restriction
            ->getAttribute('relationship');

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

No branches or pull requests

3 participants