mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Suppressing NoValue should not treat subsequent code as unevaluated
Fix https://github.com/vimeo/psalm/issues/10302
This commit is contained in:
parent
b3ef6a0bd7
commit
dcd53cadab
@ -528,18 +528,18 @@ final class AssignmentAnalyzer
|
||||
}
|
||||
|
||||
if ($context->vars_in_scope[$var_id]->isNever()) {
|
||||
if (IssueBuffer::accepts(
|
||||
if (!IssueBuffer::accepts(
|
||||
new NoValue(
|
||||
'All possible types for this assignment were invalidated - This may be dead code',
|
||||
new CodeLocation($statements_analyzer->getSource(), $assign_var),
|
||||
),
|
||||
$statements_analyzer->getSuppressedIssues(),
|
||||
)) {
|
||||
return false;
|
||||
// if the error is suppressed, do not treat it as never anymore
|
||||
$context->vars_in_scope[$var_id] = Type::getMixed();
|
||||
$context->has_returned = false;
|
||||
}
|
||||
|
||||
$context->vars_in_scope[$var_id] = Type::getNever();
|
||||
|
||||
$context->inside_assignment = $was_in_assignment;
|
||||
|
||||
return $context->vars_in_scope[$var_id];
|
||||
|
@ -806,13 +806,16 @@ final class ArgumentAnalyzer
|
||||
}
|
||||
|
||||
if ($input_type->isNever()) {
|
||||
IssueBuffer::maybeAdd(
|
||||
if (!IssueBuffer::accepts(
|
||||
new NoValue(
|
||||
'All possible types for this argument were invalidated - This may be dead code',
|
||||
$arg_location,
|
||||
),
|
||||
$statements_analyzer->getSuppressedIssues(),
|
||||
);
|
||||
)) {
|
||||
// if the error is suppressed, do not treat it as exited anymore
|
||||
$context->has_returned = false;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
@ -476,13 +476,13 @@ class UnusedCodeTest extends TestCase
|
||||
return new a;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
final class b {
|
||||
public function test(): a {
|
||||
return new a;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function process(b $handler): a {
|
||||
if (\extension_loaded("fdsfdsfd")) {
|
||||
return $handler->test();
|
||||
@ -1323,6 +1323,38 @@ class UnusedCodeTest extends TestCase
|
||||
new A;
|
||||
PHP,
|
||||
],
|
||||
'callNeverReturnsSuppressed' => [
|
||||
'code' => '<?php
|
||||
namespace Foo;
|
||||
/**
|
||||
* @psalm-suppress InvalidReturnType
|
||||
* @return never
|
||||
*/
|
||||
function foo() : void {}
|
||||
|
||||
function bar(mixed $s) : string {
|
||||
return is_string($s) ? "hello" : "world";
|
||||
}
|
||||
|
||||
/** @psalm-suppress NoValue */
|
||||
$a = foo();
|
||||
print_r($a);',
|
||||
],
|
||||
'useNeverReturnsAsArgSuppressed' => [
|
||||
'code' => '<?php
|
||||
namespace Foo;
|
||||
/**
|
||||
* @psalm-suppress InvalidReturnType
|
||||
* @return never
|
||||
*/
|
||||
function foo() : void {}
|
||||
|
||||
function bar(mixed $s) : void {}
|
||||
|
||||
/** @psalm-suppress NoValue */
|
||||
bar(foo());
|
||||
echo "hello";',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user