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

Psalm cannot properly infer interfaces when these are declared via class_alias #6325

Closed
boesing opened this issue Aug 17, 2021 · 1 comment · Fixed by #6327
Closed

Psalm cannot properly infer interfaces when these are declared via class_alias #6325

boesing opened this issue Aug 17, 2021 · 1 comment · Fixed by #6327

Comments

@boesing
Copy link
Contributor

boesing commented Aug 17, 2021

When using class_alias to replace an existing interface, psalm is not able to verify that the implementing class implements that interface.

https://psalm.dev/r/d0893a607e

@psalm-github-bot
Copy link

I found these snippets:

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

namespace Psr\Container
{
	interface ContainerInterface
    {}
}


namespace Interop\Container
{
    class_alias(\Psr\Container\ContainerInterface::class, ContainerInterface::class);
}


namespace Foo
{
    use Interop\Container\ContainerInterface;
    
    interface ClassInterface
    {
        public function __construct(ContainerInterface $container);
    }
    
    class ClassName implements ClassInterface
    {
        public function __construct(ContainerInterface $container)
        {
        }
    }
    
    class Container implements ContainerInterface
    {
    }
}

namespace Baz
{
    use Foo\Container;
    use Foo\ClassName;
    
    
    class Foo
    {
        /** @var Container */
        private $container;
        
        public function __construct(Container $container)
        {
        	$this->container = $container;
        }
        
    	public function initialize(): void
        {
            new ClassName($this->container);
        }
    }
}
Psalm output (using commit 285fa13):

ERROR: InvalidArgument - 55:27 - Argument 1 of Foo\ClassName::__construct expects Psr\Container\ContainerInterface, Foo\Container provided

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.

1 participant