diff --git a/src/cmd/ksh93/bltins/whence.c b/src/cmd/ksh93/bltins/whence.c index 760c4e6c2..5e12bda25 100644 --- a/src/cmd/ksh93/bltins/whence.c +++ b/src/cmd/ksh93/bltins/whence.c @@ -192,7 +192,7 @@ static int whence(Shell_t *shp,char **argv, register int flags) } /* built-ins and functions next */ bltins: - if(!(flags&F_FLAG) && (np = nv_bfsearch(name, shp->fun_tree, &nq, ¬used)) && !is_abuiltin(np)) + if(!(flags&F_FLAG) && (np = nv_bfsearch(name, shp->fun_tree, &nq, ¬used)) && is_afunction(np)) { if(flags&Q_FLAG) continue; diff --git a/src/cmd/ksh93/tests/subshell.sh b/src/cmd/ksh93/tests/subshell.sh index 2ba5cbe90..a7fc8ef1b 100755 --- a/src/cmd/ksh93/tests/subshell.sh +++ b/src/cmd/ksh93/tests/subshell.sh @@ -699,6 +699,16 @@ got=$( f() { echo WRONG; }; ( unset -f f; PATH=/dev/null f 2>&1 ) ) [[ $got == $exp ]] || err_exit 'unset -f fails in sub-subshell on function set in subshell' \ "(expected match of $(printf %q "$exp"), got $(printf %q "$got"))" +# Functions unset in a subshell shouldn't be detected by type (whence -v) +# https://github.com/ksh93/ksh/pull/287 +notafunc() { + echo 'Failure' +} +exp=Success +got=$(unset -f notafunc; type notafunc 2>/dev/null || echo Success) +[[ $got == "$exp" ]] || err_exit "type/whence -v finds function in virtual subshell after it's unset with 'unset -f'" \ + "(expected $(printf %q "$exp"), got $(printf %q "$got"))" + # ====== # Unsetting or redefining aliases within subshells