1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Revert "Fix #3631 - apply assertions to RHS of equality in conditional"

This reverts commit 9c17795545.
This commit is contained in:
Brown 2020-06-22 20:01:27 -04:00
parent fc8212e207
commit 1f86afece7
4 changed files with 18 additions and 39 deletions

View File

@ -193,7 +193,8 @@ class FunctionAnalyzer extends FunctionLikeAnalyzer
return clone $array_type->type_param;
}
} elseif ($first_arg_type->hasScalarType()
&& ($second_arg = ($call_args[1]->value ?? null))
&& isset($call_args[1])
&& ($second_arg = $call_args[1]->value)
&& ($second_arg_type = $statements_analyzer->node_data->getType($second_arg))
&& $second_arg_type->hasScalarType()
) {

View File

@ -123,29 +123,6 @@ class AssertionFinder
return $if_types;
}
if ($conditional instanceof PhpParser\Node\Expr\Assign) {
$var_name = ExpressionIdentifier::getArrayVarId(
$conditional->var,
$this_class_name,
$source
);
$if_types = self::scrapeAssertions(
$conditional->expr,
$this_class_name,
$source,
$codebase,
$inside_negation,
$cache
);
if ($var_name) {
$if_types[$var_name] = [['!falsy']];
}
return $if_types;
}
$var_name = ExpressionIdentifier::getArrayVarId(
$conditional,
$this_class_name,
@ -162,6 +139,20 @@ class AssertionFinder
}
}
if ($conditional instanceof PhpParser\Node\Expr\Assign) {
$var_name = ExpressionIdentifier::getArrayVarId(
$conditional->var,
$this_class_name,
$source
);
if ($var_name) {
$if_types[$var_name] = [['!falsy']];
}
return $if_types;
}
if ($conditional instanceof PhpParser\Node\Expr\BooleanNot) {
$expr_assertions = null;

View File

@ -85,7 +85,8 @@ class MethodCallReturnTypeFetcher
if (InternalCallMapHandler::inCallMap((string) $call_map_id)) {
if (($template_result->upper_bounds || $class_storage->stubbed)
&& ($method_storage = ($class_storage->methods[$method_id->method_name] ?? null))
&& isset($class_storage->methods[$method_id->method_name])
&& ($method_storage = $class_storage->methods[$method_id->method_name])
&& $method_storage->return_type
) {
$return_type_candidate = clone $method_storage->return_type;

View File

@ -2781,20 +2781,6 @@ class ConditionalTest extends \Psalm\Tests\TestCase
$a->format("d-m-Y");
}',
],
'applyTruthyAssertionsToRightHandSideOfAssignment' => [
'<?php
function takesAString(string $name): void {}
function randomReturn(): ?string {
return rand(1,2) === 1 ? "foo" : null;
}
$name = randomReturn();
if ($foo = ($name !== null)) {
takesAString($name);
}'
],
];
}