Skip to content
Permalink
Browse files

Allow multiple @psalm-assert annotations for a given variable

  • Loading branch information
muglug committed Dec 9, 2019
1 parent aaffdbc commit 74de32fefe504516119390035a4941374a8bcecd
@@ -3444,7 +3444,14 @@ protected static function applyAssertionsToContext(
}
}
} else {
$type_assertions[$assertion_var_id] = $assertion->rule;
if (isset($type_assertions[$assertion_var_id])) {
$type_assertions[$assertion_var_id] = array_merge(
$type_assertions[$assertion_var_id],
$assertion->rule
);
} else {
$type_assertions[$assertion_var_id] = $assertion->rule;
}
}
} elseif ($arg_value && ($assertion->rule === [['!falsy']] || $assertion->rule === [['true']])) {
if ($assertion->rule === [['true']]) {
@@ -862,6 +862,29 @@ function bar(?string $s) : string {
}',
'error_message' => 'TypeDoesNotContainType',
],
'assertScalarAndEmpty' => [
'<?php
/**
* @param mixed $value
* @psalm-assert scalar $value
* @psalm-assert !empty $value
*/
function assertScalarNotEmpty($value) : void {}
/** @param scalar $s */
function takesScalar($s) : void {}
/**
* @param mixed $bar
*/
function foo($bar) : void {
assertScalarNotEmpty($bar);
takesScalar($bar);
if ($bar) {}
}',
'error_message' => 'RedundantCondition - src/somefile.php:19:29',
],
];
}
}

0 comments on commit 74de32f

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