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

Applying type-modifying function conditionally drops type info #10897

Open
simPod opened this issue Apr 18, 2024 · 0 comments
Open

Applying type-modifying function conditionally drops type info #10897

simPod opened this issue Apr 18, 2024 · 0 comments

Comments

@simPod
Copy link
Contributor

simPod commented Apr 18, 2024

Bug report

I have a function

/**
 * @template Tk
 * @template Tv
 *
 * @param Generator<Tk, Tv, mixed, mixed> $generator
 *
 * @return iterable<Tk, Tv>
 */
function rewindable(Generator $generator): iterable;

I want to apply this function on a variable of type iterable when it's instance of Generator

$new = $old instanceof Generator ? rewindable($old) : $old;

$old is of type iterable<A,B> and I'd expect $new to be of the same type. However, the type info is lost and $new is of type iterable<mixed>.

Code snippet that reproduces the problem

https://phpstan.org/r/8e49d7cf-ee0f-4943-8c7c-d5e1cd8596b8

Expected output

L34: Dumped type: iterable<ToString>

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

No response

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

No branches or pull requests

1 participant