diff --git a/src/Psalm/Checker/Statements/Block/IfChecker.php b/src/Psalm/Checker/Statements/Block/IfChecker.php index a7a99afaa..0e70f0fe2 100644 --- a/src/Psalm/Checker/Statements/Block/IfChecker.php +++ b/src/Psalm/Checker/Statements/Block/IfChecker.php @@ -180,7 +180,7 @@ class IfChecker $if_context->inside_conditional = false; - $mixed_var_ids = []; + $mixed_var_ids = ['$_GET', '$_POST']; foreach ($if_context->vars_in_scope as $var_id => $type) { if ($type->isMixed()) { @@ -871,7 +871,7 @@ class IfChecker $elseif_context->inside_conditional = false; - $mixed_var_ids = []; + $mixed_var_ids = ['$_GET', '$_POST']; foreach ($elseif_context->vars_in_scope as $var_id => $type) { if ($type->isMixed()) { diff --git a/src/Psalm/Checker/Statements/Expression/BinaryOpChecker.php b/src/Psalm/Checker/Statements/Expression/BinaryOpChecker.php index 5659a746d..1a9fa88fb 100644 --- a/src/Psalm/Checker/Statements/Expression/BinaryOpChecker.php +++ b/src/Psalm/Checker/Statements/Expression/BinaryOpChecker.php @@ -283,7 +283,7 @@ class BinaryOpChecker $statements_checker ); - $mixed_var_ids = []; + $mixed_var_ids = ['$_GET', '$_POST']; foreach ($context->vars_in_scope as $var_id => $type) { if ($type->isMixed()) { diff --git a/src/Psalm/Checker/Statements/Expression/TernaryChecker.php b/src/Psalm/Checker/Statements/Expression/TernaryChecker.php index 4f6ea38fc..936c04397 100644 --- a/src/Psalm/Checker/Statements/Expression/TernaryChecker.php +++ b/src/Psalm/Checker/Statements/Expression/TernaryChecker.php @@ -45,6 +45,43 @@ class TernaryChecker $statements_checker ); + $mixed_var_ids = ['$_GET', '$_POST']; + + foreach ($context->vars_in_scope as $var_id => $type) { + if ($type->isMixed()) { + $mixed_var_ids[] = $var_id; + } + } + + foreach ($context->vars_possibly_in_scope as $var_id => $_) { + if (!isset($context->vars_in_scope[$var_id])) { + $mixed_var_ids[] = $var_id; + } + } + + + $if_clauses = array_values( + array_map( + /** + * @return \Psalm\Clause + */ + function (\Psalm\Clause $c) use ($mixed_var_ids) { + $keys = array_keys($c->possibilities); + + foreach ($keys as $key) { + foreach ($mixed_var_ids as $mixed_var_id) { + if (preg_match('/^' . preg_quote($mixed_var_id, '/') . '(\[|-)/', $key)) { + return new \Psalm\Clause([], true); + } + } + } + + return $c; + }, + $if_clauses + ) + ); + $ternary_clauses = Algebra::simplifyCNF(array_merge($context->clauses, $if_clauses)); $negated_clauses = Algebra::negateFormula($if_clauses); diff --git a/src/Psalm/Checker/StatementsChecker.php b/src/Psalm/Checker/StatementsChecker.php index d06cdc05d..93beb12b2 100644 --- a/src/Psalm/Checker/StatementsChecker.php +++ b/src/Psalm/Checker/StatementsChecker.php @@ -1055,7 +1055,7 @@ class StatementsChecker extends SourceChecker implements StatementsSource return $context->vars_in_scope[$const_name]; } - $file_path = $statements_checker->getFilePath(); + $file_path = $statements_checker->getRootFilePath(); $project_checker = $statements_checker->getFileChecker()->project_checker; $file_storage_provider = $project_checker->file_storage_provider; diff --git a/tests/IssetTest.php b/tests/IssetTest.php index 35c5a575b..7d6d2744b 100644 --- a/tests/IssetTest.php +++ b/tests/IssetTest.php @@ -334,6 +334,13 @@ class IssetTest extends TestCase if ($arr[$k][0]) {} }', ], + 'mixedArrayIsset' => [ + ' [], + 'error_levels' => ['MixedAssignment', 'MixedArrayAccess'], + ], ]; }