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) {
|
||||
$suffix = '';
|
||||
|
||||
$original_type = $parser_return_type;
|
||||
|
||||
if ($parser_return_type instanceof PhpParser\Node\NullableType) {
|
||||
$suffix = '|null';
|
||||
$parser_return_type = $parser_return_type->type;
|
||||
@ -1690,10 +1692,7 @@ class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements PhpParse
|
||||
|
||||
$storage->return_type_location = new CodeLocation(
|
||||
$this->file_scanner,
|
||||
$stmt,
|
||||
null,
|
||||
false,
|
||||
CodeLocation::FUNCTION_RETURN_TYPE
|
||||
$original_type
|
||||
);
|
||||
|
||||
if ($stmt->returnsByRef()) {
|
||||
|
@ -137,14 +137,12 @@ echo $a;';
|
||||
'message' => 'Could not verify return type \'string|null\' for psalmCanVerify',
|
||||
'file_name' => 'somefile.php',
|
||||
'file_path' => 'somefile.php',
|
||||
'snippet' => 'function psalmCanVerify(int $your_code): ?string {
|
||||
return $as_you . "type";
|
||||
}',
|
||||
'snippet' => 'function psalmCanVerify(int $your_code): ?string {',
|
||||
'selected_text' => '?string',
|
||||
'from' => 47,
|
||||
'to' => 54,
|
||||
'snippet_from' => 6,
|
||||
'snippet_to' => 85,
|
||||
'snippet_to' => 56,
|
||||
'column_from' => 42,
|
||||
'column_to' => 49,
|
||||
],
|
||||
|
@ -138,14 +138,12 @@ echo $a;';
|
||||
'message' => 'Could not verify return type \'string|null\' for psalmCanVerify',
|
||||
'file_name' => 'somefile.php',
|
||||
'file_path' => 'somefile.php',
|
||||
'snippet' => 'function psalmCanVerify(int $your_code): ?string {
|
||||
return $as_you . "type";
|
||||
}',
|
||||
'snippet' => 'function psalmCanVerify(int $your_code): ?string {',
|
||||
'selected_text' => '?string',
|
||||
'from' => 47,
|
||||
'to' => 54,
|
||||
'snippet_from' => 6,
|
||||
'snippet_to' => 85,
|
||||
'snippet_to' => 56,
|
||||
'column_from' => 42,
|
||||
'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
|
||||
function psalmCanVerify(int $your_code): ?string {
|
||||
return $as_you . "type";
|
||||
}
|
||||
|
||||
ERROR: UndefinedConstant - somefile.php:7:6 - Const CHANGE_ME is not defined
|
||||
echo CHANGE_ME;
|
||||
|
@ -915,6 +915,13 @@ class ReturnTypeTest extends TestCase
|
||||
}',
|
||||
'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