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

Looks like Psalm doesn't recognize class aliases #3465

Closed
runtothefather opened this issue May 27, 2020 · 4 comments
Closed

Looks like Psalm doesn't recognize class aliases #3465

runtothefather opened this issue May 27, 2020 · 4 comments
Labels

Comments

@runtothefather
Copy link

Faced with the issue with fatal error while psalm processing the project, it is failed on the psalm --init command when processing the line with class alias definition
the exact example was

try {
  //some code
} catch (\Doctrine\Common\Persistence\Mapping\MappingException $e) { -- fatal on this line
}

looks like due to class been moved into another namespace, psalm doesn't parse this
tried to simulate situation in the sandbox https://psalm.dev/r/c63cf9ad4b

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/c63cf9ad4b
<?php
namespace UserException;

class UserException extends \Exception {
	
}

namespace Alias\UserException;

use function class_alias;

class_alias(
	\UserException\UserException::class, 
	'\Alias\UserException\UserExceptionAlias'
);

namespace Client;

try {
	throw new \Alias\UserException\UserExceptionAlias();
} catch (\Alias\UserException\UserExceptionAlias $e) {
    var_dump($e);
}
Psalm output (using commit 769ac5c):

ERROR: UndefinedClass - 20:12 - Class or interface Alias\UserException\UserExceptionAlias does not exist

ERROR: UndefinedClass - 21:10 - Class or interface Alias\UserException\UserExceptionAlias does not exist

@weirdan weirdan added the bug label May 27, 2020
@weirdan
Copy link
Collaborator

weirdan commented May 27, 2020

Also, this: https://psalm.dev/r/15b31a80cf crashes.

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/15b31a80cf
<?php
namespace UserException;

class UserException extends \Exception {
	
}

namespace Alias\UserException;

use function class_alias;

class_alias(
	\UserException\UserException::class, 
	\Alias\UserException\UserExceptionAlias::class
);

namespace Client;

try {
	throw new \Alias\UserException\UserExceptionAlias();
} catch (\Alias\UserException\UserExceptionAlias $e) {
    var_dump($e);
}
Psalm encountered an internal error:

/vendor/vimeo/psalm/src/Psalm/Internal/Provider/ClassLikeStorageProvider.php: Could not get class storage for alias\userexception\userexceptionalias

muglug added a commit that referenced this issue May 27, 2020
@muglug muglug closed this as completed in b9ea115 May 27, 2020
@BenjaminHoegh
Copy link

Seems like you can trigger the issue if you do this

class_alias(class_exists('SomeClassExtra') ? 'SomeClassExtra' : 'SomeClass', 'SomeClassParentAlias');

class SomeClassExtended extends SomeClassParentAlias
{

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