mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 12:55:26 +01:00
Use more accurate return type
This commit is contained in:
parent
b7a68edd0b
commit
42d3bceb4e
@ -494,7 +494,9 @@ class FunctionCallReturnTypeFetcher
|
|||||||
$function_call_node = DataFlowNode::getForMethodReturn(
|
$function_call_node = DataFlowNode::getForMethodReturn(
|
||||||
$function_id,
|
$function_id,
|
||||||
$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
|
$function_storage->specialize_call ? $node_location : null
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -431,7 +431,9 @@ class MethodCallReturnTypeFetcher
|
|||||||
(string) $method_id,
|
(string) $method_id,
|
||||||
$cased_method_id,
|
$cased_method_id,
|
||||||
$is_declaring
|
$is_declaring
|
||||||
|
? ($statements_analyzer->data_flow_graph instanceof TaintFlowGraph
|
||||||
? ($method_storage->signature_return_type_location ?: $method_storage->location)
|
? ($method_storage->signature_return_type_location ?: $method_storage->location)
|
||||||
|
: ($method_storage->return_type_location ?: $method_storage->location))
|
||||||
: null,
|
: null,
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
|
@ -257,7 +257,9 @@ class StaticCallAnalyzer extends CallAnalyzer
|
|||||||
$node_location = new CodeLocation($statements_analyzer->getSource(), $stmt);
|
$node_location = new CodeLocation($statements_analyzer->getSource(), $stmt);
|
||||||
|
|
||||||
$method_location = $method_storage
|
$method_location = $method_storage
|
||||||
|
? ($statements_analyzer->data_flow_graph instanceof TaintFlowGraph
|
||||||
? ($method_storage->signature_return_type_location ?: $method_storage->location)
|
? ($method_storage->signature_return_type_location ?: $method_storage->location)
|
||||||
|
: ($method_storage->return_type_location ?: $method_storage->location))
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
if ($method_storage && $method_storage->specialize_call) {
|
if ($method_storage && $method_storage->specialize_call) {
|
||||||
|
@ -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'
|
'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'
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user