diff --git a/src/cmd/ksh93/sh/parse.c b/src/cmd/ksh93/sh/parse.c index 7f55ce510..0f7373184 100644 --- a/src/cmd/ksh93/sh/parse.c +++ b/src/cmd/ksh93/sh/parse.c @@ -222,6 +222,9 @@ static void check_typedef(struct comnod *tp, char intypeset) char **argv = dp->dolval + ARG_SPARE; if(intypeset==2) { + /* Skip over possible 'command' prefix(es) */ + while(*argv && strcmp(*argv, SYSENUM->nvname)) + argv++; /* Skip over 'enum' options */ opt_info.index = 0; while(optget(argv, sh_optenum)) @@ -245,11 +248,7 @@ static void check_typedef(struct comnod *tp, char intypeset) } } if(cp) - { - Namval_t *mp=(Namval_t*)tp->comnamp ,*bp; - bp = sh_addbuiltin(cp, (Shbltin_f)mp->nvalue.bfp, (void*)0); - nv_onattr(bp,nv_isattr(mp,NV_PUBLIC)); - } + nv_onattr(sh_addbuiltin(cp, (Shbltin_f)SYSTRUE->nvalue.bfp, NIL(void*)), NV_BLTIN|BLT_DCL); } /* diff --git a/src/cmd/ksh93/tests/enum.sh b/src/cmd/ksh93/tests/enum.sh index c67e3a498..437752b86 100755 --- a/src/cmd/ksh93/tests/enum.sh +++ b/src/cmd/ksh93/tests/enum.sh @@ -146,5 +146,15 @@ a=orange; let "a+=2" 2>/dev/null && err_exit "arithmetic can assign out of range a=green; let "a-=2" 2>/dev/null && err_exit "arithmetic can assign out of range (subtract)" a=blue; let "a*=3" 2>/dev/null && err_exit "arithmetic can assign out of range (multiply)" +# ====== +# Enum types should parse with 'command' prefix(es) and options and instantly +# recognise subsequent builtins it creates, even as a oneliner, even with +# shcomp. (This requires an ugly parser hack that this tests for.) +got=$(eval 2>&1 'command command command enum -i -i -iii --igno -ii PARSER_t=(r g b); '\ +'command command PARSER_t -r -rrAAA -A -rArArA -Arrrrrrr hack=([C]=G); typeset -p hack') +exp='PARSER_t -r -A hack=([C]=g)' +[[ $got == "$exp" ]] || err_exit "incorrect typeset output for enum with command prefix and options" \ + "(expected $(printf %q "$exp"); got $(printf %q "$got"))" + # ====== exit $((Errors<125?Errors:125))