diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2022-04-11 21:08:06 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2022-04-11 21:08:06 -0700 |
commit | 51ca241352218e6da8db10fe07c90e229a0bc1f8 (patch) | |
tree | 3e8b4e28353bdb5b64f182737127a524b8e0e299 | |
parent | 3dd49d281145d457bf8fa834418c2a7ff38250bd (diff) | |
download | egawk-51ca241352218e6da8db10fe07c90e229a0bc1f8.tar.gz egawk-51ca241352218e6da8db10fe07c90e229a0bc1f8.tar.bz2 egawk-51ca241352218e6da8db10fe07c90e229a0bc1f8.zip |
@let: bug re-using previously scalar location as array.
* test/let1.awk: New test case.
* interpret.h (r_interpret): Our new Op_clear_var opcode should
not only assign the null value to the variable, but reset its type
to Node_var_new.
-rw-r--r-- | interpret.h | 6 | ||||
-rw-r--r-- | test/let1.awk | 7 |
2 files changed, 12 insertions, 1 deletions
diff --git a/interpret.h b/interpret.h index ef087951..0dc261d6 100644 --- a/interpret.h +++ b/interpret.h @@ -743,6 +743,7 @@ mod: break; case Op_clear_var: + { /* * Clear variable to the undefined value * that is equal to 0 and "" represented by @@ -751,7 +752,8 @@ mod: * locals, which may re-use previously * initialized frame locations. */ - lhs = get_lhs(pc->memory, false); + NODE *var = pc->memory; + lhs = get_lhs(var, false); /* * If it's already clear, nothing to do @@ -760,6 +762,8 @@ mod: unref(*lhs); *lhs = dupnode(Nnull_string); } + var->type = Node_var_new; + } break; case Op_store_field: diff --git a/test/let1.awk b/test/let1.awk index 94a1a681..431fb8b8 100644 --- a/test/let1.awk +++ b/test/let1.awk @@ -38,6 +38,13 @@ BEGIN { print "b3", l3 "-" x } +# test re-use of scalar var as array + +BEGIN { + @let (i = 3) { } + @let (a) { a[0] = 42 } +} + # test clearing uninitialized variables function f4() |