File tree Expand file tree Collapse file tree 3 files changed +47
-0
lines changed Expand file tree Collapse file tree 3 files changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -540,6 +540,18 @@ private static function unionWithSubtractedType(
540540 return $ type ;
541541 }
542542
543+ if ($ subtractedType instanceof SubtractableType) {
544+ $ withoutSubtracted = $ subtractedType ->getTypeWithoutSubtractedType ();
545+ if ($ withoutSubtracted ->isSuperTypeOf ($ type )->yes ()) {
546+ $ subtractedSubtractedType = $ subtractedType ->getSubtractedType ();
547+ if ($ subtractedSubtractedType === null ) {
548+ return new NeverType ();
549+ }
550+
551+ return self ::intersect ($ type , $ subtractedSubtractedType );
552+ }
553+ }
554+
543555 if ($ type instanceof SubtractableType) {
544556 $ subtractedType = $ type ->getSubtractedType () === null
545557 ? $ subtractedType
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types = 1 );
2+
3+ namespace Substracted ;
4+
5+
6+ use function PHPStan \Testing \assertType ;
7+
8+ class HelloWorld
9+ {
10+ public function sayHello (mixed $ date , bool $ foo ): void
11+ {
12+ if (is_object ($ date )){
13+
14+ } else {
15+ assertType ('mixed~object ' , $ date );
16+
17+ if ($ foo ) {
18+ $ date = new \stdClass ();
19+ }
20+ assertType ('mixed~object~stdClass ' , $ date );
21+
22+ if (is_object ($ date )) {
23+ assertType ('stdClass ' , $ date );
24+ }
25+ }
26+ }
27+ }
Original file line number Diff line number Diff line change @@ -4143,6 +4143,14 @@ public static function dataIntersect(): iterable
41434143 ObjectWithoutClassType::class,
41444144 'object ' ,
41454145 ],
4146+ [
4147+ [
4148+ new MixedType (subtractedType: new ObjectWithoutClassType (new ObjectType ('stdClass ' ))),
4149+ new ObjectWithoutClassType (),
4150+ ],
4151+ ObjectType::class,
4152+ 'stdClass ' ,
4153+ ],
41464154 ];
41474155
41484156 if (PHP_VERSION_ID < 80100 ) {
You can’t perform that action at this time.
0 commit comments