Avoid warning about non-nullable class-property in traits. - #6100
Conversation
|
Note: the failing tests seem unrelated to those changes |
|
@ondrejmirtes any opinion about this? I will have time in the upcoming days to make adjustments if needed. Thanks! Regards |
Credit: made with the help of Opus 5. Fixes phpstan/phpstan#14416
|
@SanderMuller any opinion about this PR? I will have time in the upcoming days to make adjustments if needed. Thanks in advance! Best regards |
|
I'm not a maintainer, so this isn't an approval — but you asked, and the PR deserved a proper look, so I checked it out and ran it. Hopefully this makes the decision cheap for @ondrejmirtes. It does what it says. I ran the issue reproducer as a real analysis on // MyTrait.php
trait MyTrait {
public function a(): bool { return isset($this->i); }
public function b(): bool { return empty($this->i); }
public function c(): int { return $this->i ?? -1; }
}
// MyClass.php class MyClass { use MyTrait; public int $i = 10; }
// MyClass2.php class MyClass2 { use MyTrait; }Same input, PR's base commit ( So #14416 is fixed. ( It doesn't over-suppress. Control case — same shape, but every using class declares the property non-nullable: trait AllSetTrait { public function m(): bool { return isset($this->k); } }
class A1 { use AllSetTrait; public int $k = 1; }
class A2 { use AllSetTrait; public int $k = 2; }→ still reported, once per context: which is the behaviour you'd want, and matches the Tests. The three touched suites pass (96 tests), and The two red CI jobs are unrelated — I read the logs rather than assuming:
So your "seem unrelated" note holds on both counts. Re: the #5479 feedback — the tests now use Two things worth an explicit decision from @ondrejmirtes — design calls, not defects:
Two cosmetic notes, take or leave: the #5309 rules cache Nothing I found looks like a blocker. Thanks for sticking with this one since April — the fixture in particular is a nice piece of work. @staabm what do you think? |
Credit: made with the help of Opus 5.
Fixes phpstan/phpstan#14416
This supersedes #5479