mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
Allow newlines in shortcut version of return type provider
This commit is contained in:
parent
f3d278609e
commit
b73b75f1a1
@ -2487,17 +2487,22 @@ class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements PhpParse
|
||||
$param_type_mapping[$token_body] = $template_name;
|
||||
}
|
||||
|
||||
// spaces are allowed before $foo in get(string $foo) magic method
|
||||
// definitions, but we want to remove them in this instance
|
||||
if (isset($fixed_type_tokens[$i - 1])
|
||||
&& $fixed_type_tokens[$i - 1][0][0] === ' '
|
||||
) {
|
||||
unset($fixed_type_tokens[$i - 1]);
|
||||
}
|
||||
|
||||
$fixed_type_tokens[$i][0] = $param_type_mapping[$token_body];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @psalm-suppress ArgumentTypeCoercion due to theoretical list -> array coercion
|
||||
*/
|
||||
$storage->return_type = Type::parseTokens(
|
||||
$fixed_type_tokens,
|
||||
array_values($fixed_type_tokens),
|
||||
null,
|
||||
$this->function_template_types + $class_template_types
|
||||
);
|
||||
|
@ -204,6 +204,31 @@ class ConditionalReturnTypeTest extends TestCase
|
||||
return 5;
|
||||
}
|
||||
|
||||
return true;
|
||||
}'
|
||||
],
|
||||
'variableConditionalSyntaxWithNewlines' => [
|
||||
'<?php
|
||||
/**
|
||||
* @psalm-return (
|
||||
* $i is 0
|
||||
* ? string
|
||||
* : (
|
||||
* $i is 1
|
||||
* ? int
|
||||
* : bool
|
||||
* )
|
||||
* )
|
||||
*/
|
||||
function getDifferentType(int $i) {
|
||||
if ($i === 0) {
|
||||
return "hello";
|
||||
}
|
||||
|
||||
if ($i === 1) {
|
||||
return 5;
|
||||
}
|
||||
|
||||
return true;
|
||||
}'
|
||||
],
|
||||
|
Loading…
x
Reference in New Issue
Block a user