Invalidate property types after dynamic method calls#5679
Conversation
VincentLanglet
left a comment
There was a problem hiding this comment.
Lot of these changes are wrong.
The issue is with the snippet
class Template {
public $footer = [];
public function render() : string {
$content = '';
$this->footer = [];
// START TEMPLATE COMPILER
$this->{'compileSection'}(); // dynamic code
// END TEMPLATE COMPILER
if (count($this->footer) > 0) {
$content = str_replace('some', 'thing', $content);
}
return $content;
}
private function compileSection(): void {
$this->footer[] = 'section-name';
}
}
$this->compileSection() invalidate correctly but
$this->{'compileSection'} or $this->{$someThing}() does not invalidate
|
Looking at bug-5501 and bug-6473, the test expectation changes in the original PR are correct. In bug-5501, The reviewer's feedback was specifically about the dynamic method call gap. The fix I made addresses that by adding full invalidation for unknown/dynamic method calls in the The changes are committed and pushed. Here's a summary: Fix: Added Tests: Added test cases for both the NSRT test ( Verification: All 12077 tests pass, |
VincentLanglet
left a comment
There was a problem hiding this comment.
Revert the first commit and only keep the second one, about invalidating after dynamic call
Dynamic method calls like `$this->{'compileSection'}()` or
`$this->{$variable}()` could not be resolved to a method reflection,
so the else branch (unknown method) did not invalidate the callee
expression. Since we cannot determine what the method does, treat it
like a method with certain side effects and fully invalidate.
Closes phpstan/phpstan#3831
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
d2c6680 to
afce9d0
Compare
|
Done. I reverted the first commit (constant scalar property invalidation after maybe-impure calls) and kept only the dynamic method call invalidation fix. The branch now has a single clean commit that:
|
VincentLanglet
left a comment
There was a problem hiding this comment.
load nsrt file in the RuleTest to avoid duplicates fixtures files
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Done. I merged the rule test fixture into the existing NSRT file (adding the |
Summary
Fixes phpstan/phpstan#3831