File tree Expand file tree Collapse file tree 5 files changed +40
-3
lines changed Expand file tree Collapse file tree 5 files changed +40
-3
lines changed Original file line number Diff line number Diff line change @@ -527,7 +527,8 @@ private function processStmtNode(
527
527
throw new ShouldNotHappenException ();
528
528
}
529
529
530
- if ($ stmt ->name ->toLowerString () === '__construct ' ) {
530
+ $ isFromTrait = $ stmt ->getAttribute ('originalTraitMethodName ' ) === '__construct ' ;
531
+ if ($ stmt ->name ->toLowerString () === '__construct ' || $ isFromTrait ) {
531
532
foreach ($ stmt ->params as $ param ) {
532
533
if ($ param ->flags === 0 ) {
533
534
continue ;
@@ -548,6 +549,7 @@ private function processStmtNode(
548
549
$ phpDoc ,
549
550
$ phpDocParameterTypes [$ param ->var ->name ] ?? null ,
550
551
true ,
552
+ $ isFromTrait ,
551
553
$ param ,
552
554
false ,
553
555
$ scope ->isInTrait (),
@@ -723,6 +725,7 @@ private function processStmtNode(
723
725
$ docComment ,
724
726
$ phpDocType ,
725
727
false ,
728
+ false ,
726
729
$ prop ,
727
730
$ isReadOnly ,
728
731
$ scope ->isInTrait (),
Original file line number Diff line number Diff line change @@ -118,12 +118,12 @@ public function getUninitializedProperties(
118
118
continue ;
119
119
}
120
120
$ originalProperties [$ property ->getName ()] = $ property ;
121
- $ is = TrinaryLogic::createFromBoolean ($ property ->isPromoted ());
121
+ $ is = TrinaryLogic::createFromBoolean ($ property ->isPromoted () && ! $ property -> isPromotedFromTrait () );
122
122
$ initialInitializedProperties [$ property ->getName ()] = $ is ;
123
123
foreach ($ constructors as $ constructor ) {
124
124
$ initializedProperties [$ constructor ][$ property ->getName ()] = $ is ;
125
125
}
126
- if ($ property ->isPromoted ()) {
126
+ if ($ property ->isPromoted () && ! $ property -> isPromotedFromTrait () ) {
127
127
continue ;
128
128
}
129
129
$ uninitializedProperties [$ property ->getName ()] = $ property ;
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ public function __construct(
22
22
private ?string $ phpDoc ,
23
23
private ?Type $ phpDocType ,
24
24
private bool $ isPromoted ,
25
+ private bool $ isPromotedFromTrait ,
25
26
Node $ originalNode ,
26
27
private bool $ isReadonlyByPhpDoc ,
27
28
private bool $ isDeclaredInTrait ,
@@ -52,6 +53,11 @@ public function isPromoted(): bool
52
53
return $ this ->isPromoted ;
53
54
}
54
55
56
+ public function isPromotedFromTrait (): bool
57
+ {
58
+ return $ this ->isPromotedFromTrait ;
59
+ }
60
+
55
61
public function getPhpDoc (): ?string
56
62
{
57
63
return $ this ->phpDoc ;
Original file line number Diff line number Diff line change @@ -24,3 +24,17 @@ public function __construct(
24
24
$ this ->__traitConstruct ($ message );
25
25
}
26
26
}
27
+
28
+ class SpecializedException2
29
+ {
30
+ use StringableMessageTrait {
31
+ StringableMessageTrait::__construct as __traitConstruct;
32
+ }
33
+
34
+ public function __construct (
35
+ public int $ code ,
36
+ string $ message ,
37
+ ) {
38
+ //$this->__traitConstruct($message);
39
+ }
40
+ }
Original file line number Diff line number Diff line change @@ -213,4 +213,18 @@ public function testBug7649(): void
213
213
]);
214
214
}
215
215
216
+ public function testBug9577 (): void
217
+ {
218
+ if (PHP_VERSION_ID < 80100 ) {
219
+ $ this ->markTestSkipped ('Test requires PHP 8.1. ' );
220
+ }
221
+
222
+ $ this ->analyse ([__DIR__ . '/../Classes/data/bug-9577.php ' ], [
223
+ [
224
+ 'Class Bug9577\SpecializedException2 has an uninitialized readonly property $message. Assign it in the constructor. ' ,
225
+ 8 ,
226
+ ],
227
+ ]);
228
+ }
229
+
216
230
}
You can’t perform that action at this time.
0 commit comments