psalm
psalm copied to clipboard
Malformed annotation generates confusing errors
It seems that if an annotation is malformed, then the line immediately above is being ignored. This causes code failures down the road with confusing and sometimes misleading error messages.
Note: checked @var
annotations only. Not sure if it affects others.
See https://psalm.dev/r/b61b64ba4f
I found these snippets:
https://psalm.dev/r/b61b64ba4f
<?php
/**
* @var int $n
* @var string missing_dollar_sign
*/
echo $n + $n;
Psalm output (using commit afe85fa):
ERROR: InvalidOperand - 8:6 - Cannot perform a numeric operation with non-numeric types string and string
Similar to #7902, interesting that it only affects the previous line though: https://psalm.dev/r/8e3c4046db
We should both fix this to not ignore the previous line, and also add an InvalidDocblock
error for the missing_dollar_sign
line.
I found these snippets:
https://psalm.dev/r/8e3c4046db
<?php
/**
* @var int $a
* @var int $b
* @var string missing_dollar_sign
* @var int $c
* @var int $d
*/
echo $a + $b + $c + $d;
Psalm output (using commit afe85fa):
ERROR: InvalidOperand - 11:11 - Cannot perform a numeric operation with a non-numeric type string