Skip to content
Permalink
Browse files

Deal with a reconciled var more accurately

Ref #2426
  • Loading branch information
muglug committed Jan 6, 2020
1 parent cd0d118 commit 8e786a17dd22ad3b4601b5302d162870c0ebdd23
@@ -471,6 +471,10 @@ private static function scrapeEqualityAssertions(
$source
);

if ($var_name && $base_conditional instanceof PhpParser\Node\Expr\Assign) {
$var_name = '=' . $var_name;
}

$var_type = $source->node_data->getType($base_conditional);

if ($var_name) {
@@ -670,6 +670,10 @@ public static function combineOredClauses(array $left_clauses, array $right_clau
}

foreach ($left_clause->possibilities as $var => $possible_types) {
if (isset($right_clause->redefined_vars[$var])) {
continue;
}

if (isset($possibilities[$var])) {
$possibilities[$var] = array_merge($possibilities[$var], $possible_types);
} else {
@@ -2498,6 +2498,31 @@ function foo(): int {
return 0;
}',
],
'SKIPPED-assertHardConditional' => [
'<?php
interface Convertor {
function maybeConvert(string $value): ?SomeObject;
}
interface SomeObject {
function isValid(): bool;
}
/**
* @param mixed $value
*/
function exampleWithOr(Convertor $convertor, $value): SomeObject
{
if (!\is_string($value)
|| ($value = $convertor->maybeConvert($value)) === null
|| !$value->isValid()
) {
throw new Exception();
}
return $value;
}'
],
];
}

0 comments on commit 8e786a1

Please sign in to comment.
You can’t perform that action at this time.