Skip to content

When using PHP attributes it incorrectly "builds" the Fully Qualified Class Name #6211

@Ilyes512

Description

@Ilyes512

See https://psalm.dev/r/4dc3c5409a

This might have to do with #6197 and the linked PR #6204

Activity

psalm-github-bot

psalm-github-bot commented on Jul 31, 2021

@psalm-github-bot

I found these snippets:

https://psalm.dev/r/4dc3c5409a
<?php

namespace NamespaceOne {
    use Attribute;
    
    #[Attribute(Attribute::TARGET_CLASS)]
    class FooAttribute
    {
        /** @var class-string */
        private string $className;

        /**
         * @param class-string<FoobarInterface> $className
         */
        public function __construct(string $className)
        {
            $this->className = $className;
        }
    }

    interface FoobarInterface {}

    class Bar implements FoobarInterface {}
}

namespace NamespaceTwo {
    use NamespaceOne\FooAttribute;
    use NamespaceOne\Bar;
    
	#[FooAttribute(className: Bar::class)]
	class Baz {}
}
Psalm output (using commit 7e137f5):

ERROR: InvalidArgument - 30:28 - Argument 1 of NamespaceOne\FooAttribute::__construct expects class-string<NamespaceOne\FoobarInterface>, NamespaceTwo\NamespaceOne\Bar::class provided
added a commit that references this issue on Jul 31, 2021
e4ead74
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @weirdan@Ilyes512

      Issue actions

        When using PHP attributes it incorrectly "builds" the Fully Qualified Class Name · Issue #6211 · vimeo/psalm