Fl4m3Ph03n1x
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?
Marked As Solved
Fl4m3Ph03n1x
Fixed with PR:
Also Liked
al2o3cr
The typespec of Desktop.Menu.render is incorrect:
Fl4m3Ph03n1x
dominicletz
Thanks guys, sometimes I just can’t figure out what dialyzer is trying to tell me, will look into this and fix!
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









