LionOps
I’m still relatively new to Elixir, so I’m hoping someone can shed some light on what’s up with my mode and/or dialyzer:
defmodule Eclipse.Router.Connection do
@moduledoc """
Server for a connection
"""
use GenServer, restart: :transient
@local_opts [:binary, packet: :raw, active: false, reuseaddr: true, reuseport: true]
@remote_opts [:binary, :inet, active: false, packet: :raw]
@type state :: %{
socket: Eclipse.Router.Socket.t()
}
@impl GenServer
@spec init({Eclipse.Config.Connections.t(), :local}) :: {:ok, state()}
def init({%Eclipse.Config.Connections{} = config, :local}) do
{:ok, socket} = :gen_tcp.listen(config.local_port, @local_opts)
{:ok, client} = :gen_tcp.accept(socket)
{:ok, %{socket: Eclipse.Router.Socket.new(client)}}
end
@spec init({Eclipse.Config.Connections.t(), :remote}) :: {:ok, state()}
def init({%Eclipse.Config.Connections{} = config, :remote}) do
{:ok, socket} = :gen_tcp.connect(config.remote_hostname, config.remote_port, @remote_opts)
{:ok, Eclipse.Router.Socket.new(socket)}
end
end
The above code passes, but the second init has the wrong success typing. {:ok, Eclipse.Router.Socket.new(socket)} as opposed to {:ok, %{socket: Eclipse.Router.Socket.new(socket)}}
If I comment out the first init, I get the expected errors.
Some guidance is appreciated on what I’m doing wrong.
Trending in Questions
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
Hello folks!
So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
I’m working on a small exercise involving update_in/3, and I came up with this solution:
data = %{
name: "Periodic Table",
category:...
New
How Can I Optimise Compile Time Dependencies
I have been building an elixir application for about 2 years now. Many modules and files ha...
New
Is there any way to avoid the Hologram compiler running when using iex? It seems like the front-end code could potentially be disregarded...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #ai
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #metaprogramming











Showing Posts 1 to 9- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
dimitarvp
How is it wrong? Check what you’re returning in the second function variant – it’s what Dialyzer is finding as well. You are returning a value without putting it in a map.
sabiwara
By default dialyzer’s success typing is pretty loose and is happy as long as one branch is OK, here is a minimal example:
But after adding the following flags to your
mix.exs(this is the config I personally recommend and use):Dialyzer is now able to catch these errors:
That being said, even if dialyzer is able to understand this particular error with the right flags, it is important to keep in mind that it remains quite limited and that there are a whole range of type errors it won’t be able to catch.
LionOps
stateis a map, though, is it not? Both function variants have the same return spec, but return different things. Dialyzer will error on the second variant if I comment out the first variant, or if I remove the map from the first variant, it’ll error there.LionOps
I had those flags in place, and it’s not catching the error. If I’m understanding things correctly, I’ve setup dialxyr correctly and have the correct spec, but it’s not equipped to catch the error.
dimitarvp
Your first variant has this as a return value:
The second variant however has this:
Maybe I misunderstand the problem but the difference is pretty clear.
LionOps
Yes, the variants are different. My problem is that it’s not clear to dialyzer that the second function variant doesn’t match the spec.
I would expect dialyzer to error for the second variant because the return does not match the spec; however, it seems that as long as the first instance is correct, dialyzer is happy. That is a surprising behavior.
My mix config:
I don’t think it’s a configuration issue because the flags I’m using are in the output:
I would expect my code to not pass dialzyer, but it does. I’m trying to understand why.
sabiwara
Indeed this seems like a bug or limitation in dialyzer, despite the
[:missing_return, :extra_return]flags.It seems it avoids “diving in” when containers superficially seem to have the correct type:
No warning on
{:ok, ""}, but it would catch it if it is the wrong atom{:error, 2}or wrong tuple size{:ok, 1, 2}.For maps, it seems it is fine as long as the other close returns a map:
but fails when the top-level is not a map.
Will open up an issue to OTP.
sabiwara
Done: Dialyzer's `-Wmissing_return` fails to detect incorrect nested types · Issue #8935 · erlang/otp · GitHub
sabiwara
Update from the issue: