As I was getting
chef-server up to speed with
dialyzer, I got myself into a
little situation, that I couldn’t make heads nor tails of.
If you’ve run
dialyzer, you’ve probably seen the dreaded
function has no
local return error. The first thing I usually do is look at the following few
errors. If there’s something nearby, I’ll fix that first. Maybe
return will go away.
Of course, sometimes you really want the function to have no return.
dialyzer provides a type for that:
In Learn You Some Erlang's
we’re introduced to two most basic types:
any() is any
erlang term, so it’s not just a clever nickname.
none() is tricky. It means
that no return type is valid and that this function should crash.
So, why are we talking about it?
I had a function that I knew should have no return. Somewhere down it’s call
stack, it calls
error/1 which crashes things, and I’m cool with that. But
dialyzer told me there was no local return. I KNOW! I told you it was
so we should be fine with that.
After more time than I care to admit, and scrolling through that same Learn You Some Erlang page, I stumbled across this:
no_return(): this is an alias of none()
Well, if it’s an alias, it should also break. But, desperate times… And it
no_return() succeeded! Let’s look at the code:
When a function called
none() was fine; however, when the
function calls a function that calls
no_return() will get the
So I emailed Fred about it, which eventually ended with “We should ask Kostis”. And as it so happened, I was soon headed to EUC, which Kostis was also attending. I literally had a gist with this code ready to go on my phone, should the opportunity to ask about it arise.
As it turns out, it did! The answer straight from Kostis, is that
no_return() should be equivalent. If they’re not, it’s an issue with the
implementation (read: I found a bug in
dialyzer!), but it doesn’t matter,
just always use
So, there you have it.
none() is for chumps.
no_return() 4 lyfe.