mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Fix #1437 - use correct return type line for error
This commit is contained in:
parent
85f0fa6e7d
commit
c800fb9282
@ -1666,6 +1666,8 @@ class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements PhpParse
|
|||||||
if ($parser_return_type) {
|
if ($parser_return_type) {
|
||||||
$suffix = '';
|
$suffix = '';
|
||||||
|
|
||||||
|
$original_type = $parser_return_type;
|
||||||
|
|
||||||
if ($parser_return_type instanceof PhpParser\Node\NullableType) {
|
if ($parser_return_type instanceof PhpParser\Node\NullableType) {
|
||||||
$suffix = '|null';
|
$suffix = '|null';
|
||||||
$parser_return_type = $parser_return_type->type;
|
$parser_return_type = $parser_return_type->type;
|
||||||
@ -1690,10 +1692,7 @@ class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements PhpParse
|
|||||||
|
|
||||||
$storage->return_type_location = new CodeLocation(
|
$storage->return_type_location = new CodeLocation(
|
||||||
$this->file_scanner,
|
$this->file_scanner,
|
||||||
$stmt,
|
$original_type
|
||||||
null,
|
|
||||||
false,
|
|
||||||
CodeLocation::FUNCTION_RETURN_TYPE
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($stmt->returnsByRef()) {
|
if ($stmt->returnsByRef()) {
|
||||||
|
@ -137,14 +137,12 @@ echo $a;';
|
|||||||
'message' => 'Could not verify return type \'string|null\' for psalmCanVerify',
|
'message' => 'Could not verify return type \'string|null\' for psalmCanVerify',
|
||||||
'file_name' => 'somefile.php',
|
'file_name' => 'somefile.php',
|
||||||
'file_path' => 'somefile.php',
|
'file_path' => 'somefile.php',
|
||||||
'snippet' => 'function psalmCanVerify(int $your_code): ?string {
|
'snippet' => 'function psalmCanVerify(int $your_code): ?string {',
|
||||||
return $as_you . "type";
|
|
||||||
}',
|
|
||||||
'selected_text' => '?string',
|
'selected_text' => '?string',
|
||||||
'from' => 47,
|
'from' => 47,
|
||||||
'to' => 54,
|
'to' => 54,
|
||||||
'snippet_from' => 6,
|
'snippet_from' => 6,
|
||||||
'snippet_to' => 85,
|
'snippet_to' => 56,
|
||||||
'column_from' => 42,
|
'column_from' => 42,
|
||||||
'column_to' => 49,
|
'column_to' => 49,
|
||||||
],
|
],
|
||||||
|
@ -138,14 +138,12 @@ echo $a;';
|
|||||||
'message' => 'Could not verify return type \'string|null\' for psalmCanVerify',
|
'message' => 'Could not verify return type \'string|null\' for psalmCanVerify',
|
||||||
'file_name' => 'somefile.php',
|
'file_name' => 'somefile.php',
|
||||||
'file_path' => 'somefile.php',
|
'file_path' => 'somefile.php',
|
||||||
'snippet' => 'function psalmCanVerify(int $your_code): ?string {
|
'snippet' => 'function psalmCanVerify(int $your_code): ?string {',
|
||||||
return $as_you . "type";
|
|
||||||
}',
|
|
||||||
'selected_text' => '?string',
|
'selected_text' => '?string',
|
||||||
'from' => 47,
|
'from' => 47,
|
||||||
'to' => 54,
|
'to' => 54,
|
||||||
'snippet_from' => 6,
|
'snippet_from' => 6,
|
||||||
'snippet_to' => 85,
|
'snippet_to' => 56,
|
||||||
'column_from' => 42,
|
'column_from' => 42,
|
||||||
'column_to' => 49,
|
'column_to' => 49,
|
||||||
],
|
],
|
||||||
@ -214,8 +212,6 @@ somefile.php:15: [E0001] PossiblyUndefinedGlobalVariable: Possibly undefined glo
|
|||||||
|
|
||||||
ERROR: MixedInferredReturnType - somefile.php:2:42 - Could not verify return type \'string|null\' for psalmCanVerify
|
ERROR: MixedInferredReturnType - somefile.php:2:42 - Could not verify return type \'string|null\' for psalmCanVerify
|
||||||
function psalmCanVerify(int $your_code): ?string {
|
function psalmCanVerify(int $your_code): ?string {
|
||||||
return $as_you . "type";
|
|
||||||
}
|
|
||||||
|
|
||||||
ERROR: UndefinedConstant - somefile.php:7:6 - Const CHANGE_ME is not defined
|
ERROR: UndefinedConstant - somefile.php:7:6 - Const CHANGE_ME is not defined
|
||||||
echo CHANGE_ME;
|
echo CHANGE_ME;
|
||||||
|
@ -915,6 +915,13 @@ class ReturnTypeTest extends TestCase
|
|||||||
}',
|
}',
|
||||||
'error_message' => 'InvalidReturnStatement',
|
'error_message' => 'InvalidReturnStatement',
|
||||||
],
|
],
|
||||||
|
'invalidReturnTypeCorrectLine' => [
|
||||||
|
'<?php
|
||||||
|
function f1(
|
||||||
|
int $a
|
||||||
|
): string {}',
|
||||||
|
'error_message' => 'InvalidReturnType - src/somefile.php:4:24'
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user