Closed gonzalobf closed 1 year ago
By default eqWAlizer may not refine record fields in general (as it may result in performance issues on average - especially with gigantic records). However, it is possible to force eqWAlizer to be smarter about it in two steps:
eqwalizer:refinable(X)
marker: (https://github.com/WhatsApp/eqwalizer/blob/9935940d71ef65c7bf7a9dfad77d89c0006c288e/eqwalizer/test_projects/eqwalizer/src/eqwalizer.erl#L47-L54handle_cast
This works:
...
-record(state, {
socket = undefined :: eqwalizer:refinable(connected | undefined)
}).
...
-spec handle_cast(term(), #state{}) -> {noreply, #state{}}.
handle_cast(_Msg, #state{socket=undefined}) ->
{noreply, #state{socket=connected}};
handle_cast(_Msg, State=#state{socket=Socket}) ->
send(Socket),
{noreply, State}.
Cool! thank you :)
Closing it since there is a workaround.
Sorry, if the title is not the best one but I tried to condense everything in a few words.
I was playing with eqwalizer in a project where I have a module similar to the example below. The module is a
gen_server
with socket in the#state{}
. The socket can beundefined
when there is no connection orgen_tcp:socket()
when there is one. I have simulated the socket with two atoms:undefined
|connected
Output:
I was expecting eqwalizer not to raise an error in
send(Socket)
since at this point Socket can't beundefined
. If it was, the firsthandle_cast
would have match and run the code inside. I can avoid the eqwalizer error by addingwhen Socket =/= undefined ->
in the secondhandle_cast
, but I was wondering if there are plans of supporting this in the future.Than you