File tree Expand file tree Collapse file tree 3 files changed +2695
-0
lines changed Expand file tree Collapse file tree 3 files changed +2695
-0
lines changed Original file line number Diff line number Diff line change @@ -897,6 +897,10 @@ private static function optimizeConstantArrays(array $types): array
897
897
$ keyType = self ::union (...$ keyTypes );
898
898
$ valueType = self ::union (...$ valueTypes );
899
899
900
+ if ($ valueType instanceof UnionType && count ($ valueType ->getTypes ()) > ConstantArrayTypeBuilder::ARRAY_COUNT_LIMIT ) {
901
+ $ valueType = $ valueType ->generalize (GeneralizePrecision::lessSpecific ());
902
+ }
903
+
900
904
$ arrayType = new ArrayType ($ keyType , $ valueType );
901
905
if ($ eachIsList ) {
902
906
$ arrayType = self ::intersect ($ arrayType , new AccessoryArrayListType ());
Original file line number Diff line number Diff line change @@ -1510,6 +1510,16 @@ public function testBug12627(): void
1510
1510
$ this ->assertNoErrors ($ errors );
1511
1511
}
1512
1512
1513
+ public function testBug12159 (): void
1514
+ {
1515
+ if (PHP_VERSION_ID < 80300 ) {
1516
+ $ this ->markTestSkipped ('Test requires PHP 8.3. ' );
1517
+ }
1518
+
1519
+ $ errors = $ this ->runAnalyse (__DIR__ . '/data/bug-12159.php ' );
1520
+ $ this ->assertNoErrors ($ errors );
1521
+ }
1522
+
1513
1523
/**
1514
1524
* @param string[]|null $allAnalysedFiles
1515
1525
* @return Error[]
You can’t perform that action at this time.
0 commit comments