saif

saif

Dialyzer - Function foo/1 has no local return

Hello everyone,

Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been almost 3 years, and I’m really excited and having so much fun.

Having worked on some statically typed languages I’ve been using typespecs and Dialyzer a lot more in my day to day. And this particular message has been driving me crazy:

Function foo/1 has no local return

I just spent about 4 hours trying to figure out why Dialyzer was so upset. And it turned out it’s because when I want to refactor a type I forget to change it everywhere in the code. Dialyzer starts complaining and I can’t figure out why. So I end up having to pinpoint what’s causing the issue and then fixing it. A lot of the time it’s for something completely unrelated! Like for example using the %{ my_struct | key: val} update syntax to update a struct instead of struct(my_struct, key: val).

Has anybody else run into this issue before? And is there a way to help Dialyzer get better at pinpointing the exact issue?

Cheers!

Most Liked

Eiji

Eiji

While I don’t know about any kind of universal solutions you can take a look at this article:
Dialyzer, or how I learned to stop worrying and love the cryptic error messages

There is also one useful hex package:

In case you have no idea what dialyzer is trying to say you can use dialyxir mix task:

mix dialyzer.explain unmatched_return
NobbZ

NobbZ

It does not mean that. It does mean that from dialyzers perspective the mentioned function will always raise. Not that it has some code path that will raise.

Understanding how dialyzer thinks that it will always raise requires an analisis of the function mentioned, as well as its nested functions.

I have experienced quite often that the problem was some NIF replacement function that raised, rather than calling :erlang.nif_error/1,2.

In many other cases it was some situation in which wrongly declared typespecs misleaded dialyzer to make assumptions that were not matching runtime behaviour.

NobbZ

NobbZ

The error has no local return means that dialyzer can not find a path that won’t raise or throw.

This warning is undebuggable without having more insight into the code.

Where Next?

Popular in Discussions Top

PragTob
Hello everyone, I know we had quite some threads (read through lots of them) about background job processing but it remains a hotly deba...
New
mikl
I wanted to capitalize a string, and tried using String.capitalize(). That generally works well, until you try to capitalize a word like...
New
cvkmohan
The upcoming Phoenix 1.6 release looks very interesting. Became a habit to watch the commits - and - what they are bringing in. phx.gen...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39247 209
New
crabonature
I’m still quite new to Elixir. As I understand we got in Elixir “multi guards” as convention to simplify one large guard with or’s?: de...
New
New
jer
I’ve been using umbrellas for a while, and generally started off (on greenfield projects at least) by isolating subapps based on clearly ...
New
jsonify
So, is Heroku the only free option for hosting Phoenix/Elixir at this point? I’m not ready to commit to paying monthly and was wondering ...
New
und0ck3d
Hello everyone! A few days ago I’ve created a topic here about how people were creating CMSs with Elixir and Phoenix. I’ve been studying...
New
griffinbyatt
Sobelow Sobelow is a security-focused static analysis tool for the Phoenix framework. For security researchers, it is a useful tool for g...
New

Other popular topics Top

stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
RisingFromAshes
I've read in another post that it may be possible with a router helper - but I couldn't find an appropriate one, and tbh, I'm still just ...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
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
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

We're in Beta

About us Mission Statement