mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
enable the exposure of the source line number when DocblockParseException is thrown
This commit is contained in:
parent
e694719272
commit
46a0b03aac
@ -21,6 +21,7 @@ class CommentChecker
|
||||
* @param string $var_id
|
||||
* @param array<string, string>|null $template_types
|
||||
* @param int|null $var_line_number
|
||||
* @param int|null $came_from_line_number what line number in $source that $comment came from
|
||||
* @return Type\Union|null
|
||||
* @throws DocblockParseException If there was a problem parsing the docblock.
|
||||
* @psalm-suppress MixedArrayAccess
|
||||
@ -31,7 +32,8 @@ class CommentChecker
|
||||
StatementsSource $source,
|
||||
$var_id = null,
|
||||
array $template_types = null,
|
||||
&$var_line_number = null
|
||||
&$var_line_number = null,
|
||||
$came_from_line_number = null
|
||||
) {
|
||||
$type_in_comments_var_id = null;
|
||||
|
||||
@ -86,6 +88,17 @@ class CommentChecker
|
||||
try {
|
||||
$defined_type = Type::parseString($type_in_comments);
|
||||
} catch (TypeParseTreeException $e) {
|
||||
if (is_int($came_from_line_number)) {
|
||||
throw new DocblockParseException(
|
||||
$type_in_comments .
|
||||
' is not a valid type' .
|
||||
' (from ' .
|
||||
$source->getCheckedFilePath() .
|
||||
':' .
|
||||
$came_from_line_number .
|
||||
')'
|
||||
);
|
||||
}
|
||||
throw new DocblockParseException($type_in_comments . ' is not a valid type');
|
||||
}
|
||||
|
||||
|
@ -64,6 +64,7 @@ class AssignmentChecker
|
||||
* @param Context $context
|
||||
* @param string $doc_comment
|
||||
* @param bool $by_reference
|
||||
* @param int|null $came_from_line_number
|
||||
* @return false|Type\Union
|
||||
*/
|
||||
public static function analyze(
|
||||
@ -73,7 +74,8 @@ class AssignmentChecker
|
||||
Type\Union $assign_value_type = null,
|
||||
Context $context,
|
||||
$doc_comment,
|
||||
$by_reference = false
|
||||
$by_reference = false,
|
||||
$came_from_line_number = null
|
||||
) {
|
||||
$var_id = ExpressionChecker::getVarId(
|
||||
$assign_var,
|
||||
@ -88,11 +90,15 @@ class AssignmentChecker
|
||||
);
|
||||
|
||||
if ($doc_comment) {
|
||||
$null = null;
|
||||
$type_in_comments = CommentChecker::getTypeFromComment(
|
||||
$doc_comment,
|
||||
$context,
|
||||
$statements_checker->getSource(),
|
||||
$var_id
|
||||
$var_id,
|
||||
null,
|
||||
$null,
|
||||
$came_from_line_number
|
||||
);
|
||||
} else {
|
||||
$type_in_comments = null;
|
||||
|
@ -89,7 +89,9 @@ class ExpressionChecker
|
||||
$stmt->expr,
|
||||
null,
|
||||
$context,
|
||||
(string)$stmt->getDocComment()
|
||||
(string)$stmt->getDocComment(),
|
||||
false,
|
||||
$stmt->getLine()
|
||||
);
|
||||
|
||||
if ($assignment_type === false) {
|
||||
|
Loading…
Reference in New Issue
Block a user