@@ -140,13 +140,21 @@ public function setIsCallable(bool $is_callable): self
140
140
141
141
/**
142
142
* @param non-empty-array<string|int, Union> $properties
143
- * @return static
144
143
*/
145
- public function setProperties (array $ properties ): self
144
+ public function setProperties (array $ properties ): self | TArray
146
145
{
147
146
if ($ properties === $ this ->properties ) {
148
147
return $ this ;
149
148
}
149
+ if (count ($ properties ) === 1
150
+ && $ properties [array_key_first ($ properties )]->isNever ()
151
+ && ($ this ->fallback_params === null || $ this ->fallback_params [1 ]->isNever ())
152
+ ) {
153
+ $ never = $ properties [array_key_first ($ properties )];
154
+ return new TArray ([
155
+ $ never , $ never ,
156
+ ], $ this ->from_docblock );
157
+ }
150
158
$ cloned = clone $ this ;
151
159
$ cloned ->properties = $ properties ;
152
160
if ($ cloned ->is_list ) {
@@ -169,9 +177,6 @@ public function setProperties(array $properties): self
169
177
return $ cloned ;
170
178
}
171
179
172
- /**
173
- * @return static
174
- */
175
180
public function makeSealed (): self
176
181
{
177
182
if ($ this ->fallback_params === null ) {
@@ -543,9 +548,6 @@ public function getKey(bool $include_extra = true): string
543
548
return 'array ' ;
544
549
}
545
550
546
- /**
547
- * @return static
548
- */
549
551
#[Override]
550
552
public function replaceTemplateTypesWithStandins (
551
553
TemplateResult $ template_result ,
@@ -558,7 +560,7 @@ public function replaceTemplateTypesWithStandins(
558
560
bool $ replace = true ,
559
561
bool $ add_lower_bound = false ,
560
562
int $ depth = 0 ,
561
- ): self {
563
+ ): self | TArray {
562
564
if ($ input_type instanceof TKeyedArray
563
565
&& $ input_type ->is_list
564
566
&& $ input_type ->isSealed ()
@@ -581,6 +583,11 @@ public function replaceTemplateTypesWithStandins(
581
583
->type_params [1 ]
582
584
->setPossiblyUndefined (!$ this ->isNonEmpty ());
583
585
586
+ if ($ replaced_list_type ->isNever ()) {
587
+ return new TArray ([
588
+ $ replaced_list_type , $ replaced_list_type ,
589
+ ], $ this ->from_docblock );
590
+ }
584
591
$ cloned = clone $ this ;
585
592
$ cloned ->properties = [$ replaced_list_type ];
586
593
$ cloned ->fallback_params = [$ this ->fallback_params [1 ], $ replaced_list_type ];
@@ -647,20 +654,26 @@ public function replaceTemplateTypesWithStandins(
647
654
return $ this ;
648
655
}
649
656
$ cloned = clone $ this ;
657
+ if (count ($ properties ) === 1
658
+ && $ properties [array_key_first ($ properties )]->isNever ()
659
+ && ($ fallback_params === null || $ fallback_params [1 ]->isNever ())
660
+ ) {
661
+ $ never = $ properties [array_key_first ($ properties )];
662
+ return new TArray ([
663
+ $ never , $ never ,
664
+ ], $ this ->from_docblock );
665
+ }
650
666
$ cloned ->properties = $ properties ;
651
667
/** @psalm-suppress PropertyTypeCoercion */
652
668
$ cloned ->fallback_params = $ fallback_params ;
653
669
return $ cloned ;
654
670
}
655
671
656
- /**
657
- * @return static
658
- */
659
672
#[Override]
660
673
public function replaceTemplateTypesWithArgTypes (
661
674
TemplateResult $ template_result ,
662
675
?Codebase $ codebase ,
663
- ): self {
676
+ ): self | TArray {
664
677
$ properties = $ this ->properties ;
665
678
foreach ($ properties as $ offset => $ property ) {
666
679
$ properties [$ offset ] = TemplateInferredTypeReplacer::replace (
@@ -679,6 +692,15 @@ public function replaceTemplateTypesWithArgTypes(
679
692
}
680
693
if ($ properties !== $ this ->properties || $ fallback_params !== $ this ->fallback_params ) {
681
694
$ cloned = clone $ this ;
695
+ if (count ($ properties ) === 1
696
+ && $ properties [array_key_first ($ properties )]->isNever ()
697
+ && ($ fallback_params === null || $ fallback_params [1 ]->isNever ())
698
+ ) {
699
+ $ never = $ properties [array_key_first ($ properties )];
700
+ return new TArray ([
701
+ $ never , $ never ,
702
+ ], $ this ->from_docblock );
703
+ }
682
704
$ cloned ->properties = $ properties ;
683
705
/** @psalm-suppress PropertyTypeCoercion */
684
706
$ cloned ->fallback_params = $ fallback_params ;
0 commit comments