Skip to content

Fix invokable objects incorrectly labeled as instances of Closure#4797

Open
HypeMC wants to merge 1 commit intophpstan:2.1.xfrom
HypeMC:fix-13975
Open

Fix invokable objects incorrectly labeled as instances of Closure#4797
HypeMC wants to merge 1 commit intophpstan:2.1.xfrom
HypeMC:fix-13975

Conversation

@HypeMC
Copy link

@HypeMC HypeMC commented Jan 21, 2026

@HypeMC HypeMC force-pushed the fix-13975 branch 8 times, most recently from a02e586 to 6d1e13c Compare January 22, 2026 04:07
if (
$this->isCallable()->yes()
&& $otherType->isCallable()->yes()
&& !($otherType->isObject()->yes() && $otherType->isInstanceOf(Closure::class)->yes())
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ondrejmirtes Hi, I'm not sure how to proceed here. I tried using instanceof, but PHPStan said I should use isObject() instead. Now I'm getting this error. Any advice?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see other similar spots in the codebase.
it need to look like (new ObjectType(Closure::class))->isSuperTypeOf(...)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@staabm Thank you for the help, it seems ok now.

$this->assertNoErrors($errors);
}

public function testBug13975(): void
Copy link
Contributor

@staabm staabm Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

your test needs to be moved into a *RuleTest which relates to the error message you no longer want to have.

AnalyzerIntegrationTest is reserved for performance and crash-tests

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess an additional test like https://phpstan.org/r/3cdd0efb-d240-49dd-9073-d1ada4d9843e might kill the mutant

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems you lost the original test-case while adding the new one.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry, I misunderstood you, fixed

@HypeMC HypeMC force-pushed the fix-13975 branch 6 times, most recently from 1a0435a to 47220f6 Compare February 5, 2026 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Invokable objects incorrectly labeled as instances of \Closure

2 participants