[erlang-questions] Overriding built-in functions in a module

Raimo Niskanen raimo+erlang-questions@REDACTED
Fri Jun 4 08:25:38 CEST 2010


On Fri, Jun 04, 2010 at 05:18:58PM +1200, Richard O'Keefe wrote:
> 
> On Jun 4, 2010, at 3:39 PM, Igor Ribeiro Sucupira wrote:
> 
> > On Thu, Jun 3, 2010 at 10:00 PM, Richard O'Keefe <ok@REDACTED> wrote:
> >> 
> >> So let's do what the first error message says:
> >> 
> >> *    4  bar() -> ?MODULE:spawn(fun (X) -> X+1 end).
> >> 
> >> m% erlc foo.erl
> >> ./foo.erl:6: Warning: defining BIF spawn/1

You are right about the "defining BIF" warning being misleading!

> >> ./foo.erl:6: Warning: function spawn/1 is unused
> >> 
> >> There's an explicit call there, how can it not be used?
> > 
> > 
> > This was a little bit unrelated to the topic. Given that you can't
> > call a non-exported function with that syntax, that code is certainly
> > not calling the local fun spawn/1, since it's not exported.
> 
> Note that I wasn't suggesting that the call should be *allowed*,
> only that it is *there*.  There's a big difference between
> "there are NO calls to this function" and

But there *are* no calls to the local function spawn/1.

The local function spawn/1 will never be used and
that is what that warning says.

One might argue that any other module might call foo:spawn/1
so therefore any local function might actually be used
(the programmers intention was to use it) from another
module so a warning about a local function not being used
is never certain to be right...

> "the calls to this function won't be allowed at run time because
>  the function is not exported."

The call to ?MODULE:spawn/1 will be *allowed* at run time but
will probably fail. Not certainly, however. A newer version
of ?MODULE might export it so it *could* be part of a
code upgrade (silly name for that, though :-).

> 
> In short, I am not quarreling with the decision to report an
> error here, only commenting that the error message is extremely
> misleading.

#1 is. #2 not really.

> 
> 
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED

-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB


More information about the erlang-questions mailing list