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
Cannot suppress UnnecessaryVarAnnotation #3573
Comments
I found these snippets: https://psalm.dev/r/35a6f3cc6a<?php
/**
* @param class-string $class
* @psalm-suppress UnnecessaryVarAnnotation
*/
function foo(string $class): Foo {
if (!is_subclass_of($class, Foo::class)) {
throw new \LogicException();
}
/** @psalm-suppress UnnecessaryVarAnnotation */
/**
* @psalm-suppress UnnecessaryVarAnnotation
* @var Foo $instance
* @psalm-suppress UnnecessaryVarAnnotation
*/
$instance = new $class();
return $instance;
}
|
This: https://psalm.dev/r/7711914ceb not working looks lie a bug to me. |
I found these snippets: https://psalm.dev/r/7711914ceb<?php
class Foo {}
/**
* @param class-string $class
*/
function foo(string $class): Foo {
if (!is_subclass_of($class, Foo::class)) {
throw new \LogicException();
}
/**
* @psalm-suppress UnnecessaryVarAnnotation
* @var Foo $instance
*/
$instance = new $class();
return $instance;
}
|
Looks like same issue is for InvalidDocBlock https://psalm.dev/r/cdc465928b |
I found these snippets: https://psalm.dev/r/cdc465928b<?php
/**
* @template T as (object|array<string, mixed>)
*/
abstract class Provider
{
/**
* @param mixed[]|object $entity
* @psalm-param T $entity
*
* @return mixed[]
*/
abstract protected function collectDataToReindexRow($entity): array;
}
/** @psalm-suppress InvalidDocblock */
/**
* @psalm-suppress InvalidDocblock
* @extends Provider<(array<string, mixed>>)>
*/
class A extends Provider
{
protected function collectDataToReindexRow($row): array
{
return [];
}
}
|
Don't really know why this was closed without any comment. So just for others who run into this. I found out how to suppress this: https://psalm.dev/r/b3c4b437cb The suppress docblock should be right above the code line.
|
I found these snippets: https://psalm.dev/r/b3c4b437cb<?php
class Foo {}
/**
* @param class-string $class
*/
function foo(string $class): Foo {
if (!is_subclass_of($class, Foo::class)) {
throw new \LogicException();
}
/** @var Foo $instance */
/** @psalm-suppress UnnecessaryVarAnnotation */
$instance = new $class();
return $instance;
}
|
This issue isn't fixed. Please, check first snippet. |
@muglug, thanks in advance. |
The PR above should fix the issue. @martindilling just FYI, your fix was not really a fix. The suppression was not effective, but neither was the @var because it was not above the code anymore. So you indirectly fixed the issue by removing what Psalm was complaining about 😄 |
https://psalm.dev/r/35a6f3cc6a
The text was updated successfully, but these errors were encountered: