🐛 fix bug in special argument "arg"
if defining a parameter named "arg", this will cause error value of the last local variable of this function
This commit is contained in:
parent
94b6e84693
commit
4a7a2ce11e
|
@ -219,7 +219,12 @@ void codegen::func_gen(function* node) {
|
||||||
// then the arg is [2, 3], because 1 is accepted by "a"
|
// then the arg is [2, 3], because 1 is accepted by "a"
|
||||||
// so in fact "f" is the same as:
|
// so in fact "f" is the same as:
|
||||||
// var f = func(a, arg...) {return(arg)}
|
// 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);
|
in_iterloop.push(0);
|
||||||
block_gen(block);
|
block_gen(block);
|
||||||
|
|
|
@ -22,6 +22,16 @@ var f = func() {
|
||||||
|
|
||||||
f(1, 2, 3);
|
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
|
# command line arguments
|
||||||
println(arg);
|
println(arg);
|
||||||
println(globals.arg);
|
println(globals.arg);
|
Loading…
Reference in New Issue