Skip to content

Commit 05582c8

Browse files
committed
Show correct line for unused symbol warning for global symbols
Fixes #252.
1 parent a47bd9d commit 05582c8

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

source/compiler/sc1.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4808,11 +4808,9 @@ static int testsymbols(symbol *root,int level,int testlabs,int testconst)
48084808
if (sym->parent!=NULL)
48094809
break; /* hierarchical data type */
48104810
if ((sym->usage & (uWRITTEN | uREAD | uSTOCK | uPUBLIC))==0) {
4811-
if (testconst)
4812-
errorset(sSETPOS,sym->lnumber);
4811+
errorset(sSETPOS,sym->lnumber);
48134812
error(203,sym->name,sym->lnumber); /* symbol isn't used (and not stock) */
4814-
if (testconst)
4815-
errorset(sSETPOS,0);
4813+
errorset(sSETPOS,0);
48164814
} else if ((sym->usage & (uREAD | uSTOCK | uPUBLIC))==0) {
48174815
errorset(sSETPOS,sym->lnumber);
48184816
error(204,sym->name); /* value assigned to symbol is never used */

source/compiler/tests/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ set_tests_properties(reset_errline_gh_230 PROPERTIES PASS_REGULAR_EXPRESSION "\
3333
.*\\.pwn\\(4\\) : warning 204: symbol is assigned a value that is never used: \\\"x\\\"\
3434
")
3535

36+
add_compiler_test(unused_symbol_line_gh_252 ${CMAKE_CURRENT_SOURCE_DIR}/unused_symbol_line_gh_252.pwn)
37+
set_tests_properties(unused_symbol_line_gh_252 PROPERTIES PASS_REGULAR_EXPRESSION "\
38+
.*\\.pwn\\(4\\) : warning 203: symbol is never used: \\\"y\\\"
39+
.*\\.pwn\\(8\\) : warning 203: symbol is never used: \\\"z\\\"
40+
.*\\.pwn\\(1\\) : warning 203: symbol is never used: \\\"x\\\"
41+
")
42+
3643
# Crashers
3744
#
3845
# These tests simply check that the compiler doesn't crash.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
new x;
2+
3+
main() {
4+
new y;
5+
f(0);
6+
}
7+
8+
f(z) {
9+
}

0 commit comments

Comments
 (0)