Skip to content

Commit 791e708

Browse files
committed
Optimize scalar values in oversized constant arrays
1 parent 9cd58b5 commit 791e708

File tree

3 files changed

+1208
-0
lines changed

3 files changed

+1208
-0
lines changed

Diff for: src/Type/TypeCombinator.php

+4
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,10 @@ private static function optimizeConstantArrays(array $types): array
843843
return TypeCombinator::intersect($type, new OversizedArrayType());
844844
}
845845

846+
if ($type instanceof ConstantScalarType) {
847+
return $type->generalize(GeneralizePrecision::moreSpecific());
848+
}
849+
846850
return $traverse($type);
847851
});
848852
$valueTypes[$generalizedValueType->describe(VerbosityLevel::precise())] = $generalizedValueType;

Diff for: tests/PHPStan/Analyser/AnalyserIntegrationTest.php

+6
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,12 @@ public function testBug7637(): void
913913
$this->assertSame(57, $errors[2]->getLine());
914914
}
915915

916+
public function testBug12671(): void
917+
{
918+
$errors = $this->runAnalyse(__DIR__ . '/data/bug-12671.php');
919+
$this->assertNoErrors($errors);
920+
}
921+
916922
public function testBug7737(): void
917923
{
918924
$errors = $this->runAnalyse(__DIR__ . '/data/bug-7737.php');

0 commit comments

Comments
 (0)