Skip to content

Commit

Permalink
Revert "Fix #3631 - apply assertions to RHS of equality in conditional"
Browse files Browse the repository at this point in the history
This reverts commit 9c17795.
  • Loading branch information
muglug committed Jun 23, 2020
1 parent fc8212e commit 1f86afe
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 39 deletions.
3 changes: 2 additions & 1 deletion src/Psalm/Internal/Analyzer/FunctionAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ public static function getReturnTypeFromCallMapWithArgs(
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()
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,29 +123,6 @@ public static function scrapeAssertions(
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,
Expand All @@ -162,6 +139,20 @@ public static function scrapeAssertions(
}
}

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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ public static function fetch(

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;
Expand Down
14 changes: 0 additions & 14 deletions tests/TypeReconciliation/ConditionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2781,20 +2781,6 @@ function sayHi(string $greeting): void {
$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);
}'
],
];
}

Expand Down

0 comments on commit 1f86afe

Please sign in to comment.