1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Fix #2442 - using asserting after a MixedAssignment removes that error

This commit is contained in:
Matthew Brown 2020-02-08 23:01:45 -05:00
parent 5f4d797fe1
commit 4de6f5c4ec
4 changed files with 42 additions and 0 deletions

View File

@ -682,6 +682,14 @@ class FunctionCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expressio
);
foreach ($changed_var_ids as $var_id => $_) {
if ($first_appearance = $statements_analyzer->getFirstAppearance($var_id)) {
IssueBuffer::remove(
$statements_analyzer->getFilePath(),
'MixedAssignment',
$first_appearance->raw_file_start
);
}
if (isset($op_vars_in_scope[$var_id])) {
$op_vars_in_scope[$var_id]->from_docblock = true;
}

View File

@ -3596,6 +3596,14 @@ class CallAnalyzer
foreach ($changed_var_ids as $var_id => $_) {
if (isset($op_vars_in_scope[$var_id])) {
if ($first_appearance = $statements_analyzer->getFirstAppearance($var_id)) {
IssueBuffer::remove(
$statements_analyzer->getFilePath(),
'MixedAssignment',
$first_appearance->raw_file_start
);
}
$op_vars_in_scope[$var_id]->from_docblock = true;
foreach ($op_vars_in_scope[$var_id]->getAtomicTypes() as $changed_atomic_type) {

View File

@ -240,6 +240,23 @@ class IssueBuffer
return true;
}
public static function remove(string $file_path, string $issue_type, int $file_offset) : void
{
if (!isset(self::$issues_data[$file_path])) {
return;
}
$filtered_issues = [];
foreach (self::$issues_data[$file_path] as $issue) {
if ($issue['type'] !== $issue_type || $issue['from'] !== $file_offset) {
$filtered_issues[] = $issue;
}
}
self::$issues_data[$file_path] = $filtered_issues;
}
public static function addFixableIssue(string $issue_type) : void
{
if (isset(self::$fixable_issue_counts[$issue_type])) {

View File

@ -242,6 +242,15 @@ echo $a;';
'line' => 6,
'error' => '"hello"',
],
'assertCancelsMixedAssignment' => [
'<?php
$a = $_GET["hello"];
assert(is_int($a));
if (is_int($a)) {}',
'message' => "Found a redundant condition when evaluating docblock-defined type \$a and trying to reconcile type 'int' to int",
'line' => 4,
'error' => 'is_int($a)',
],
];
}
}