Skip to content

Commit ad730d3

Browse files
authored
Merge pull request #431 from Daniel-Cortez/suggestions-fix
Fix incorrect suggestions for state variables
2 parents f8fec55 + 443979a commit ad730d3

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

source/compiler/sc5.c

+9-2
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ static char *warnmsg[] = {
199199
};
200200

201201
static char *noticemsg[] = {
202-
/*001*/ "; did you mean \"%s\"?\n"
202+
/*001*/ "; did you mean \"%s\"?\n",
203+
/*002*/ "; state variable out of scope\n"
203204
};
204205

205206
#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
660661
if (type==estSYMBOL) {
661662
find_symbol:
662663
closest_sym=find_closest_symbol(name,subtype);
663-
if (closest_sym!=NULL)
664+
if (closest_sym!=NULL) {
664665
closest_name=closest_sym->name;
666+
if ((subtype & esfVARIABLE)!=0 && closest_sym->states!=NULL && strcmp(closest_name,name)==0) {
667+
assert(number==17); /* undefined symbol */
668+
error(makelong(number,2),name);
669+
return 0;
670+
} /* if */
671+
} /* if */
665672
} else if (type==estNONSYMBOL) {
666673
if (tMIDDLE<subtype && subtype<=tLAST) {
667674
extern char *sc_tokens[];

source/compiler/tests/gh_353_symbol_suggestions.meta

+2
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,7 @@ gh_353_symbol_suggestions.pwn(138) : error 087: unknown state "BEING1" for autom
2424
gh_353_symbol_suggestions.pwn(138) : error 036: empty statement
2525
gh_353_symbol_suggestions.pwn(141) : error 087: unknown state "STATE_1" for automaton "automaton_2"; did you mean "automaton_1:STATE_1"?
2626
gh_353_symbol_suggestions.pwn(141) : error 036: empty statement
27+
gh_353_symbol_suggestions.pwn(148) : error 017: undefined symbol "test_e017_sug2_var"; state variable out of scope
28+
gh_353_symbol_suggestions.pwn(153) : error 017: undefined symbol "test_e017_sug2_var"; state variable out of scope
2729
"""
2830
}

source/compiler/tests/gh_353_symbol_suggestions.pwn

+16
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,19 @@ public test_e087()
140140
// error 087: unknown state "STATE_1" for automaton "automaton_2"; did you mean "automaton_1:STATE_1"?
141141
state automaton_2:STATE_1;
142142
}
143+
144+
new test_e017_sug2_var <automaton_3:STATE_2>;
145+
forward test_e017_sug2();
146+
public test_e017_sug2()
147+
{
148+
printf("%d\n", test_e017_sug2_var); // error 017: undefined symbol "test_e017_sug2_var"; state variable out of scope
149+
}
150+
forward test_e017_sug2_func();
151+
public test_e017_sug2_func() <automaton_3:STATE_1>
152+
{
153+
printf("%d\n", test_e017_sug2_var); // error 017: undefined symbol "test_e017_sug2_var"; state variable out of scope
154+
}
155+
public test_e017_sug2_func() <automaton_3:STATE_2>
156+
{
157+
#pragma unused test_e017_sug2_var
158+
}

0 commit comments

Comments
 (0)