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

class_implements should return class-string type #4749

Closed
staabm opened this issue Dec 1, 2020 · 3 comments · Fixed by #9228
Closed

class_implements should return class-string type #4749

staabm opened this issue Dec 1, 2020 · 3 comments · Fixed by #9228

Comments

@staabm
Copy link
Contributor

staabm commented Dec 1, 2020

https://psalm.dev/r/886622aa50

didn't expect

ERROR: ArgumentTypeCoercion - 21:4 - Argument 1 of p expects array<array-key, class-string>, parent type non-empty-array<string, string> provided
@psalm-github-bot
Copy link

I found these snippets:

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

class B {}
interface F {}

class HelloWorld extends B implements F
{

}

/** @param class-string[] $p */
function p($p) {
}

$p = class_parents(HelloWorld::class);
if ($p)
	p($p);

$p = class_implements(HelloWorld::class);
if ($p)
	p($p);
Psalm output (using commit 27d928b):

INFO: UnusedParam - 12:12 - Param $p is never referenced in this method

INFO: MissingReturnType - 12:10 - Method p does not have a return type, expecting void

ERROR: ArgumentTypeCoercion - 21:4 - Argument 1 of p expects array<array-key, class-string>, parent type non-empty-array<string, string> provided

@orklah
Copy link
Collaborator

orklah commented Dec 1, 2020

This is easy to fix but I'm not sure what the long term vision is here.

There are two string pseudo-types: class-string and trait-string and there is a string pseudo-pseudo-type interface-string who is interpreted exactly as a class-string. This means, new class_implements(HelloWorld::class)[0]() would actually be valid code for Psalm.

I'm not sure why there isn't a full interface-string so I'm not sure this is a good idea.

@orklah
Copy link
Collaborator

orklah commented Oct 24, 2021

I guess we could just return interface-strings. Please propose a PR if you want :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants