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

Use more accurate return type

This commit is contained in:
Matt Brown 2021-03-18 15:19:29 -04:00
parent b7a68edd0b
commit 42d3bceb4e
4 changed files with 25 additions and 3 deletions

View File

@ -494,7 +494,9 @@ class FunctionCallReturnTypeFetcher
$function_call_node = DataFlowNode::getForMethodReturn(
$function_id,
$function_id,
$function_storage->signature_return_type_location ?: $function_storage->location,
$statements_analyzer->data_flow_graph instanceof TaintFlowGraph
? ($function_storage->signature_return_type_location ?: $function_storage->location)
: ($function_storage->return_type_location ?: $function_storage->location),
$function_storage->specialize_call ? $node_location : null
);

View File

@ -431,7 +431,9 @@ class MethodCallReturnTypeFetcher
(string) $method_id,
$cased_method_id,
$is_declaring
? ($statements_analyzer->data_flow_graph instanceof TaintFlowGraph
? ($method_storage->signature_return_type_location ?: $method_storage->location)
: ($method_storage->return_type_location ?: $method_storage->location))
: null,
null
);

View File

@ -257,7 +257,9 @@ class StaticCallAnalyzer extends CallAnalyzer
$node_location = new CodeLocation($statements_analyzer->getSource(), $stmt);
$method_location = $method_storage
? ($statements_analyzer->data_flow_graph instanceof TaintFlowGraph
? ($method_storage->signature_return_type_location ?: $method_storage->location)
: ($method_storage->return_type_location ?: $method_storage->location))
: null;
if ($method_storage && $method_storage->specialize_call) {

View File

@ -3215,6 +3215,22 @@ class UnusedVariableTest extends TestCase
}',
'error_message' => 'MixedAssignment - src' . DIRECTORY_SEPARATOR . 'somefile.php:10:38 - Unable to determine the type that $a is being assigned to, derived from expression at src' . DIRECTORY_SEPARATOR . 'somefile.php:3:55'
],
'warnAboutDocblockReturnType' => [
'<?php
/** @return array[] */
function makeArray() : array {
return [["hello"]];
}
$arr = makeArray();
foreach ($arr as $some_arr) {
foreach ($some_arr as $a) {
echo $a;
}
}',
'error_message' => 'MixedAssignment - src' . DIRECTORY_SEPARATOR . 'somefile.php:10:47 - Unable to determine the type that $a is being assigned to, derived from expression at src' . DIRECTORY_SEPARATOR . 'somefile.php:2:33'
],
];
}
}