File tree Expand file tree Collapse file tree 3 files changed +22
-2
lines changed Expand file tree Collapse file tree 3 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -987,7 +987,7 @@ public static function intersect(Type ...$types): Type
987
987
$ newArray ->setOffsetValueType (
988
988
self ::intersect ($ keyType , $ types [$ j ]->getIterableKeyType ()),
989
989
self ::intersect ($ valueTypes [$ k ], $ types [$ j ]->getIterableValueType ()),
990
- $ types [$ i ]->isOptionalKey ($ k ),
990
+ $ types [$ i ]->isOptionalKey ($ k ) && ! $ types [ $ j ]-> hasOffsetValueType ( $ keyType )-> yes () ,
991
991
);
992
992
}
993
993
$ types [$ i ] = $ newArray ->getArray ();
@@ -1003,7 +1003,7 @@ public static function intersect(Type ...$types): Type
1003
1003
$ newArray ->setOffsetValueType (
1004
1004
self ::intersect ($ keyType , $ types [$ i ]->getIterableKeyType ()),
1005
1005
self ::intersect ($ valueTypes [$ k ], $ types [$ i ]->getIterableValueType ()),
1006
- $ types [$ j ]->isOptionalKey ($ k ),
1006
+ $ types [$ j ]->isOptionalKey ($ k ) && ! $ types [ $ i ]-> hasOffsetValueType ( $ keyType )-> yes () ,
1007
1007
);
1008
1008
}
1009
1009
$ types [$ j ] = $ newArray ->getArray ();
Original file line number Diff line number Diff line change @@ -1129,6 +1129,7 @@ public function dataFileAsserts(): iterable
1129
1129
yield from $ this ->gatherAssertTypes (__DIR__ . '/../Rules/Variables/data/bug-8113.php ' );
1130
1130
yield from $ this ->gatherAssertTypes (__DIR__ . '/data/phpunit-integration.php ' );
1131
1131
yield from $ this ->gatherAssertTypes (__DIR__ . '/data/bug-8361.php ' );
1132
+ yield from $ this ->gatherAssertTypes (__DIR__ . '/data/bug-8373.php ' );
1132
1133
}
1133
1134
1134
1135
/**
Original file line number Diff line number Diff line change
1
+ <?php declare (strict_types = 1 );
2
+
3
+ namespace Bug8373 ;
4
+
5
+ use function PHPStan \Testing \assertType ;
6
+
7
+ function (string $ one , string $ two ): string {
8
+ $ args = [$ one , $ two ];
9
+
10
+ assertType ('array{string, string} ' , $ args );
11
+ assertType ('array{0?: non-falsy-string, 1?: non-falsy-string} ' , array_filter ($ args ));
12
+
13
+ \assert (array_filter ($ args ) === $ args );
14
+
15
+ assertType ('array{non-falsy-string, non-falsy-string} ' , $ args );
16
+ assertType ('array{non-falsy-string, non-falsy-string} ' , array_filter ($ args ));
17
+
18
+ return $ args [1 ];
19
+ };
You can’t perform that action at this time.
0 commit comments