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

False positive InvalidTemplateParam when use "static" as Template Param #11199

Open
darkdarin opened this issue Jan 13, 2025 · 1 comment
Open

Comments

@darkdarin
Copy link

Example:
https://psalm.dev/r/f8c1600e03

Result:
ERROR: InvalidTemplateParam - 20:8 - Extended template param TModel expects type Model, type static given

Expects:
No errors.

Phpstan example: https://phpstan.org/r/b6e3f530-00ef-4bf5-9610-59bacad09f8d

Copy link

I found these snippets:

https://psalm.dev/r/f8c1600e03
<?php
/**
 * @template TModel of Model
 */
trait HasCollection {
    /**
     * @return list<TModel>
     */
 	public function get(): array 
    {
		return [];
	}
}

class Model
{
    /**
	 * @use HasCollection<static>
     */
  	use HasCollection;
}

class MyClass extends Model {
}

$class = new MyClass();
$result = $class->get();

/** @psalm-trace $result */
Psalm output (using commit 765dcbf):

INFO: Trace - 29:28 - $result: list<MyClass&static>

INFO: UnusedVariable - 27:1 - $result is never referenced or the value is not used

ERROR: InvalidTemplateParam - 20:8 - Extended template param TModel expects type Model, type static given

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