tosbourn

tosbourn

Help understanding dialyzer output of: "The call ... will never return since it differs in the 1st argument from the success typing arguments"

I’ll be honest, there is a lot about dialyzer output that confuses me.

Right now I’m confused by “The call … will never return since it differs in the 1st argument from the success typing arguments”

file.ex:23: The call ‘Elixir.Timber’:add_context(#{‘struct’:=‘Elixir.Timber.Contexts.UserContext’, ‘email’:=, ‘id’:=, ‘name’:=‘nil’}) will never return since it differs in the 1st argument from the success typing arguments: (maybe_improper_list())

My reading of that error is that dialyzer thinks that me calling Timber.add_context will fail because I’m sending in a struct and it is expecting input of maybe_improper_list.

Even though I know this works and Timber is an external dependancy, I wanted to understand why it wanted some type of list. I cracked into their code. Here is the code for add_context/1;

  @doc """
  Adds a context entry to the stack. See `Timber::Contexts::CustomContext` for examples.
  """
  @spec add_context(map | Keyword.t | Context.context_element) :: :ok
  def add_context(data) do
    CurrentContext.load()
    |> Context.add(data)
    |> CurrentContext.save()
  end

There is no explicit mention of maybe_improper_list, and as far as I know map covers the fact I’m passing in a struct.

Am I interpreting the output correctly? Any help would be much appreciated.

Most Liked

gon782

gon782

Same here. Mostly I think if you use it from the beginning you’re always reminded to keep it neat. I started using VS Code in the middle of working on a side project that was already underway for some time (before I got involved) and was bombarded with warnings that just came from undisciplined changes without dialyzing, etc..

It’s too easy to fall behind when you have to do something manually and I think everyone who’s used dialyzer has gotten like 2 screens full of trash thrown at them and it’s easy to become conditioned into not using it because of that. ElixirLS says “We’ll do this little by little together and I’m sure it will be fine in the end” and I like that a lot. It’s more akin to using statically typed languages.

dom

dom

I had a look - there’s a ton of issues with the typespecs in this project. For your specific problem, Dialyzer says that the typespec for add/2 is wrong:

lib/timber/context.ex:48: Invalid type specification for function 'Elixir.Timber.Context':add/2. The success typing is (_,maybe_improper_list()) -> any()

Which is in turn because the spec for sub-functions are wrong. For instance:

https://github.com/timberio/timber-elixir/blob/master/lib/timber/context.ex#L121

https://github.com/timberio/timber-elixir/blob/master/lib/timber/contexts/user_context.ex#L15

The user context spec says id is a string, but to_api_map takes it as an integer. Dialyzer infers this is impossible.

Or take insert/3:

https://github.com/timberio/timber-elixir/blob/master/lib/timber/context.ex#L83

It accepts an atom as the second argument, violating its own typespec a few lines above which says it must be a context struct.

So, at the end of the day the problem is the typespecs are wrong, causing Dialyzer to think that the functions will not work if you pass them a context struct. So it infers the “success type” is a list, because it’s the only thing that would work correctly according to the provided specs.

mbuhot

mbuhot

I’ve hit similar issues in libraries before. It’s frustrating when package authors add typespecs for documentation purposes, but don’t run dialyzer in CI to check that the code and specs agree.

Where Next?

Popular in Questions Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
Kurisu
For example for a current url like http://localhost:4000/cosmetic/products?_utf8=✓&query=perfume&page=2, I would like to get: ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lists...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New

Other popular topics Top

axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 48342 226
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New

We're in Beta

About us Mission Statement