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

ArgumentTypeCoercion when using string-class<Interface> in a php attribute #6197

Closed
Ilyes512 opened this issue Jul 28, 2021 · 1 comment · Fixed by #6204
Closed

ArgumentTypeCoercion when using string-class<Interface> in a php attribute #6197

Ilyes512 opened this issue Jul 28, 2021 · 1 comment · Fixed by #6204
Labels

Comments

@Ilyes512
Copy link

Ilyes512 commented Jul 28, 2021

When using a php (8) attribute that expects a single parameter of type class-string<Foobar> in its constructor it returns an ArgumentTypeCoercion-error. The error incorrectly states I am passing a parent class name while in fact it's a child class name.

See https://psalm.dev/r/e6976b117f (took the snippet from #4871 that might be related to this issue)

@psalm-github-bot
Copy link

I found these snippets:

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

#[Attribute(Attribute::TARGET_CLASS)]
class Foo
{
    /** @var class-string */
    private string $className;
    
    /**
     * @param class-string<Foobar> $className
     */
    public function __construct(string $className)
    {
        $this->className = $className;
    }
}

interface Foobar {}

class Bar implements Foobar {}

#[Foo(className: Bar::class)]
class Baz {}
Psalm output (using commit 89ee1f1):

ERROR: ArgumentTypeCoercion - 22:18 - Argument 1 of Foo::__construct expects class-string<Foobar>, parent type "Bar" provided

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants