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

MixedAssignment error when checking type with elseif instead of if #10516

Open
theodorejb opened this issue Dec 22, 2023 · 1 comment
Open

MixedAssignment error when checking type with elseif instead of if #10516

theodorejb opened this issue Dec 22, 2023 · 1 comment

Comments

@theodorejb
Copy link
Contributor

https://psalm.dev/r/64f44812c4

This code pattern unexpectedly outputs a MixedAssignment error. If the elseif is replaced with if (which doesn't change the logic), the MixedAssignment error goes away.

Copy link

I found these snippets:

https://psalm.dev/r/64f44812c4
<?php

function returnsArray(): array {
    return ["foo" => 42];
}

foreach (returnsArray() as $key => $value) {
    if ($key !== "foo") {
     	throw new Exception("Unexpected array key");   
    }
    elseif (!is_int($value)) {
     	throw new Exception("Unexpected array value");   
    }

    /** @psalm-trace $value */
    echo $value * 3;
}
Psalm output (using commit a75d26a):

INFO: MixedAssignment - 7:36 - Unable to determine the type that $value is being assigned to

INFO: Trace - 16:5 - $value: int

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