1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Fix #2742 - prevent paradoxes in assert calls

This commit is contained in:
Matthew Brown 2020-02-09 11:42:41 -05:00
parent 4de6f5c4ec
commit 3559fdd6b3
2 changed files with 18 additions and 4 deletions

View File

@ -660,6 +660,16 @@ class FunctionCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expressio
$codebase
);
$cond_assigned_var_ids = [];
\Psalm\Internal\Analyzer\AlgebraAnalyzer::checkForParadox(
$context->clauses,
$assert_clauses,
$statements_analyzer,
$stmt,
$cond_assigned_var_ids
);
$simplified_clauses = Algebra::simplifyCNF(array_merge($context->clauses, $assert_clauses));
$assert_type_assertions = Algebra::getTruthsFromFormula($simplified_clauses);
@ -674,7 +684,12 @@ class FunctionCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expressio
$assert_type_assertions,
$context->vars_in_scope,
$changed_var_ids,
[],
array_map(
function ($v) {
return true;
},
$assert_type_assertions
),
$statements_analyzer,
$statements_analyzer->getTemplateTypeMap() ?: [],
$context->inside_loop,

View File

@ -429,13 +429,12 @@ class EmptyTest extends \Psalm\Tests\TestCase
}',
'error_message' => 'MixedReturnTypeCoercion'
],
'SKIPPED-secondEmptyTwice' => [
'secondEmptyTwice' => [
'<?php
/**
* @param array{a?:int,b?:string} $p
* @return non-empty-array
*/
function f(array $p):array {
function f(array $p) : void {
if (empty($p)) {
throw new RuntimeException("");
}