1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Fix #2977 - make MixedAssignment message a bit more clear, hopefully

This commit is contained in:
Matthew Brown 2020-03-15 23:20:12 -04:00
parent c85fa9083d
commit a8a1142889
2 changed files with 13 additions and 3 deletions

View File

@ -343,10 +343,20 @@ class AssignmentAnalyzer
&& !strpos($root_var_id ?? '', '->')
&& !$comment_type
) {
$assign_value_id = $assign_value
? ExpressionAnalyzer::getArrayVarId(
$assign_value,
$statements_analyzer->getFQCLN(),
$statements_analyzer
)
: null;
if (IssueBuffer::accepts(
new MixedAssignment(
'Cannot assign' . ($var_id ? ' ' . $var_id . ' ' : ' ') . 'to a mixed type',
new CodeLocation($statements_analyzer->getSource(), $assign_var)
$var_id
? 'Unable to determine the type that ' . $var_id . ' is being assigned to'
: 'Unable to determine the type of this assignment',
new CodeLocation($statements_analyzer->getSource(), $assign_value ?: $assign_var)
),
$statements_analyzer->getSuppressedIssues()
)) {

View File

@ -1181,7 +1181,7 @@ class ReturnTypeTest extends TestCase
$res = map(function(int $i): string { return (string) $i; })([1,2,3]);
',
'error_message' => 'MixedAssignment - src/somefile.php:10:51 - Cannot assign $value to a mixed type',
'error_message' => 'MixedAssignment - src/somefile.php:10:51 - Unable to determine the type that $value is being assigned to',
],
'cannotInferReturnClosureWithMoreSpecificTypes' => [
'<?php