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

Always report MissingTemplateParam when template params are not provided #10878

Open
BenMorel opened this issue Apr 3, 2024 · 1 comment
Open

Comments

@BenMorel
Copy link
Contributor

BenMorel commented Apr 3, 2024

I just realized that Psalm doesn't complain if you declare a class with template params, and use it somewhere without providing these params:

/**
 * @template K
 * @template V
 */
class Map
{
}

/**
 * @param Map $map
 */
function test(Map $map): void
{
}

https://psalm.dev/r/6b7f6de782
https://psalm.dev/r/7ee714cedb

I could not find an option to make Psalm complain in this case. Would it be possible to add it?

Copy link

I found these snippets:

https://psalm.dev/r/6b7f6de782
<?php

/**
 * @template K
 * @template V
 */
class Map
{
}

/**
 * @param Map $map
 */
function test(Map $map): void
{
    /** @psalm-trace $map */
}
Psalm output (using commit ef3b018):

INFO: Trace - 16:0 - $map: Map

INFO: UnusedParam - 14:19 - Param map is never referenced in this method
https://psalm.dev/r/7ee714cedb
<?php

/**
 * @template K of object
 * @template V
 */
class Map
{
}

/**
 * @param Map $map
 */
function test(Map $map): void
{
    /** @psalm-trace $map */
}
Psalm output (using commit ef3b018):

INFO: Trace - 16:0 - $map: Map<object, mixed>

INFO: UnusedParam - 14:19 - Param map is never referenced in this method

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