From 36886b5bac75cda19506ba357136200ccf2fe2d4 Mon Sep 17 00:00:00 2001 From: Bart Schaefer Date: Sat, 28 Nov 2020 09:23:10 -0800 Subject: Add PM_DECLARED and PM_DECLAREDNULL parameter flags. This addresses the issue that "typeset foo" creates $foo set to an empty string, which differs from typeset handling in bash and ksh. It does this by concealing the internal value rather than alter the way internal values are defaulted. This imposes the following changes: A typeset variable with no assignment triggers NO_UNSET warnings when the name is used in parameter expansion or math. The typeset -AEFHLRTZailux options are applied upon the first assignment to the variable. Explicit unset before the first assignment discards all of those properties. If any option is applied to an existing name, historic behavior is unchanged. Consequent to the foregoing, the (t) parameter expansion flag prints nothing until after the first assignment, and the (i) and (I) subscript flags also print nothing. The bash behavior of "unset foo; typeset -p foo" is NOT used. This is called out as an emulation distinction, not a change. The test cases have not been updated, so several now fail. The test harness has been updated to declare default values. --- Src/builtin.c | 1 + 1 file changed, 1 insertion(+) (limited to 'Src/builtin.c') diff --git a/Src/builtin.c b/Src/builtin.c index 26335a2e8..691734221 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -2491,6 +2491,7 @@ typeset_single(char *cname, char *pname, Param pm, UNUSED(int func), return NULL; } } + pm->node.flags |= PM_DECLAREDNULL; } else { if (idigit(*pname)) zerrnam(cname, "not an identifier: %s", pname); -- cgit 1.4.1