File tree Expand file tree Collapse file tree 2 files changed +42
-22
lines changed
tests/PHPStan/Rules/Methods/data Expand file tree Collapse file tree 2 files changed +42
-22
lines changed Original file line number Diff line number Diff line change @@ -517,33 +517,23 @@ public static function selectFromArgs(
517517 if ($ originalArg ->unpack ) {
518518 $ unpack = true ;
519519 $ constantArrays = $ type ->getConstantArrays ();
520- $ expanded = false ;
521520 if (count ($ constantArrays ) > 0 ) {
522- $ allStringKeys = true ;
523521 foreach ($ constantArrays as $ constantArray ) {
524- foreach ($ constantArray ->getKeyTypes () as $ keyType ) {
525- if (!$ keyType ->isString ()->yes ()) {
526- $ allStringKeys = false ;
527- break 2 ;
528- }
529- }
530- }
531- if ($ allStringKeys ) {
532- foreach ($ constantArrays as $ constantArray ) {
533- foreach ($ constantArray ->getKeyTypes () as $ j => $ keyType ) {
534- $ keyName = $ keyType ->getValue ();
535- if (!isset ($ types [$ keyName ])) {
536- $ types [$ keyName ] = $ constantArray ->getValueTypes ()[$ j ];
537- } else {
538- $ types [$ keyName ] = TypeCombinator::union ($ types [$ keyName ], $ constantArray ->getValueTypes ()[$ j ]);
539- }
522+ foreach ($ constantArray ->getKeyTypes () as $ j => $ keyType ) {
523+ $ valueType = $ constantArray ->getValueTypes ()[$ j ];
524+ $ valueIndex = $ keyType ->getValue ();
525+ if (is_string ($ valueIndex )) {
526+ $ hasName = true ;
527+ } else {
528+ $ valueIndex = $ i + $ j ;
540529 }
530+
531+ $ types [$ valueIndex ] = isset ($ types [$ valueIndex ])
532+ ? TypeCombinator::union ($ types [$ valueIndex ], $ valueType )
533+ : $ valueType ;
541534 }
542- $ hasName = true ;
543- $ expanded = true ;
544535 }
545- }
546- if (!$ expanded ) {
536+ } else {
547537 $ types [$ index ] = $ type ->getIterableValueType ();
548538 }
549539 } else {
Original file line number Diff line number Diff line change @@ -20,3 +20,33 @@ public function __construct(
2020}
2121
2222$ a = new A (...['x ' => 5 , 'y ' => 'b ' ]);
23+
24+ $ aa = new A (...[5 , 'y ' => 'b ' ]);
25+
26+ $ aaa = new A (...[5 , 'b ' ]);
27+
28+ $ aaaa = new A (...[1 => 5 , 2 => 'b ' ]);
29+
30+ /**
31+ * @template Y of 'a'|'b'
32+ */
33+ class B
34+ {
35+ /**
36+ * @param Y $y
37+ */
38+ public function __construct (
39+ public readonly int $ init ,
40+ public readonly int $ x ,
41+ public readonly string $ y = 'a ' ,
42+ ) {
43+ }
44+ }
45+
46+ $ a = new B (1 , ...['x ' => 5 , 'y ' => 'b ' ]);
47+
48+ $ aa = new B (1 , ...[5 , 'y ' => 'b ' ]);
49+
50+ $ aaa = new B (1 , ...[5 , 'b ' ]);
51+
52+ $ aaaa = new B (1 , ...[1 => 5 , 2 => 'b ' ]);
You can’t perform that action at this time.
0 commit comments