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.

Last Post!

saif

saif

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

I think this was the case for me the majority of the time.

Where Next?

Popular in Discussions Top

scouten
I’m looking for a host for the server part of a small (personal) side project that I’m working on. It’s currently written in Node.js and ...
New
joeerl
I’m playing with Elixir - It’s fun. I think @rvirding does give Elixir courses these days. Re: files and database - when I given Erlang ...
New
acrolink
How does the two languages compare when it comes to server side application development? Any experiences or ideas? Thank you.
New
chulkilee
Here are the list of HTTP client libraries/wrappers, and some thoughts on HTTP client in general. I’d like to hear from others how they w...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
owaisqayum
I have a sample string sentence = "Hello, world ... 123 *** ^%&*())^% %%:>" From this string, I want to only keep the integers, ...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

Other popular topics Top

KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36689 110
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
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
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement