Skip to content

Commit

Permalink
Show correct line for unused symbol warning for global symbols
Browse files Browse the repository at this point in the history
Fixes #252.
  • Loading branch information
Zeex committed Jan 10, 2018
1 parent a47bd9d commit 05582c8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
6 changes: 2 additions & 4 deletions source/compiler/sc1.c
Expand Up @@ -4808,11 +4808,9 @@ static int testsymbols(symbol *root,int level,int testlabs,int testconst)
if (sym->parent!=NULL)
break; /* hierarchical data type */
if ((sym->usage & (uWRITTEN | uREAD | uSTOCK | uPUBLIC))==0) {
if (testconst)
errorset(sSETPOS,sym->lnumber);
errorset(sSETPOS,sym->lnumber);
error(203,sym->name,sym->lnumber); /* symbol isn't used (and not stock) */
if (testconst)
errorset(sSETPOS,0);
errorset(sSETPOS,0);
} else if ((sym->usage & (uREAD | uSTOCK | uPUBLIC))==0) {
errorset(sSETPOS,sym->lnumber);
error(204,sym->name); /* value assigned to symbol is never used */
Expand Down
7 changes: 7 additions & 0 deletions source/compiler/tests/CMakeLists.txt
Expand Up @@ -33,6 +33,13 @@ set_tests_properties(reset_errline_gh_230 PROPERTIES PASS_REGULAR_EXPRESSION "\
.*\\.pwn\\(4\\) : warning 204: symbol is assigned a value that is never used: \\\"x\\\"\
")

add_compiler_test(unused_symbol_line_gh_252 ${CMAKE_CURRENT_SOURCE_DIR}/unused_symbol_line_gh_252.pwn)
set_tests_properties(unused_symbol_line_gh_252 PROPERTIES PASS_REGULAR_EXPRESSION "\
.*\\.pwn\\(4\\) : warning 203: symbol is never used: \\\"y\\\"
.*\\.pwn\\(8\\) : warning 203: symbol is never used: \\\"z\\\"
.*\\.pwn\\(1\\) : warning 203: symbol is never used: \\\"x\\\"
")

# Crashers
#
# These tests simply check that the compiler doesn't crash.
Expand Down
9 changes: 9 additions & 0 deletions source/compiler/tests/unused_symbol_line_gh_252.pwn
@@ -0,0 +1,9 @@
new x;

main() {
new y;
f(0);
}

f(z) {
}

0 comments on commit 05582c8

Please sign in to comment.