Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix counting array properties when some are Never #6971

Merged
merged 1 commit into from Nov 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -341,10 +341,18 @@ private static function getReturnTypeFromCallMapWithArgs(
$min = 0;
$max = 0;
foreach ($atomic_types['array']->properties as $property) {
if (!$property->possibly_undefined) {
// empty, never and possibly undefined can't count for min value
if (!$property->possibly_undefined
&& !$property->isEmpty()
&& !$property->isNever()
) {
$min++;
}
$max++;

//empty and never can't count for max value because we know keys are undefined
if (!$property->isEmpty() && !$property->isNever()) {
$max++;
}
}

if ($atomic_types['array']->sealed) {
Expand Down
14 changes: 13 additions & 1 deletion tests/TypeReconciliation/RedundantConditionTest.php
Expand Up @@ -867,7 +867,19 @@ public function get(): ?stdClass{ return new stdClass;}
}
'
]
],
'countWithNeverValuesInKeyedArray' => [
'<?php
/** @var non-empty-array $report_data */
$report_data = [];
if ( array_key_exists( "A", $report_data ) ) {
} elseif ( !empty( $report_data[0]["type"] ) && rand(0,1) ) {
if ( rand(0,1) ) {}
if ( count( $report_data ) === 1 ) {
}
}'
],
];
}

Expand Down