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

MethodSignatureMismatch does not infer the type from phpdoc in child class #5899

Closed
Snowfall022 opened this issue Jun 6, 2021 · 9 comments
Closed
Labels

Comments

@Snowfall022
Copy link

Snowfall022 commented Jun 6, 2021

In this snippet it properly works, but in my project I have this scan result:

Analyzing files...

░░

ERROR: MethodSignatureMismatch - src/ChildClass.php:13:39 - Argument 1 of ChildClass::doUpdate has wrong type 'array<array-key, mixed>', expecting 'array<array-key, int>' as defined by AbstractClass::doUpdate (see https://psalm.dev/042)
    protected function doUpdate(array $oldTemplateParameters, array $newTemplateParameters): bool


ERROR: MethodSignatureMismatch - src/ChildClass.php:13:69 - Argument 2 of ChildClass::doUpdate has wrong type 'array<array-key, mixed>', expecting 'array<array-key, int>' as defined by AbstractClass::doUpdate (see https://psalm.dev/042)
    protected function doUpdate(array $oldTemplateParameters, array $newTemplateParameters): bool


------------------------------
2 errors found
------------------------------

What could be the reason and how to force psalm to use my phpdoc?

@psalm-github-bot
Copy link

I found these snippets:

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

abstract class AbstractClass
{
    /**
     * @param int[] $oldTemplateParameters
     * @param int[] $newTemplateParameters
     */
    abstract protected function doUpdate(
        array $oldTemplateParameters,
        array $newTemplateParameters
    ): bool;
}

class ChildClass extends AbstractClass
{
    /**
     * @param int[] $oldTemplateParameters
     * @param int[] $newTemplateParameters
     */
    protected function doUpdate(array $oldTemplateParameters, array $newTemplateParameters): bool
    {
        return true;
    }
}
Psalm output (using commit 3ad3375):

No issues!

@orklah
Copy link
Collaborator

orklah commented Jun 6, 2021

Seems like Psalm ignored the phpdoc. Do you have any ParseError reported by Psalm? (If it can't read the doc, it fallbacks to the signature and array is array<array-key, mixed>

@Snowfall022
Copy link
Author

@orklah there is no mention of ParseError in the report. Psalm 4.6.3, also repeats on 4.7.3. PHP 7.4

@orklah
Copy link
Collaborator

orklah commented Jun 8, 2021

This is weird. We'd need to reproduce it somehow. Is your project public or can you make a reproducer on a github repo?

@Snowfall022
Copy link
Author

@orklah https://github.com/Snowfall022/psalm-issue-case/tree/master

I found that this issue repeats when I use phalcon stubs

@orklah
Copy link
Collaborator

orklah commented Jun 8, 2021

I'll take a look this afternoon. In the meantime, could you try to reduce the list of stubs until you identify which one cause the issue?

@Snowfall022
Copy link
Author

@orklah any of them, actually. Reduced to single item.

@orklah
Copy link
Collaborator

orklah commented Jun 8, 2021

It even reproduce when the only stub is actually an empty file, as long as there is preloadClasses=true in the stub xml tag.

@orklah
Copy link
Collaborator

orklah commented Jun 12, 2021

This is actually a duplicate of #5626 where @markrandall already analyzed the issue and came to the same conclusion :)

@orklah orklah closed this as completed Jun 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants