diff --git a/src/cmd/ksh93/sh/parse.c b/src/cmd/ksh93/sh/parse.c index 86fdb3e23..f1474331e 100644 --- a/src/cmd/ksh93/sh/parse.c +++ b/src/cmd/ksh93/sh/parse.c @@ -234,7 +234,14 @@ static void check_typedef(struct comnod *tp, char intypeset) } } if(cp) + { + if(!dcl_tree) + { + dcl_tree = dtopen(&_Nvdisc, Dtoset); + dtview(sh.bltin_tree, dcl_tree); + } nv_onattr(sh_addbuiltin(cp, (Shbltin_f)SYSTRUE->nvalue.bfp, NIL(void*)), NV_BLTIN|BLT_DCL); + } } /* * (De)activate an internal declaration built-ins tree into which check_typedef() can pre-add dummy type @@ -250,9 +257,8 @@ static void dcl_hacktivate(void) { if(dcl_recursion++) return; - if(!dcl_tree) - dcl_tree = dtopen(&_Nvdisc, Dtoset); - dtview(sh.bltin_tree, dcl_tree); + if(dcl_tree) + dtview(sh.bltin_tree, dcl_tree); orig_exit = error_info.exit; error_info.exit = dcl_exit; } @@ -261,7 +267,12 @@ static void dcl_dehacktivate(void) if(!dcl_recursion || --dcl_recursion) return; error_info.exit = orig_exit; - dtview(sh.bltin_tree, NIL(Dt_t*)); + if(dcl_tree) + { + dtview(sh.bltin_tree, NIL(Dt_t*)); + if(!sh.shcomp) + dtclear(dcl_tree); + } } static noreturn void dcl_exit(int e) { diff --git a/src/cmd/ksh93/tests/types.sh b/src/cmd/ksh93/tests/types.sh index abfd1c7da..4b9bb36fa 100755 --- a/src/cmd/ksh93/tests/types.sh +++ b/src/cmd/ksh93/tests/types.sh @@ -658,6 +658,8 @@ if false then typeset -T PARSER_t=(typeset name=foobar) fi PATH=/dev/null command -v PARSER_t >/dev/null && err_exit "PARSER_t incompletely defined though definition was never executed" +(PATH=/dev/null eval 'PARSER_t x=(name=y)') 2>/dev/null +(($?==3)) || err_exit "PARSER_t assignment not a syntax error though definition was never executed" unset v got=$( set +x; redirect 2>&1; typeset -T Subsh_t=(typeset -i x); Subsh_t -a v=( (x=1) (x=2) (x=3) ); typeset -p v ) @@ -675,7 +677,7 @@ exp=': trap: is a special shell builtin' # ====== # Bugs involving scripts without a #! path -# Hashbangless scripts are execeuted in a reinitialised fork of ksh, which is very bug-prone. +# Hashbangless scripts are executed in a reinitialised fork of ksh, which is very bug-prone. # https://github.com/ksh93/ksh/issues/350 # Some of these fixed bugs don't involve types at all, but the tests need to go somewhere. # Plus, invoking these from an environment with a bunch of types defined is an additional test.