fixed a bug of not checking a function name against named variables

This commit is contained in:
hyung-hwan 2009-06-28 06:42:53 +00:00
parent b9d3b490a2
commit 3c63104bf7
4 changed files with 19 additions and 9 deletions

View File

@ -1,5 +1,5 @@
/* /*
* $Id: parse.c 215 2009-06-27 05:52:54Z hyunghwan.chung $ * $Id: parse.c 216 2009-06-27 12:42:53Z hyunghwan.chung $
* *
Copyright 2006-2009 Chung, Hyung-Hwan. Copyright 2006-2009 Chung, Hyung-Hwan.
@ -845,7 +845,8 @@ static qse_awk_nde_t* parse_function (qse_awk_t* awk)
return QSE_NULL; return QSE_NULL;
} }
if (qse_map_search (awk->tree.funs, name, name_len) != QSE_NULL) /* check if it has already been defined as a function */
if (qse_map_search (awk->tree.funs, name, name_len) != QSE_NULL)
{ {
/* the function is defined previously */ /* the function is defined previously */
SETERRARG ( SETERRARG (
@ -854,6 +855,15 @@ static qse_awk_nde_t* parse_function (qse_awk_t* awk)
return QSE_NULL; return QSE_NULL;
} }
/* check if it conflicts with a named variable */
if (qse_map_search (awk->parse.named, name, name_len) != QSE_NULL)
{
SETERRARG (
awk, QSE_AWK_EVARRED, awk->token.line,
name, name_len);
return QSE_NULL;
}
/* check if it coincides to be a global variable name */ /* check if it coincides to be a global variable name */
g = find_global (awk, name, name_len); g = find_global (awk, name, name_len);
if (g != QSE_LDA_NIL) if (g != QSE_LDA_NIL)

View File

@ -1,6 +1,6 @@
function f(f) function f(x)
{ {
print f; print x;
f("my hello"); f("my hello");
} }

View File

@ -1,3 +1,3 @@
# should print 50 # should print 50
function fn(f) { f = 20; } function fn(f) { f = 20; }
BEGIN { f = 50; fn(100); print f; } BEGIN { f = 50; fn(100); print f; }

View File

@ -1,3 +1,3 @@
# A function and a named variable cannot have the same name. # A function and a named variable cannot have the same name.
function a () { } function a () { }
BEGIN { a = 20; } BEGIN { a = 20; }