psalm icon indicating copy to clipboard operation
psalm copied to clipboard

Malformed annotation generates confusing errors

Open flaviovs opened this issue 2 years ago • 3 comments

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

flaviovs avatar Sep 06 '22 01:09 flaviovs

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

psalm-github-bot[bot] avatar Sep 06 '22 01:09 psalm-github-bot[bot]

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.

AndrolGenhald avatar Sep 06 '22 15:09 AndrolGenhald

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

psalm-github-bot[bot] avatar Sep 06 '22 15:09 psalm-github-bot[bot]