Open
Description
I have
@spec child_pid(term) :: pid | nil
def child_pid(term) when not is_pid(term) do
pid({:child, term})
end
def child_pid(pid) do
case Supervisor.which_children(pid) do
[{_id, child_pid, _type, _modules}] ->
if is_pid(child_pid) do
child_pid
else
nil
end
_ ->
nil
end
end
I'm getting:
lib/checker/util.ex: The variable on line 59 is expected to have type pid() | nil but it has type :restarting | :undefined | pid()
57 [{_id, child_pid, _type, _modules}] ->
58 if is_pid(child_pid) do
59 child_pid
60 else
61 nil
I don't think it should get any error,
Rewritting the clause like this makes the error go away, and it is clearer, but I thought of sharing it here anyway.
def child_pid(pid) do
case Supervisor.which_children(pid) do
[{_id, child_pid, _type, _modules}] when is_pid(child_pid) ->
child_pid
_ ->
nil
end
end