Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppressing Erlang "unused function" warnings

I wrote an Erlang module where not all the internal functions are directly called. Instead, there's a couple functions that look something like this:

weird_func(Cmd, Args) ->
    ?MODULE:Cmd(Args).

It's a simplified example, but you get the idea. The Erlang compiler spits out warnings about unused functions, when in fact they are actually used, just not directly. Is there some way to suppress these warnings? Ideally I don't want to suppress all such warnings, but rather I'd like to tell the Erlang compiler to consider a few specific functions as special cases.

like image 390
Nick Avatar asked Jul 22 '10 15:07

Nick


2 Answers

there is a compile option specifically for this :

http://www.erlang.org/doc/man/compile.html

so, for your example insert a directive like this :

-compile([{nowarn_unused_function, [{ wierd_function_1,Arity1 },
                                       ... ]}]).

but the above warning about the compiler silently discarding the functions still stands as far as i know.

like image 53
tcmon Avatar answered Oct 15 '22 21:10

tcmon


It's not just a matter of suppressing the warning. An unexported function can't be called in the way you intend.

-module(foo).
-export([f/0]).
f() -> ?MODULE:g().
g() -> ok.

1> c(foo).
./foo.erl:4: Warning: function g/0 is unused
{ok,foo}
2> foo:f().
** exception error: undefined function foo:g/0

The compiler is free to drop the unused, unexported function completely. Simply export the function making it available call using the ?MODULE:F syntax.

like image 22
cthulahoops Avatar answered Oct 15 '22 22:10

cthulahoops