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-import-type doesn't work with autoloaded files? #3999

Closed
douggr opened this issue Aug 17, 2020 · 5 comments
Closed

@psalm-import-type doesn't work with autoloaded files? #3999

douggr opened this issue Aug 17, 2020 · 5 comments
Labels

Comments

@douggr
Copy link

douggr commented Aug 17, 2020

We have this (working) example: https://psalm.dev/r/531fd85425, which have only one file.

BUT, when we try to use @psalm-import-type among several files, psalm fails with ERROR: UndefinedDocblockClass - src/Error.php:16:19 - Docblock-defined class or interface DL2\PsalmIssue\TFoo does not exist (see https://psalm.dev/200).

Funny thing, it'll work if I add a constant within the class, but I don't want to.

I've created a simple example here: https://github.com/douggr/psalm-issues (clone, composer install && composer psalm)

So, my question is: how should I expect @psalm-import-type to work? Am I missing something?

I'm using psalm@dev-master:

$ ./vendor/bin/psalm --version
Psalm dev-master@bb3c5d4c388754d2e4789ddb515af0f995aa9d2f

refs #3816

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/531fd85425
<?php declare(strict_types=1);

namespace DL2\PsalmIssue;

/**
 * @psalm-type TFoo = 'A'|'B'|'C'
 */
class A
{
}

/**
 * @psalm-import-type TFoo from A
 *
 * @psalm-type TError = array{
 *      foo: TFoo
 * }
 */
class B
{
    /**
     * @var array
     * @psalm-var ?TError
     */
    public $error;
}
Psalm output (using commit 7adc25c):

No issues!

@douggr douggr changed the title [question] how does @psalm-import-type behave? [question] how does @psalm-import-type works/import types? Aug 17, 2020
@douggr douggr changed the title [question] how does @psalm-import-type works/import types? @psalm-import-type doesn't work with autoloaded files? Aug 17, 2020
@marartner
Copy link

I think this is related to #3807

@muglug
Copy link
Collaborator

muglug commented Aug 18, 2020

Reproduced in https://psalm.dev/r/e856fbf28d – removing the namespace fixes the issue, so it's something trivial around that.

@psalm-github-bot
Copy link

I found these snippets:

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

namespace Bar;

/**
 * @psalm-type TFoo = 'A'|'B'|'C'
 */
class A
{
}

/**
 * @psalm-import-type TFoo from A as TFoo2
 *
 * @psalm-type TError = array{
 *      foo: TFoo2
 * }
 */
class B
{
    /**
     * @var ?TError $error
     */
    public $error = null;
}
Psalm output (using commit 134955a):

ERROR: UndefinedDocblockClass - 22:13 - Docblock-defined class or interface Bar\TFoo2 does not exist

ERROR: UndefinedDocblockClass - 24:5 - Docblock-defined class or interface Bar\TFoo2 does not exist

@muglug muglug added the bug label Aug 18, 2020
@muglug muglug closed this as completed in 1468a28 Aug 18, 2020
@douggr
Copy link
Author

douggr commented Aug 18, 2020

Awesome! Thank you :)

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