You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like the following code to be valid. Currently Psalm emits ArgumentTypeCoercion - 28:31 - Argument 1 of foo::dogetdayname expects int(1)|int(2)|int(3)|int(4)|int(5)|int(6)|int(7), parent type int provided
<?php
class foo
{
/** @var array<int,string> */
public const DAYS = [
1 => 'mon',
2 => 'tue',
3 => 'wed',
4 => 'thu',
5 => 'fri',
6 => 'sat',
7 => 'sun'
];
/** @param key-of<self::DAYS> $dayNum*/
private static function doGetDayName(int $dayNum): string
{
return self::DAYS[$dayNum];
}
/** @throws LogicException */
public static function getDayName(int $dayNum): string
{
if (! array_key_exists($dayNum, self::DAYS)) {
throw new \LogicException();
}
return self::doGetDayName($dayNum); // ArgumentTypeCoercion emitted here
}
}
I would like the following code to be valid. Currently Psalm emits
ArgumentTypeCoercion - 28:31 - Argument 1 of foo::dogetdayname expects int(1)|int(2)|int(3)|int(4)|int(5)|int(6)|int(7), parent type int provided
https://psalm.dev/r/8afe8ba4ea
For now we can work around this by adding
/** @var key-of<self::DAYS> $dayNum */
(https://psalm.dev/r/7cc1f58d92 )The text was updated successfully, but these errors were encountered: