Skip to content

Commit

Permalink
Silence unused var warning for variables starting with _ (#469)
Browse files Browse the repository at this point in the history
  • Loading branch information
Akuli authored Dec 19, 2023
1 parent 31cc68c commit 799bfce
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/simplify_cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ static void remove_unused_variables(CfGraph *cfg)
if (
used[i] == WRITE
&& cfg->locals.ptr[i]->name[0] != '\0'
&& cfg->locals.ptr[i]->name[0] != '_'
&& strcmp(cfg->locals.ptr[i]->name, "return") != 0
) {
show_warning(write_locations[i], "variable '%s' is never used", cfg->locals.ptr[i]->name);
Expand Down
3 changes: 3 additions & 0 deletions tests/should_succeed/unused_variable.jou
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
def main() -> int:
# You get no warning if variable name starts with '_'
_ = 123
x = 4 # Warning: variable 'x' is never used
_foo = 7
return 0

0 comments on commit 799bfce

Please sign in to comment.