-
Notifications
You must be signed in to change notification settings - Fork 653
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
Having MethodSignatureMismatch when a trait method has the return type 'static', but is overriden in a trait #8673
Comments
I found these snippets: https://psalm.dev/r/c655b72643<?php
/**
* @template E of mixed
*/
trait SomeTrait {
/** @return static */
public function get(): static {
return $this;
}
}
trait SomeOtherTrait {
/** @return static */
public function get(): static {
return $this;
}
}
/**
* @template E o of mixed
*/
class SomeClass {
/** @use SomeTrait<E> */
use SomeTrait;
}
/**
* @template E o of mixed
* @extends SomeClass<E>
*/
class SomeOtherClass extends SomeClass {
use SomeOtherTrait;
}
|
It may be a check to avoid this: https://3v4l.org/bfbC0 in older php versions and we missed the change somehow? |
Yeah, most likely. I remember that used to be an annoying issue, but im using 8.1, so it should be fine. |
Unfortunately, I have like 0 practice with traits so I'm easily confused, especially with advanced usage. I dug a little, the issue is emitted from here:
I noticed a php > 8 check, so I went looking for the change that introduced it, and it is here: So, my previous explanation seems wrong. We had a I'd say it's a wrongly inferred mismatch, possibly due to having static inferrence inside traits (that confuses me even more ><) |
To make matters a bit more complicated @orklah, there are multiple traits involved in my specific use case. There's a The full hierarchy is:
|
That being said, there is no mismatch. Since the return type is |
Any methods that I have in traits that have a return type of
static
, which are overridden in a later trait, are giving meMethodSignatureMismatch
errors, saying that it should return the trait, which isn't possible.Here's an example error.
Here's the recreation: https://psalm.dev/r/c655b72643
The text was updated successfully, but these errors were encountered: