diff --git a/src/nasal_codegen.cpp b/src/nasal_codegen.cpp index 683fb54..730b705 100644 --- a/src/nasal_codegen.cpp +++ b/src/nasal_codegen.cpp @@ -219,7 +219,12 @@ void codegen::func_gen(function* node) { // then the arg is [2, 3], because 1 is accepted by "a" // so in fact "f" is the same as: // var f = func(a, arg...) {return(arg)} - add_symbol("arg"); + auto arg = std::string("arg"); + // this is used to avoid confliction with defined parameter + while(local_find(arg)>=0) { + arg = "0" + arg; + } + add_symbol(arg); in_iterloop.push(0); block_gen(block); diff --git a/test/globals_test.nas b/test/globals_test.nas index c698b33..3016cda 100644 --- a/test/globals_test.nas +++ b/test/globals_test.nas @@ -22,6 +22,16 @@ var f = func() { f(1, 2, 3); +var a = func(arg, b) { + println(arg, " ", b); +} +var b = func(a) { + println(a, " ", arg); +} + +a(1, 2, 3, 4); # 1 2 +b(1, 2, 3, 4); # 1 [2 3 4] + # command line arguments println(arg); println(globals.arg); \ No newline at end of file