I'm using Erlang R16B03.
This code:
list_dir(Directory, Retries) when is_integer(Retries), Retries > 0 ->
Port = get_efile_port(),
try erlang:port_info(Port) of
Result ->
error_logger:info_msg("list_dir - erlang:port_info(~p) -> ~p ", [Port,Result])
catch
_:Reason ->
error_logger:info_msg("list_dir - erlang:port_info(~p) -> {error, ~p }",[Port,Reason])
end,
case prim_file:list_dir(Port, Directory) of
{error, einval} ->
error_logger:info_msg(" list_dir - port : ~p , directory : ~p", [Port, Directory]),
clear_efile_port(),
list_dir(Directory, Retries-1);
Result ->
Result
end.
Generates the following compiler exception:
/basho/riak/deps/bitcask/src/bitcask_fileops.erl:855: variable 'Result' unsafe in 'try' (line 843)
ERROR: compile failed while processing /basho/riak/deps/bitcask: rebar_abort
make: *** [compile] Error 1
But if I rename the first use of the variable name Result
to Res
, it compiles fine, e.g:
list_dir(Directory, Retries) when is_integer(Retries), Retries > 0 ->
Port = get_efile_port(),
try erlang:port_info(Port) of
Res ->
error_logger:info_msg("list_dir - erlang:port_info(~p) -> ~p ", [Port,Res])
catch
_:Reason ->
error_logger:info_msg("list_dir - erlang:port_info(~p) -> {error, ~p }",[Port,Reason])
end,
case prim_file:list_dir(Port, Directory) of
{error, einval} ->
error_logger:info_msg(" list_dir - port : ~p , directory : ~p", [Port, Directory]),
clear_efile_port(),
list_dir(Directory, Retries-1);
Result ->
Result
end.
As far as I can see the variables are within two different scopes (try/catch and case).
Is this a compiler bug or have I failed to understand the Erlang syntax correctly?