From 303b78251792acc9ba8af1ba44ab5b748421bd00 Mon Sep 17 00:00:00 2001 From: Daniel_Cortez Date: Tue, 18 Jun 2019 21:58:34 +0700 Subject: [PATCH 1/2] Fix incorrect suggestions for state variables --- source/compiler/sc5.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/source/compiler/sc5.c b/source/compiler/sc5.c index 7429c3f..c6c25bb 100644 --- a/source/compiler/sc5.c +++ b/source/compiler/sc5.c @@ -199,7 +199,8 @@ static char *warnmsg[] = { }; static char *noticemsg[] = { -/*001*/ "; did you mean \"%s\"?\n" +/*001*/ "; did you mean \"%s\"?\n", +/*002*/ "; state variable out of scope\n" }; #define NUM_WARNINGS (sizeof warnmsg / sizeof warnmsg[0]) @@ -660,8 +661,14 @@ SC_FUNC int error_suggest(int number,const char *name,const char *name2,int type if (type==estSYMBOL) { find_symbol: closest_sym=find_closest_symbol(name,subtype); - if (closest_sym!=NULL) + if (closest_sym!=NULL) { closest_name=closest_sym->name; + if ((subtype & esfVARIABLE)!=0 && closest_sym->states!=NULL && strcmp(closest_name,name)==0) { + assert(number==17); /* undefined symbol */ + error(makelong(number,2),name); + return 0; + } /* if */ + } /* if */ } else if (type==estNONSYMBOL) { if (tMIDDLE Date: Tue, 18 Jun 2019 22:00:52 +0700 Subject: [PATCH 2/2] Update tests for suggestions --- .../tests/gh_353_symbol_suggestions.meta | 2 ++ .../compiler/tests/gh_353_symbol_suggestions.pwn | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/source/compiler/tests/gh_353_symbol_suggestions.meta b/source/compiler/tests/gh_353_symbol_suggestions.meta index f9d8f94..af4fd1f 100644 --- a/source/compiler/tests/gh_353_symbol_suggestions.meta +++ b/source/compiler/tests/gh_353_symbol_suggestions.meta @@ -24,5 +24,7 @@ gh_353_symbol_suggestions.pwn(138) : error 087: unknown state "BEING1" for autom gh_353_symbol_suggestions.pwn(138) : error 036: empty statement gh_353_symbol_suggestions.pwn(141) : error 087: unknown state "STATE_1" for automaton "automaton_2"; did you mean "automaton_1:STATE_1"? gh_353_symbol_suggestions.pwn(141) : error 036: empty statement +gh_353_symbol_suggestions.pwn(148) : error 017: undefined symbol "test_e017_sug2_var"; state variable out of scope +gh_353_symbol_suggestions.pwn(153) : error 017: undefined symbol "test_e017_sug2_var"; state variable out of scope """ } diff --git a/source/compiler/tests/gh_353_symbol_suggestions.pwn b/source/compiler/tests/gh_353_symbol_suggestions.pwn index 81a22d6..84deb5d 100644 --- a/source/compiler/tests/gh_353_symbol_suggestions.pwn +++ b/source/compiler/tests/gh_353_symbol_suggestions.pwn @@ -140,3 +140,19 @@ public test_e087() // error 087: unknown state "STATE_1" for automaton "automaton_2"; did you mean "automaton_1:STATE_1"? state automaton_2:STATE_1; } + +new test_e017_sug2_var ; +forward test_e017_sug2(); +public test_e017_sug2() +{ + printf("%d\n", test_e017_sug2_var); // error 017: undefined symbol "test_e017_sug2_var"; state variable out of scope +} +forward test_e017_sug2_func(); +public test_e017_sug2_func() +{ + printf("%d\n", test_e017_sug2_var); // error 017: undefined symbol "test_e017_sug2_var"; state variable out of scope +} +public test_e017_sug2_func() +{ + #pragma unused test_e017_sug2_var +}