diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index fe94880..c5246a8 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -2856,10 +2856,9 @@ static void decl_const(int vclass) /* add_constant() checks for duplicate definitions */ if (!matchtag(tag,exprtag,FALSE)) { /* temporarily reset the line number to where the symbol was defined */ - int orgfline=fline; - fline=symbolline; + errorset(sSETPOS,symbolline); error(213); /* tagname mismatch */ - fline=orgfline; + errorset(sSETPOS,0); } /* if */ sym=add_constant(constname,val,vclass,tag); if (sym!=NULL) @@ -4781,6 +4780,7 @@ static int testsymbols(symbol *root,int level,int testlabs,int testconst) } else if ((sym->usage & uREAD)==0) { errorset(sSETPOS,sym->lnumber); error(203,sym->name); /* symbol isn't used: ... */ + errorset(sSETPOS,0); } /* if */ } /* if */ break; @@ -4800,6 +4800,7 @@ static int testsymbols(symbol *root,int level,int testlabs,int testconst) if (testconst && (sym->usage & uREAD)==0) { errorset(sSETPOS,sym->lnumber); error(203,sym->name); /* symbol isn't used: ... */ + errorset(sSETPOS,0); } /* if */ break; default: @@ -4810,13 +4811,17 @@ static int testsymbols(symbol *root,int level,int testlabs,int testconst) if (testconst) errorset(sSETPOS,sym->lnumber); error(203,sym->name,sym->lnumber); /* symbol isn't used (and not stock) */ + if (testconst) + 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 */ + errorset(sSETPOS,0); #if 0 // ??? not sure whether it is a good idea to force people use "const" } else if ((sym->usage & (uWRITTEN | uPUBLIC | uCONST))==0 && sym->ident==iREFARRAY) { errorset(sSETPOS,sym->lnumber); error(214,sym->name); /* make array argument "const" */ + errorset(sSETPOS,0); #endif } /* if */ /* also mark the variable (local or global) to the debug information */ diff --git a/source/compiler/tests/CMakeLists.txt b/source/compiler/tests/CMakeLists.txt index fe7c138..242c953 100644 --- a/source/compiler/tests/CMakeLists.txt +++ b/source/compiler/tests/CMakeLists.txt @@ -10,27 +10,34 @@ function(add_compiler_test test_name options) ENVIRONMENT PATH=$) endfunction() -# # Compile tests # # These tests compare compile output against a regular expression and fail if the output # doesn't match the expected pattern. -# -add_compiler_test(gh_217 ${CMAKE_CURRENT_SOURCE_DIR}/gh_217.pwn) -set_tests_properties(gh_217 PROPERTIES PASS_REGULAR_EXPRESSION -".*: warning 237: user warning: this is warning 1[\r\n]+\ -.*: warning 237: user warning: this iswarning 2[\r\n]+\ -.*: warning 237: user warning: this is warning 3[\r\n]+\ -.*: warning 237: user warning: this is warning 4[\r\n]+\ -.*: warning 234: function is deprecated \\(symbol \"f\"\\) don't use this functionplease[\r\n]+\ -.*: warning 234: function is deprecated \\(symbol \"f\"\\) don't use this functionplease") -# +add_compiler_test(gh_217 ${CMAKE_CURRENT_SOURCE_DIR}/gh_217.pwn) +set_tests_properties(gh_217 PROPERTIES PASS_REGULAR_EXPRESSION "\ +.*\\.pwn\\(11\\) : warning 237: user warning: this is warning 1\ +.*\\.pwn\\(13\\) : warning 237: user warning: this iswarning 2\ +.*\\.pwn\\(15\\) : warning 237: user warning: this is warning 3\ +.*\\.pwn\\(17\\) : warning 237: user warning: this is warning 4\ +.*\\.pwn\\(27\\) : warning 234: function is deprecated \\(symbol \"f\"\\) don't use this functionplease\ +.*\\.pwn\\(32\\) : warning 234: function is deprecated \\(symbol \"f\"\\) don't use this functionplease\ +") + +add_compiler_test(reset_errline_gh_230 ${CMAKE_CURRENT_SOURCE_DIR}/reset_errline_gh_230.pwn) +set_tests_properties(reset_errline_gh_230 PROPERTIES PASS_REGULAR_EXPRESSION "\ +.*\\.pwn\\(2\\) : error 017: undefined symbol \\\"undefined\\\"\ +.*\\.pwn\\(2\\) : warning 215: expression has no effect\ +.*\\.pwn\\(7\\) : warning 204: symbol is assigned a value that is never used: \\\"y\\\"\ +.*\\.pwn\\(4\\) : warning 204: symbol is assigned a value that is never used: \\\"x\\\"\ +") + # Crashers # # These tests simply check that the compiler doesn't crash. # # TODO: Probably need to support tests that exist with a non-zero code but don't crash? # Right now this will cause a failure. -# + add_compiler_test(md_array_crash_gh_220 ${CMAKE_CURRENT_SOURCE_DIR}/md_array_crash_gh_220.pwn) diff --git a/source/compiler/tests/reset_errline_gh_230.pwn b/source/compiler/tests/reset_errline_gh_230.pwn new file mode 100644 index 0000000..ec30d4a --- /dev/null +++ b/source/compiler/tests/reset_errline_gh_230.pwn @@ -0,0 +1,8 @@ +main() { + undefined; + + new x = 0; + + new y; + y = 123; +} \ No newline at end of file