mirror of
https://github.com/danog/psalm.git
synced 2024-12-02 09:37:59 +01:00
Fix #2442 - using asserting after a MixedAssignment
removes that error
This commit is contained in:
parent
5f4d797fe1
commit
4de6f5c4ec
@ -682,6 +682,14 @@ class FunctionCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expressio
|
|||||||
);
|
);
|
||||||
|
|
||||||
foreach ($changed_var_ids as $var_id => $_) {
|
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])) {
|
if (isset($op_vars_in_scope[$var_id])) {
|
||||||
$op_vars_in_scope[$var_id]->from_docblock = true;
|
$op_vars_in_scope[$var_id]->from_docblock = true;
|
||||||
}
|
}
|
||||||
|
@ -3596,6 +3596,14 @@ class CallAnalyzer
|
|||||||
|
|
||||||
foreach ($changed_var_ids as $var_id => $_) {
|
foreach ($changed_var_ids as $var_id => $_) {
|
||||||
if (isset($op_vars_in_scope[$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;
|
$op_vars_in_scope[$var_id]->from_docblock = true;
|
||||||
|
|
||||||
foreach ($op_vars_in_scope[$var_id]->getAtomicTypes() as $changed_atomic_type) {
|
foreach ($op_vars_in_scope[$var_id]->getAtomicTypes() as $changed_atomic_type) {
|
||||||
|
@ -240,6 +240,23 @@ class IssueBuffer
|
|||||||
return true;
|
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
|
public static function addFixableIssue(string $issue_type) : void
|
||||||
{
|
{
|
||||||
if (isset(self::$fixable_issue_counts[$issue_type])) {
|
if (isset(self::$fixable_issue_counts[$issue_type])) {
|
||||||
|
@ -242,6 +242,15 @@ echo $a;';
|
|||||||
'line' => 6,
|
'line' => 6,
|
||||||
'error' => '"hello"',
|
'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)',
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user