1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 12:24:49 +01:00

Fix #5025 - prevent crash in assert function during reflection

This commit is contained in:
Matt Brown 2021-01-17 12:08:19 -05:00 committed by Daniil Gentili
parent 245b944c85
commit 0107afb2fb
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
3 changed files with 34 additions and 1 deletions

View File

@ -297,7 +297,12 @@ class FunctionLikeNodeScanner
null
);
$negated_formula = \Psalm\Internal\Algebra::negateFormula($if_clauses);
try {
$negated_formula = \Psalm\Internal\Algebra::negateFormula($if_clauses);
} catch (\Psalm\Exception\ComplicatedExpressionException $e) {
$var_assertions = [];
break;
}
$rules = \Psalm\Internal\Algebra::getTruthsFromFormula($negated_formula);

View File

@ -1414,6 +1414,24 @@ class AssertAnnotationTest extends TestCase
}
?>'
],
'implicitComplexAssertionNoCrash' => [
'<?php
class Foo {
private string $status = "";
public function assertValidStatusTransition(string $status): void
{
if (
("canceled" === $this->status && "complete" === $status)
|| ("canceled" === $this->status && "pending" === $status)
|| ("complete" === $this->status && "canceled" === $status)
|| ("complete" === $this->status && "pending" === $status)
) {
throw new \LogicException();
}
}
}'
],
];
}

View File

@ -2385,6 +2385,16 @@ class PropertyTypeTest extends TestCase
[],
'8.0'
],
'dynamicPropertyFetch' => [
'<?php
class Foo {
public int $a = 0;
}
function takesFoo(?Foo $foo, string $b) : void {
echo $foo->{$b} ?? null;
}'
],
];
}