psalm icon indicating copy to clipboard operation
psalm copied to clipboard

issue with psalm-assert and unions

Open mathroc opened this issue 1 year ago • 1 comments

https://psalm.dev/r/0531bb69bd

Don't know if it's one or two issues:

  1. When calling Psalm complains that "$o - object does not contain class-string<DateTime>" but since the assert is for class-string<DateTime>|DateTime and $o is an object it should be fine
  2. Post call, the infered type for $o is class-string<DateTime>|DateTime (taken from the assert) but it should be (class-string<DateTime>|DateTime)&object (the assert type & the initial type) and should resolve to DateTime

mathroc avatar Sep 25 '24 10:09 mathroc

I found these snippets:

https://psalm.dev/r/0531bb69bd
<?php

function doSomeMath(int $number): int
{
    return $number ** 2;
}

$squared = doSomeMath(3);
assert($squared === 9);
Psalm output (using commit 16b24bd):

No issues!

psalm-github-bot[bot] avatar Sep 25 '24 10:09 psalm-github-bot[bot]