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
Native return type conflicting with parent declaration, while docbloc type with same definition accepted #8660
Comments
I found these snippets: https://psalm.dev/r/e51bdf311a<?php
/** @template-covariant TValue of scalar|DateTimeImmutable */
abstract class Field
{
/** @psalm-return TValue|null */
abstract public function from(mixed $value): mixed;
}
/** @extends Field<string> */
class EnumField extends Field
{
public function from(mixed $value): string|null
{
if ($value === null) {
return null;
}
return (string) $value;
}
}
|
I think it's Psalm failing to correctly infer the type of the template when it's redefined in a child class. The return type of I'm not sure where this should be fixed though |
Is there any way this can be reduced further, perhaps? 🤔 We have suspicions, but we don't know what's going on precisely. /cc @guidobonuzzi |
Well, this shows the same thing: https://psalm.dev/r/57e10b684b with every unnecessary thing stripped (and I replaced null with bool just in case) I really think it's an issue with TValue just being dropped by Psalm's inference. |
I found these snippets: https://psalm.dev/r/57e10b684b<?php
/** @template TValue */
abstract class Field
{
/** @psalm-return TValue|bool */
abstract public function from(mixed $value): mixed;
}
/** @extends Field<string> */
class EnumField extends Field
{
public function from(mixed $value): string|bool
{
return 'a';
}
}
|
I'm surprised but it seems to have been fixed :) |
It was thanks to #8926, which fixed a bug I introduced earlier when I improved the intersection logic :) |
Given following example ( https://psalm.dev/r/e51bdf311a ), psalm seems to infer the incorrect types in
EnumField::fromMixedToValue()
Adding an
/** @return string|null */
solves the issue:I wonder if type inference is overriding native types here? 🤔
The text was updated successfully, but these errors were encountered: