-
Notifications
You must be signed in to change notification settings - Fork 651
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
Annotate "insert element" operation on TKeyedArray #4193
Comments
I found these snippets: https://psalm.dev/r/ef60918b5a<?php
/**
* @template T of array{id: int}
*
* @param T $arr
* @param-out T&array{bar: string} $arr
* @return void
**/
function addBar(array &$arr): void {
$arr['bar'] = 'bar';
}
$arr1 = ['id' => 1, 'foo' => 'foo'];
$arr2 = ['id' => 2, 'baz' => 'baz'];
addBar($arr1);
addBar($arr2);
|
At least the message is wrong, as |
I was referring to the
It's self-contradicting, as |
The message was changed, so this is no longer a bug, rather a enhancement |
I have a function that accept an
TKeyedArray
and insert a specific element into it. For example, given a input $arr which is in type of@template T of array{id: int}
, after having operation like$arr['baz'] = 'baz';
the output should becomesT & array{'baz':string}
.https://psalm.dev/r/ef60918b5a
I found a similar issue #3339 that describes a more general situation, but don't know if there is a solution for this case.
The text was updated successfully, but these errors were encountered: