From 05582c8c0dc67ffe6e2b09f97633d3e3ca361e24 Mon Sep 17 00:00:00 2001 From: Zeex Date: Wed, 10 Jan 2018 20:50:54 +0600 Subject: [PATCH] Show correct line for unused symbol warning for global symbols Fixes #252. --- source/compiler/sc1.c | 6 ++---- source/compiler/tests/CMakeLists.txt | 7 +++++++ source/compiler/tests/unused_symbol_line_gh_252.pwn | 9 +++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 source/compiler/tests/unused_symbol_line_gh_252.pwn diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index 14744a6a..ede7c9ac 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -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 */ diff --git a/source/compiler/tests/CMakeLists.txt b/source/compiler/tests/CMakeLists.txt index 242c953e..a63fdeb9 100644 --- a/source/compiler/tests/CMakeLists.txt +++ b/source/compiler/tests/CMakeLists.txt @@ -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. diff --git a/source/compiler/tests/unused_symbol_line_gh_252.pwn b/source/compiler/tests/unused_symbol_line_gh_252.pwn new file mode 100644 index 00000000..0579d54d --- /dev/null +++ b/source/compiler/tests/unused_symbol_line_gh_252.pwn @@ -0,0 +1,9 @@ +new x; + +main() { + new y; + f(0); +} + +f(z) { +}