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

Unable to import type inherited from trait. #7971

Closed
rzvc opened this issue May 15, 2022 · 2 comments
Closed

Unable to import type inherited from trait. #7971

rzvc opened this issue May 15, 2022 · 2 comments
Labels

Comments

@rzvc
Copy link

rzvc commented May 15, 2022

There's no way to import FooShape. It cannot be imported directly from FooTrait and it can't be imported from Foo either, despite Foo inheriting it and being able to use it.

/**
* @psalm-type FooShape = array{ foo: string }
*/
trait FooTrait
{
}

class Foo
{
    use FooTrait;
    
    /** @param FooShape $param */
    function test($param) : void
    {
    }
}

/**
* @psalm-import-type FooShape from Foo
* @psalm-type BarShape = FooShape & array{ bar: number }
*/
trait BarTrait
{
    /** @param BarShape $param */
    function test($param) : void
    {
    }
}

class Bar
{
    use BarTrait;
}

https://psalm.dev/r/09df77b283

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/09df77b283
<?php

/**
* @psalm-type FooShape = array{ foo: string }
*/
trait FooTrait
{
}

class Foo
{
    use FooTrait;
    
    /** @param FooShape $param */
    function test($param) : void
    {
    }
}

/**
* @psalm-import-type FooShape from Foo
* @psalm-type BarShape = FooShape & array{ bar: number }
*/
trait BarTrait
{
    /** @param BarShape $param */
    function test($param) : void
    {
    }
}

class Bar
{
    use BarTrait;
}
Psalm output (using commit f960d71):

ERROR: UndefinedDocblockClass - 26:16 - Docblock-defined class, interface or enum named BarShape does not exist

@weirdan
Copy link
Collaborator

weirdan commented Feb 5, 2024

It cannot be imported directly from FooTrait

It can be imported now (fixed in #10625).

@weirdan weirdan closed this as completed Feb 5, 2024
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