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

Empty string and generics union type parameter issue #7562

Closed
koriym opened this issue Jul 2, 2022 · 3 comments · Fixed by phpstan/phpstan-src#1731
Closed

Empty string and generics union type parameter issue #7562

koriym opened this issue Jul 2, 2022 · 3 comments · Fixed by phpstan/phpstan-src#1731
Labels
Milestone

Comments

@koriym
Copy link

koriym commented Jul 2, 2022

Bug report

Empty string and generics union type parameter does not accept an empty string.

''|class-string union type parameter accepts empty-string, but not with ''|class-string<T> parameter.

Code snippet that reproduces the problem

/**
 * @param ''|class-string<T> $p
 * @template T of object
 */
function ng($p): void
{
}

ng('');

Parameter #1 $p of function ng expects class-string<>, string given.

https://phpstan.org/r/c4e8c2a7-59a6-4863-94e4-48b0a02b7af3

Expected output

No error.

Did PHPStan help you today? Did it make you happy in any way?

It always helps. Arigato!

koriym added a commit to koriym/Ray.Di that referenced this issue Jul 2, 2022
koriym added a commit to koriym/Ray.Di that referenced this issue Jul 2, 2022
@ondrejmirtes ondrejmirtes added this to the Generics milestone Sep 1, 2022
@phpstan-bot
Copy link
Contributor

@koriym After the latest push in 1.8.x, PHPStan now reports different result with your code snippet:

@@ @@
-19: Parameter #1 $p of function ng expects class-string<>, string given.
+No errors

@staabm
Copy link
Contributor

staabm commented Sep 19, 2022

regression test incoming

clxmstaab added a commit to staabm/phpstan-src that referenced this issue Sep 19, 2022
clxmstaab added a commit to staabm/phpstan-src that referenced this issue Sep 19, 2022
ondrejmirtes pushed a commit to phpstan/phpstan-src that referenced this issue Sep 19, 2022
ondrejmirtes added a commit that referenced this issue Sep 19, 2022
phpstan/phpstan-src@9ec53eb added regression test for #7562 phpstan/phpstan-src@de67394 Optimize ConstantArrayType::isKeysSupersetOf() phpstan/phpstan-src@bd57fc5 Remove outdated comments
@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants