-
Notifications
You must be signed in to change notification settings - Fork 660
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
param-out not taken into account when using generics #8891
Comments
I found these snippets: https://psalm.dev/r/654392acdb<?php
/**
* @template T of positive-int
*/
class X {
/**
* @param-out T $s
*/
function addFoo(mixed &$s) : void {
}
}
function f3($z) {
$x = new X();
$x->addFoo($z);
/** @psalm-trace $z */
}
|
The snippet seems outdated and does not illustrate the issue. |
You're right, I made a copy-paste mistake when examining another issue 😅 Thanks for pointing that out! Here is what I meant to post: https://psalm.dev/r/e46c3120a6 |
I found these snippets: https://psalm.dev/r/e46c3120a6<?php
/**
* @template T of int
*/
class X {
/**
* @param-out T $s
*/
function addFoo(string &$s): void {
$s = 42;
}
}
|
While |
That makes sense I think, but then, does this also makes sense: https://psalm.dev/r/bb313a293d There is no implementation here, so I think in this particular case Psalm should say nothing. |
I found these snippets: https://psalm.dev/r/bb313a293d<?php
/**
* @template T of int
*/
abstract class X {
/**
* @param-out T $s
*/
abstract function addFoo(string &$s): void;
}
|
No, that doesn't make much sense to me (of course, it should be |
Should it? If the param enters the method as Here is an example: https://github.com/doctrine/lexer/blob/2.0.x/tests/ConcreteLexer.php (not sure how realistic it is though, I known |
Here is an example with just Psalm: https://psalm.dev/r/b7de7cfb93 |
I found these snippets: https://psalm.dev/r/b7de7cfb93<?php
/**
* @template T of int
*/
abstract class X {
/**
* @param-out T $s
*/
abstract function addFoo(string &$s): void;
}
/**
* @extends X<int>
*/
class Y extends X
{
public function addFoo(string &$s): void
{
$s = 42;
}
}
|
Actual issue: #8891 (comment)
Psalm doesn't seem to realize that 42 is an integer here:
https://psalm.dev/r/654392acdb
It is suggesting to use
param-out
, which is confusing as I'm already using it.The text was updated successfully, but these errors were encountered: