Repository navigation
fix(unused-code): a method verified to return $this has no unused return value - #14337
Conversation
…urn value vimeo#13989 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
✅ Performance: unchanged · Types: unchanged
How to read this table
head 4955d0b · base f4609f6 (merge-base) · workflow run |
|
Behaviour change
|
orklah
left a comment
There was a problem hiding this comment.
Thanks, the direction is right: returns_this is the verified contract, and the gate in checkMethodReferences() is the right place.
One gap with the same cause: an override that inherits the parent's @return $this without repeating the annotation is still reported, although ReturnAnalyzer::mustReturnThis() already forces its body to return $this:
class ParentQ {
/** @return $this */
public function a() { echo "p"; return $this; }
/** @return $this */
public function b() { echo "b"; return $this; }
}
final class ChildQ extends ParentQ {
public function a(): static { return $this->b(); } // PossiblyUnusedReturnValue (base and this PR)
}
(new ChildQ())->a();
(new ParentQ())->a();
(new ParentQ())->b();Using the same check as the return analysis fixes it:
&& ($method_storage->is_static
|| !($method_storage->probably_fluent
|| ReturnAnalyzer::mustReturnThis($codebase, $method_storage, $method_id)))Could you switch to that and add this case to testValidCode?
…#13989 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@orklah thanks, done in 4955d0b: Your snippet is the new valid case |
Psalm reports
PossiblyUnusedReturnValuefor a method declared@return $thiswhose body returns another fluent call.Before
After
Fixes #13989