-
Notifications
You must be signed in to change notification settings - Fork 650
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
Fix #3036: make argument $read of internal PHP function stream_socket nullable. #7718
Conversation
I'm not sure if types in callmap for parameters that are references refers to the Your change makes Psalm build fail because it's using the function without checking for null, but I suspect it can never return null (as |
TBH, I don't really know how to use this function, and I though just mapping the CallMap with the PHP doc would be sufficient... To me, it can take NULL and it can return NULL : https://3v4l.org/4QKQt My question is "can it take NULL but out as an array of streams?" and "can it take an array of streams but out as NULL ?". |
The fact that it can return null is enough to say Psalm should check against this, so this seem legit. Can you add checks in Psalm code then? |
I'm not familiar enough with Psalm internal architecture to know where I can add a test for this. Which location do you want for it? I'll write the test where you advice me. Thanks |
No test needed, but Psalm uses the function internally and your changes makes it fail on CI Can you check error in Psalm in the "Run Shepherd" job? It should point you to specific pieces of codes where "null" case should be handled |
Ok, thanks. I casted the usage of it in a Also, I upated the historical CallMap as it provoked an error in the unit tests executed. The error on the job "Pull Request Labels / label", on the other hand, looks like out of my hands, unless you can help me figure out what I've done wrong? |
@orklah It's probably not possible to have an I'm pretty sure for each of the 3 Edit: Actually it does work! You just have to ignore the |
That's weird that this error pops up... |
@niconoe- could you add the stub for |
Sorry, I don't think I have the capabilities of adding such stub. Maybe @AndrolGenhald can give it a try? |
I found these snippets: https://psalm.dev/r/50ec07381c<?php
/**
* @template TRead of null|array<array-key, resource>
* @template TWrite of null|array<array-key, resource>
* @template TExcept of null|array<array-key, resource>
*
* @param TRead $read
* @param TWrite $write
* @param TExcept $except
*
* @return false|int<0, max>
* @param-out (TRead is null ? null : array<array-key, resource>) $read
* @param-out (TWrite is null ? null : array<array-key, resource>) $write
* @param-out (TExcept is null ? null : array<array-key, resource>) $except
*
* @psalm-suppress ReferenceConstraintViolation
*/
function _stream_select(
?array &$read,
?array &$write,
?array &$except,
?int $seconds,
?int $microseconds = null
) {
return false;
}
/** @var list<resource> */
$r = [];
$w = null;
/** @var list<resource>|null */
$e = [];
_stream_select($r, $w, $e, 1);
/** @psalm-trace $r, $w, $e */;
|
Done. Thank you for the help 👍 EDIT: As the CallMap is reset, the array casting on |
I found these snippets: https://psalm.dev/r/50ec07381c<?php
/**
* @template TRead of null|array<array-key, resource>
* @template TWrite of null|array<array-key, resource>
* @template TExcept of null|array<array-key, resource>
*
* @param TRead $read
* @param TWrite $write
* @param TExcept $except
*
* @return false|int<0, max>
* @param-out (TRead is null ? null : array<array-key, resource>) $read
* @param-out (TWrite is null ? null : array<array-key, resource>) $write
* @param-out (TExcept is null ? null : array<array-key, resource>) $except
*
* @psalm-suppress ReferenceConstraintViolation
*/
function _stream_select(
?array &$read,
?array &$write,
?array &$except,
?int $seconds,
?int $microseconds = null
) {
return false;
}
/** @var list<resource> */
$r = [];
$w = null;
/** @var list<resource>|null */
$e = [];
_stream_select($r, $w, $e, 1);
/** @psalm-trace $r, $w, $e */;
|
Thanks! |
According to documentation: https://www.php.net/manual/en/function.stream-select.php