diff --git a/lib/stdlib/src/edlin_expand.erl b/lib/stdlib/src/edlin_expand.erl index 2b454c858d7..ebf37e303b1 100644 --- a/lib/stdlib/src/edlin_expand.erl +++ b/lib/stdlib/src/edlin_expand.erl @@ -393,8 +393,8 @@ is_type(Type, Cs, String) -> catch _:_ -> %% Types not possible to deduce with erl_parse - % If string contains variables, erl_parse:parse_term will fail, but we - % consider them valid sooo.. lets replace them with the atom var + %% If string contains variables, erl_parse:parse_term will fail, but we + %% consider them valid sooo.. lets replace them with the atom var B = [(fun({var, Anno, _}) -> {atom, Anno, var}; (Token) -> Token end)(X) || X <- A], try {ok, Term2} = erl_parse:parse_term(B), @@ -729,30 +729,34 @@ expand_filepath(PathPrefix, Word) -> X -> X end. -shell(Fun) -> - {ok, [{atom, _, Fun1}], _} = erl_scan:string(Fun), - case shell:local_func(Fun1) of +shell(Fun) when is_atom(Fun) -> + case shell:local_func(Fun) of true -> "shell"; false -> "user_defined" end. -doc false. +shell_default_or_bif(Fun) when is_atom(Fun) -> + case lists:member(Fun, [E || {E,_}<-get_exports(shell_default)]) of + true -> "shell_default"; + false -> bif(Fun) + end; shell_default_or_bif(Fun) -> case erl_scan:string(Fun) of - {ok, [{var, _, _}], _} -> []; - {ok, [{atom, _, Fun1}], _} -> - case lists:member(Fun1, [E || {E,_}<-get_exports(shell_default)]) of - true -> "shell_default"; - _ -> bif(Fun) - end + {ok, [{atom, _, Fun1}], _} -> shell_default_or_bif(Fun1); + _ -> [] end. -doc false. -bif(Fun) -> - {ok, [{atom, _, Fun1}], _} = erl_scan:string(Fun), - case lists:member(Fun1, [E || {E,A}<-get_exports(erlang), erl_internal:bif(E,A)]) of +bif(Fun) when is_atom(Fun) -> + case lists:member(Fun, [E || {E,_}<-get_exports(erlang)]) of true -> "erlang"; - _ -> shell(Fun) + false -> shell(Fun) + end; +bif(Fun) -> + case erl_scan:string(Fun) of + {ok, [{atom, _, Fun1}], _} -> bif(Fun1); + _ -> [] end. expand_string(Bef0) -> diff --git a/lib/stdlib/src/shell.erl b/lib/stdlib/src/shell.erl index 34eb89dc6cb..7d322455a85 100644 --- a/lib/stdlib/src/shell.erl +++ b/lib/stdlib/src/shell.erl @@ -1282,7 +1282,7 @@ help() -> %% non_builtin_local_func/3 (user_default/shell_default). %% fd, ft and td should not be exposed to the user -doc false. -local_func() -> [v,h,b,f,ff,fl,lf,lr,lt,rd,rf,rl,rp,rr,tf,save_module,history,results,catch_exception]. +local_func() -> [v,h,b,f,fd,ff,fl,lf,lr,lt,rd,rf,rl,rp,rr,tf,save_module,history,results,catch_exception]. -doc false. local_func(Func) -> lists:member(Func, local_func()). diff --git a/lib/stdlib/test/edlin_expand_SUITE.erl b/lib/stdlib/test/edlin_expand_SUITE.erl index 52074500043..a4b695c7010 100644 --- a/lib/stdlib/test/edlin_expand_SUITE.erl +++ b/lib/stdlib/test/edlin_expand_SUITE.erl @@ -449,8 +449,11 @@ get_coverage(Config) -> do_expand("M#"), do_expand("#non_existant_record"), do_expand("#a_record{ non_existand_field"), - - + do_expand("case("), + do_expand("catch("), + do_expand("case ("), + do_expand("catch ("), + %% match_arguments coverage do_expand("complete_function_parameter:integer_parameter_function(atom,"), %% match_argument -> false do_expand("complete_function_parameter:a_zero_arity_fun()"), %% match_argument, parameters empty diff --git a/lib/stdlib/test/shell_SUITE.erl b/lib/stdlib/test/shell_SUITE.erl index 114f92da027..65b76b364e2 100644 --- a/lib/stdlib/test/shell_SUITE.erl +++ b/lib/stdlib/test/shell_SUITE.erl @@ -189,11 +189,11 @@ comm_err(<<"ugly().">>), comm_err(<<"1 - 2.">>), %% Make sure we test all local shell functions in a restricted shell. LocalFuncs = shell:local_func(), -[] = lists:subtract(LocalFuncs, [v,h,b,f,fl,ff,lf,lr,lt,rd,rf,rl,rp,rr,tf,save_module,history,results,catch_exception]), +[] = lists:subtract(LocalFuncs, [v,h,b,f,fd,fl,ff,lf,lr,lt,rd,rf,rl,rp,rr,tf,save_module,history,results,catch_exception]), LocalFuncs2 = [ <<"A = 1.\nv(1).">>, <<"h().">>, <<"b().">>, <<"f().">>, <<"f(A).">>, - <<"fl()">>, <<"ff()">>, <<"ff(my_func,1)">>, <<"lf()">>, <<"lr()">>, <<"lt()">>, + <<"fl()">>, <<"fd(a, fun(X)->X end,\"a(X)->X.\")">>, <<"ff()">>, <<"ff(my_func,1)">>, <<"lf()">>, <<"lr()">>, <<"lt()">>, <<"rd(foo,{bar}).">>, <<"rf().">>, <<"rf(foo).">>, <<"rl().">>, <<"rl(foo).">>, <<"rp([hej]).">>, <<"rr(shell).">>, <<"rr(shell, shell_state).">>, <<"rr(shell,shell_state,[]).">>, <<"tf()">>, <<"tf(hej)">>, <<"save_module(\"src/my_module.erl\")">>, <<"history(20).">>, <<"results(20).">>, <<"catch_exception(0).">>],