Dialyzer warns of unmatched_return on broadcast used in RoomChannel handle_in/3. Is this normal or do I need to fix something on my end?

Here’s my terminal:

mix dialyzer --quiet
The expression produces a value of type:

:ok | {:error, _}

but this value is unmatched.

done (warnings were emitted)
Halting VM with exit status 2

The code is the default generated handle_in/3:

  # It is also common to receive messages from the client and
  # broadcast to everyone in the current topic (room:lobby).
  @impl true
  def handle_in("shout", payload, socket) do
    broadcast(socket, "shout", payload) # <= here
    {:noreply, socket}

I could do:

_ = broadcast(socket, "shout", payload) # or :ok, or case, etc...
# or .dialyzer_ignore.exs
{"lib/my_app_web/channels/room_channel.ex", :unmatched_return, 28}

I’m not a fan of any of these workarounds. I’m wondering if it is normal to get this warning here (seems like it would be common) or have I messed something up?

Thanks for any feedback

There is no workaround.

Dialyzer tells you that there is a meaningfull return value comming back, which you ignore.

You might have forgotten to use the value or you might be dropping it consciously. _ = foo() tells dialyzer that ignoring the value is what you want, though you also could have done :ok = foo() to make sure sender crashes when the broadcast failed for some reason.

1 Like

Thank you