diff --git a/src/cmd/ksh93/sh/nvtype.c b/src/cmd/ksh93/sh/nvtype.c index c59425867..1c8dc2e35 100644 --- a/src/cmd/ksh93/sh/nvtype.c +++ b/src/cmd/ksh93/sh/nvtype.c @@ -757,7 +757,12 @@ found: } } nv_onattr(mp,NV_NOFREE); - if(!np || !nv_setdisc(np, cp, mp, (Namfun_t*)np)) + if(!np) + { + errormsg(SH_DICT,ERROR_exit(1),"%s: cannot set discipline for undeclared type member",sp); + UNREACHABLE(); + } + if(!nv_setdisc(np, cp, mp, (Namfun_t*)np)) abort(); return(1); } diff --git a/src/cmd/ksh93/tests/types.sh b/src/cmd/ksh93/tests/types.sh index a64903000..863578e54 100755 --- a/src/cmd/ksh93/tests/types.sh +++ b/src/cmd/ksh93/tests/types.sh @@ -771,5 +771,12 @@ namespace sh.type [[ $got == "$exp" ]] || err_exit "'tyeset -p .sh.type' failed" \ "(expected $(printf %q "$exp"), got $(printf %q "$got"))" +# ====== +# Check for correct error message when attempting to set a discipline function for a nonexistent type member +exp=": foo.get: cannot set discipline for undeclared type member" +got=$(set +x; redirect 2>&1; typeset -T _bad_disc_t=(typeset dummy; function foo.get { :; }); echo end_reached) +let "(e=$?)==1" && [[ $got == *"$exp" ]] || err_exit "attempt to set disc for nonexistent type member not handled correctly" \ + "(expected status 1, match of *$(printf %q "$exp"); got status $e, $(printf %q "$got"))" + # ====== exit $((Errors<125?Errors:125))