-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
New warnings/errors? #528
Comments
Should I implement those warnings exactly as described? Would be nice to have any feedback before I get to implementing them. |
Update: Added an idea for a new warning:
Any feedback is welcome. |
Added ideas for two new diagnostics:
|
Issue description:
Pawn is positioned as "a robust language with a compiler that performs a maximum of static checks", but there are still a lot of areas where these checks could be improved.
I think it would be useful to have the following warnings/errors:
We already have similar warnings for
if
statements:so why not adopt the same for
switch
?This can be achieved if the user has too many bit flags.
Again, this might happen if the user has too many bit flags.
(MERGED) enum element "%s" not handled in switch ([MERGED] warning 24X: enum item "%s" not handled in switch #549)
I already experimented with implementing this warning locally last year, and had a few false-positives in YSI and amx_assembly (1, 2). I think restricting this warning to cases where only 1 or 2 enum element are missing should help to get rid from this kind of false-positives.
(MERGED) division by zero (error 094: division by zero #538)
Interestingly, the compiler already has a check for zero division in function
flooreddiv()
(sc3.c), but it only works if both operands are constant values:Also, the message "
invalid expression, assumed zero
" in the above example is misleading, becauseMight be useful if the user defined bit flags, but forgot to specify the value for the first enum element (or specified
0
instead of1
by mistake):Works on
bool:
values when the user has accidentally used bitwise negation instead of the logical one.Works when the user has used
,
inside anif
/switch
/while
/do
/for
control expression, and the sub-expression before the comma doesn't have a side effect, which means that the use of comma is most probably unintended.Detects situations when the user forgot to add an increment for the loop counter variable, thus making the loop endless:
Mostly the same as the previous diagnostic, except that it works when multiple variables are used in the loop condition.
The problem is that usually in such situations only one of the variables needs to be modified, but the compiler can't know which one.
This new warning solves the issue by only telling that none of the variables were modified and allowing the user to decide which variable should be modified and which shouldn't.
Workspace Information:
The text was updated successfully, but these errors were encountered: