aboutsummaryrefslogtreecommitdiffstats
path: root/test/let1.awk
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2022-04-12 06:41:46 -0700
committerKaz Kylheku <kaz@kylheku.com>2022-04-12 06:41:46 -0700
commitc176b812d68da2284a221c8533a68a1aa290960b (patch)
tree7de45ed4e6920483fc093c15508ddfc0d242a295 /test/let1.awk
parent51ca241352218e6da8db10fe07c90e229a0bc1f8 (diff)
downloadegawk-c176b812d68da2284a221c8533a68a1aa290960b.tar.gz
egawk-c176b812d68da2284a221c8533a68a1aa290960b.tar.bz2
egawk-c176b812d68da2284a221c8533a68a1aa290960b.zip
@let: bug re-using previously array-typed location as scalar.
* awkgram.y (let_var_list): We must generate the Op_clear_var instruction even for variables which have initializers. Otherwise the initialization will bomb if the initializer is scalar, and the location we are re-using held an array previously. * interpret.h (r_interpret): Do not use the get_lhs function, which has complex semantics that depend on the existing type, and may initialize the value, as well as blow up for an array. We work directly with var->var_value. If var already has the new variable type, we have nothing to do. We now unref the prior value only if the prior type is Node_var, because prior array values and such don't support unref. * test/let1.awk: Extension of test case which reproduced this problem, plus additional test cases for coverage of the duplicated code in the Yacc grammar.
Diffstat (limited to 'test/let1.awk')
-rw-r--r--test/let1.awk9
1 files changed, 9 insertions, 0 deletions
diff --git a/test/let1.awk b/test/let1.awk
index 431fb8b8..90b1248b 100644
--- a/test/let1.awk
+++ b/test/let1.awk
@@ -43,6 +43,15 @@ BEGIN {
BEGIN {
@let (i = 3) { }
@let (a) { a[0] = 42 }
+ @let (i = 3) { }
+}
+
+# Yacc rules are duplicated for first versus rest, so we need additional coverage.
+
+BEGIN {
+ @let (x, i = 3) { }
+ @let (x, a) { a[0] = 42 }
+ @let (x, i = 3) { }
}
# test clearing uninitialized variables