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 ($context->vars_in_scope[$var_id]->isNever()) {
|
||||||
if (IssueBuffer::accepts(
|
if (!IssueBuffer::accepts(
|
||||||
new NoValue(
|
new NoValue(
|
||||||
'All possible types for this assignment were invalidated - This may be dead code',
|
'All possible types for this assignment were invalidated - This may be dead code',
|
||||||
new CodeLocation($statements_analyzer->getSource(), $assign_var),
|
new CodeLocation($statements_analyzer->getSource(), $assign_var),
|
||||||
),
|
),
|
||||||
$statements_analyzer->getSuppressedIssues(),
|
$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;
|
$context->inside_assignment = $was_in_assignment;
|
||||||
|
|
||||||
return $context->vars_in_scope[$var_id];
|
return $context->vars_in_scope[$var_id];
|
||||||
|
@ -806,13 +806,16 @@ final class ArgumentAnalyzer
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($input_type->isNever()) {
|
if ($input_type->isNever()) {
|
||||||
IssueBuffer::maybeAdd(
|
if (!IssueBuffer::accepts(
|
||||||
new NoValue(
|
new NoValue(
|
||||||
'All possible types for this argument were invalidated - This may be dead code',
|
'All possible types for this argument were invalidated - This may be dead code',
|
||||||
$arg_location,
|
$arg_location,
|
||||||
),
|
),
|
||||||
$statements_analyzer->getSuppressedIssues(),
|
$statements_analyzer->getSuppressedIssues(),
|
||||||
);
|
)) {
|
||||||
|
// if the error is suppressed, do not treat it as exited anymore
|
||||||
|
$context->has_returned = false;
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -476,13 +476,13 @@ class UnusedCodeTest extends TestCase
|
|||||||
return new a;
|
return new a;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final class b {
|
final class b {
|
||||||
public function test(): a {
|
public function test(): a {
|
||||||
return new a;
|
return new a;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function process(b $handler): a {
|
function process(b $handler): a {
|
||||||
if (\extension_loaded("fdsfdsfd")) {
|
if (\extension_loaded("fdsfdsfd")) {
|
||||||
return $handler->test();
|
return $handler->test();
|
||||||
@ -1323,6 +1323,38 @@ class UnusedCodeTest extends TestCase
|
|||||||
new A;
|
new A;
|
||||||
PHP,
|
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