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
Strange array<empty, empty> type inference #5799
Labels
Comments
I found these snippets: https://psalm.dev/r/cf250aab5b<?php
/** @template T */
class Option
{
/** @param T $v */
public function __construct(private $v) {}
/**
* @template E
* @param E $else
* @return T|E
*/
public function getOrElse($else)
{
return random_int(0, 1) === 1 ? $this->v : $else;
}
}
$opt = new Option([1, 2]);
/** @psalm-trace $opt */
$res = $opt->getOrElse([]);
/** @psalm-trace $res */
|
Interestingly, this doesn't happen with standard ternaries for example Nor when the templates are from the same method: |
I found these snippets: https://psalm.dev/r/d05df407f7<?php
$c = rand(0,1) ? [1, 2] : [];
/** @psalm-trace $c */;
https://psalm.dev/r/d811b083c3<?php
/**
* @template T of array
* @template E of array
* @param E $else
* @param T $if
* @return T|E
*/
function getOrElse($if, $else)
{
return rand(0, 1) ? $if : $else;
}
$opt = getOrElse([], [1, 2]);
/** @psalm-trace $opt */
|
Great, my case was fixed too! Thanks! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://psalm.dev/r/cf250aab5b
$res
should bearray{1, 2}|array<empty, empty>
or like that.The text was updated successfully, but these errors were encountered: