mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
Static call inside throw does not violate purity
This commit is contained in:
parent
7af771a006
commit
edb07952fc
@ -1011,25 +1011,27 @@ class StaticCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\
|
||||
return;
|
||||
}
|
||||
|
||||
if ($context->pure && !$method_storage->pure) {
|
||||
if (IssueBuffer::accepts(
|
||||
new ImpureMethodCall(
|
||||
'Cannot call an impure method from a pure context',
|
||||
new CodeLocation($source, $stmt->name)
|
||||
),
|
||||
$statements_analyzer->getSuppressedIssues()
|
||||
)) {
|
||||
// fall through
|
||||
}
|
||||
} elseif ($context->mutation_free && !$method_storage->mutation_free) {
|
||||
if (IssueBuffer::accepts(
|
||||
new ImpureMethodCall(
|
||||
'Cannot call an possibly-mutating method from a mutation-free context',
|
||||
new CodeLocation($source, $stmt->name)
|
||||
),
|
||||
$statements_analyzer->getSuppressedIssues()
|
||||
)) {
|
||||
// fall through
|
||||
if (!$context->inside_throw) {
|
||||
if ($context->pure && !$method_storage->pure) {
|
||||
if (IssueBuffer::accepts(
|
||||
new ImpureMethodCall(
|
||||
'Cannot call an impure method from a pure context',
|
||||
new CodeLocation($source, $stmt->name)
|
||||
),
|
||||
$statements_analyzer->getSuppressedIssues()
|
||||
)) {
|
||||
// fall through
|
||||
}
|
||||
} elseif ($context->mutation_free && !$method_storage->mutation_free) {
|
||||
if (IssueBuffer::accepts(
|
||||
new ImpureMethodCall(
|
||||
'Cannot call an possibly-mutating method from a mutation-free context',
|
||||
new CodeLocation($source, $stmt->name)
|
||||
),
|
||||
$statements_analyzer->getSuppressedIssues()
|
||||
)) {
|
||||
// fall through
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -278,6 +278,29 @@ class PureAnnotationTest extends TestCase
|
||||
|
||||
echo getTraceAsString(new Exception("test"));'
|
||||
],
|
||||
'callingMethodInThrowStillPure' => [
|
||||
'<?php
|
||||
final class MyException extends \Exception {
|
||||
public static function hello(): self
|
||||
{
|
||||
return new self();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @psalm-pure
|
||||
*/
|
||||
function sumExpectedToNotBlowPowerFuse(int $first, int $second): int {
|
||||
$sum = $first + $second;
|
||||
if ($sum > 9000) {
|
||||
throw MyException::hello();
|
||||
}
|
||||
if ($sum > 90001) {
|
||||
throw new MyException();
|
||||
}
|
||||
return $sum;
|
||||
}'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user