From 4a7a1509991bfa9b79816a04fbee3398e3be6841 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Sun, 21 Nov 2021 20:13:48 +0200 Subject: Fix subtle typeof case. --- builtin.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'builtin.c') diff --git a/builtin.c b/builtin.c index d7ba82c9..266bf74a 100644 --- a/builtin.c +++ b/builtin.c @@ -4186,10 +4186,31 @@ do_typeof(int nargs) } break; case Node_var_new: - case Node_array_ref: res = "untyped"; deref = false; break; + case Node_array_ref: + /* + * function f(x) { + * print typeof(x) + * y = x + * print typeof(x) + * } + * + * BEGIN { + * print typeof(x) + * f(x) + * } + */ + if (arg->orig_array->type == Node_var + && (arg->orig_array->var_value == Nnull_string + || (arg->orig_array->var_value->flags & NULL_FIELD) != 0)) { + res = "unassigned"; + } else { + res = "untyped"; + } + deref = false; + break; case Node_var: /* * Note: this doesn't happen because the function calling code -- cgit v1.2.3