Fix errline not being reset after it's set to symbol line

Fixes #230.
This commit is contained in:
Zeex 2018-01-07 11:46:45 +06:00
parent 3ee21806d0
commit 3c6be803d7
3 changed files with 35 additions and 15 deletions

View File

@ -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 */

View File

@ -10,27 +10,34 @@ function(add_compiler_test test_name options)
ENVIRONMENT PATH=$<TARGET_FILE_DIR:pawnc>)
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)

View File

@ -0,0 +1,8 @@
main() {
undefined;
new x = 0;
new y;
y = 123;
}