Skip to content
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

UnusedParam false-positive when other issues before #11186

Open
homersimpsons opened this issue Dec 14, 2024 · 1 comment
Open

UnusedParam false-positive when other issues before #11186

homersimpsons opened this issue Dec 14, 2024 · 1 comment

Comments

@homersimpsons
Copy link

On the following code, psalm reports an UnusedParam for $userid and $error:

https://github.com/BOINC/boinc/blob/275a2a42b7004e84cb4245161211ce0a99bec7cf/html/inc/pm.inc#L113-L209

I do not really understand why, because the $userid param is used on:

https://github.com/BOINC/boinc/blob/275a2a42b7004e84cb4245161211ce0a99bec7cf/html/inc/pm.inc#L145

If you want to run psalm in the html/ directory above, it will take ~40 minutes. By trying to reduce the code I came to (https://psalm.dev/r/0a1e623634):

function pm_form_page($replyto, $userid) {
    if ($replyto) {
        $userid = 'a';
        User::lookup_id($userid);
    } elseif ($userid) {
        $user = User::lookup_id($userid);
    }
}

which highlight the same issue. But I do not know if this is the same root cause. Note that the issue disappears if I add the following above:

class User {
    public static function lookup_id($userid) {}
}

I searched if this issue was already reported but it looks like no. There are other issues about UnusedParam false-positive, but they seem to be about other cases.

Copy link

I found these snippets:

https://psalm.dev/r/0a1e623634
<?php

// class User {
//     public static function lookup_id($userid) {}
// }

function pm_form_page($replyto, $userid) {
    if ($replyto) {
        $userid = 'a';
        User::lookup_id($userid);
    } elseif ($userid) {
        $user = User::lookup_id($userid);
    }
}
Psalm output (using commit a9b5291):

ERROR: UndefinedClass - 10:9 - Class, interface or enum named User does not exist

INFO: MissingParamType - 7:23 - Parameter $replyto has no provided type

INFO: MissingParamType - 7:33 - Parameter $userid has no provided type

INFO: UnusedParam - 7:33 - Param userid is never referenced in this method

INFO: MissingReturnType - 7:10 - Method pm_form_page does not have a return type, expecting void

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant