Elixir Desktop has dialyzer issues in MenuBar

Background

I have a small app using Elixir Desktop. This app works relatively well and launches without issues:

However, I have dialyzer complaining about types. I am not sure if this is a false positive, or if I am doing something wrong.

Problem

I have a MenuBar in my application with some basic functionality. This MenuBar is as far as I understand, a Phoenix LiveView component (because it has a mount and a render functions). So this code should look familiar for most users of Phoenix and LiveView:

defmodule WebInterface.Live.MenuBar do
  @moduledoc """
  Menubar that is shown as part of the main Window on Windows/Linux. In
  MacOS this Menubar appears at the very top of the screen.
  """

  use Desktop.Menu

  alias Desktop.{Menu, Window}

  @impl Menu
  def render(assigns) do
    ~H"""
    <menubar>
      <menu label="File">
          <hr/>
          <item onclick="quit">Quit</item>
      </menu>
    </menubar>
    """
  end

  @impl Menu
  def handle_event("quit", menu) do
    Window.quit()
    {:noreply, menu}
  end

  @impl Menu
  def mount(menu), do: {:ok, menu}

  @impl Menu
  def handle_info(:changed, menu), do: {:noreply, menu}

end

The issue here is that Dialyzer is complaining about my render function:

Type mismatch for @callback render/1 in Desktop.Menu behaviour.

Expected type:
binary()

Actual type:
%Phoenix.LiveView.Rendered{
  :dynamic => (_ -> []),
  :fingerprint => 15_721_876_439_225_774_806_119_511_245_371_375_581,
  :root => true,
  :static => [<<_::1480>>, ...]
}

It says it expects a String instead of an H sigil. Which is confusing to me, because the latest version does support this sigil.

Question

So the question arises. What am I doing wrong and how can I fix this?

1 Like

The typespec of Desktop.Menu.render is incorrect:

2 Likes

So this is something a PR with the correct type could fix right ?
Thank you for confirming my suspicion @al2o3cr !

1 Like

Thanks guys, sometimes I just can’t figure out what dialyzer is trying to tell me, will look into this and fix!

1 Like

Fixed with PR:

3 Likes