ignatov / intellij-erlang

Erlang IDE
https://www.jetbrains.com/help/idea/2018.2/getting-started-with-erlang.html
Other
735 stars 120 forks source link

Assignment in case expression can declare a new variable #937

Open kvakvs opened 3 years ago

kvakvs commented 3 years ago

image

The picture shows how Socket is not defined, but it is defined 3 lines above in the case expression. This is SSH application source from OTP 22.

ignatov commented 3 years ago

Could you please add a code samle to the issue?

kvakvs commented 3 years ago

from ...otp/lib/ssh/src/ssh_connection_handler.erl

%%% ######## {hello, client|server} ####
%% The very first event that is sent when the we are set as controlling process of Socket
handle_event(_, socket_control, {hello,_}=StateName, #data{ssh_params = Ssh0} = D) ->
    VsnMsg = ssh_transport:hello_version_msg(string_version(Ssh0)),
    send_bytes(VsnMsg, D),
    case inet:getopts(Socket=D#data.socket, [recbuf]) of
    {ok, [{recbuf,Size}]} ->
        %% Set the socket to the hello text line handling mode:
        inet:setopts(Socket, [{packet, line},
                  {active, once},
                  % Expecting the version string which might
                  % be max ?MAX_PROTO_VERSION bytes:
                  {recbuf, ?MAX_PROTO_VERSION},
                  {nodelay,true}]),
            Time = ?GET_OPT(hello_timeout, Ssh0#ssh.opts, infinity),
        {keep_state, D#data{inet_initial_recbuf_size=Size}, [{state_timeout,Time,no_hello_received}] };

    Other ->
            ?call_disconnectfun_and_log_cond("Option return", 
                                             io_lib:format("Unexpected getopts return:~n  ~p",[Other]),
                                             StateName, D),
        {stop, {shutdown,{unexpected_getopts_return, Other}}}
    end;