1
0
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:
kkmuffme 2023-10-21 13:52:22 +02:00
parent b3ef6a0bd7
commit dcd53cadab
3 changed files with 43 additions and 8 deletions

View File

@ -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];

View File

@ -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;
}

View File

@ -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";',
],
];
}