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:
parent
245b944c85
commit
0107afb2fb
@ -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);
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user