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
Ensure we recognize inherited static methods for the first-class callables #8370
Conversation
The original example from the issue still doesn't work: it says
|
I found these snippets: https://psalm.dev/r/0a4421aa23<?php
/** @template T */
class Holder
{
/** @param T $value */
public function __construct(public $value) {}
}
abstract class A
{
final public function __construct(public int $i) {}
/** @return Holder<static> */
public static function create(int $i): Holder
{
return new Holder(new static($i));
}
}
class C extends A
{
}
/** @param \Closure(int):Holder<C> $_ */
function takesIntToHolder(\Closure $_): void {}
takesIntToHolder(C::create(...));
|
…st-class callables
…the first-class callables
Okay, so I managed to fix my exact case in the last commit, however it still feels like a hack and duplicated efforts. Needless to say it will suffer from other Perhaps the proper way to implement the first-class callables is first to desugar them into a closure, or maybe a |
It's one of the feature that was implemented after Matt departed from the project, so sadly, it's possible it was added without a "big picture" mindset at the time. Frankly, if you feel refactoring it would be best and you're up for it, go ahead! Now is the best moment to do so, Psalm 5 was not yet released so implementation changes won't bother anyone depending on it |
Ok, however obviously I have even less vision than you do, by a lot. Each such fix for me is a debugging exercise, and frankly I only fix those problems which I encounter myself, to solve my immediate problem :P I suggest to merge this one then, but with the proper refactoring kept in mind, WDYT? |
There's a few modules in Psalm I know and I can pinpoint some issues, but aside from that, I'm really the same. For example, I'm pretty sure you know more than me about static issues because I never went check how it works and it would take me a lot of time too :) I'm up to merge this :) |
@orklah pingie 👉👈 |
Thanks! |
fixes #8363
I have a strong feeling it's not the correct place where this functionality should belong.
For now first-class callables are implemented in the StaticCallAnalyzer just because they look like a static call syntax-wise (and are such from the perspective of
nikic/php-parser
). However, I am not sure where they should really belong: ClosureAnalyzer also seems odd here.