You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
awk: a function name used as a variable or parameter is accepted #169
Function names and variable names share one name space in awk. GNU rejects
assigning to a function name, using it as an array, naming a parameter after
its own function, or calling a parameter as a function. uutils awk accepts all
of these and runs the program.
Reproduction
Rust (incorrect)
$ ./target/release/awk 'function f() { return 1 } BEGIN { f = 2; print f }'
2
$ ./target/release/awk 'function f(f) { return f } BEGIN { print f(3) }'
3
GNU (correct)
$ gawk 'function f() { return 1 } BEGIN { f = 2; print f }'
gawk: cmd. line:1: error: function`f' called with space between name and `(',or used as a variable or an array# Exit code: 1$ gawk 'function f(f) { return f } BEGIN { print f(3) }'gawk: cmd. line:1: error: function `f': cannot use functionname as parameter name# Exit code: 1
Test
#[test]fnfunction_name_as_variable_is_an_error(){ucmd().arg("BEGIN { g[1] = 1 } function g() { }").fails_with_code(1);ucmd().arg("function h(h) { } BEGIN { }").fails_with_code(1);}
Exposed by the GNU awk test suite: delfunc, fnamedat, fnarray, fnarray2,
fnasgnm, funsmnam, paramasfunc1, paramasfunc2.
Note: this must be addressed during the lowering pass, which is where we resolve functions to the function table before other user code. This probably requires a slight logic rework to first populate the function names, and then register their bytecode location. Lastly, the checks can be added to TypedPlace::new_user, since that resolves all user variables and already handles edge cases like function locals.
Activity
Alonely0 commentedon Nov 26, 2026
Note: this must be addressed during the lowering pass, which is where we resolve functions to the function table before other user code. This probably requires a slight logic rework to first populate the function names, and then register their bytecode location. Lastly, the checks can be added to
TypedPlace::new_user, since that resolves all user variables and already handles edge cases like function locals.