Using 'inline_list_funcs' with lists:xxx

with 24.3.4 on WLS

-module(test).

-compile([nowarn_export_all, export_all]).

run(Values) ->
    lists:all(fun erlang:is_integer/1, Values),
    lists:any(fun erlang:is_integer/1, Values),
    lists:foldl(fun erlang:is_integer/1, Values, Values),
    lists:foldr(fun erlang:is_integer/1, Values, Values),
    lists:mapfoldl(fun erlang:is_integer/1, Values, Values),
    lists:mapfoldr(fun erlang:is_integer/1, Values, Values),
    lists:map(fun erlang:is_integer/1, Values),
    lists:flatmap(fun erlang:is_integer/1, Values),
    lists:filter(fun erlang:is_integer/1, Values),
    lists:foreach(fun erlang:is_integer/1, Values).

compile with inline_list_funcs will get this warning:

erlc +inline_list_funcs test.erl
test.erl:6:5: Warning: this clause cannot match because a previous clause always matches
%    6|     lists:all(fun erlang:is_integer/1, Values),
%     |     ^

test.erl:7:5: Warning: this clause cannot match because a previous clause always matches
%    7|     lists:any(fun erlang:is_integer/1, Values),
%     |     ^

test.erl:8:5: Warning: this clause cannot match because its guard evaluates to 'false'
%    8|     lists:foldl(fun erlang:is_integer/1, Values, Values),
%     |     ^

test.erl:9:5: Warning: this clause cannot match because its guard evaluates to 'false'
%    9|     lists:foldr(fun erlang:is_integer/1, Values, Values),
%     |     ^

test.erl:10:5: Warning: this clause cannot match because its guard evaluates to 'false'
%   10|     lists:mapfoldl(fun erlang:is_integer/1, Values, Values),
%     |     ^

test.erl:11:5: Warning: this clause cannot match because its guard evaluates to 'false'
%   11|     lists:mapfoldr(fun erlang:is_integer/1, Values, Values),
%     |     ^

test.erl:12:5: Warning: the call to is_integer/1 has no effect
%   12|     lists:map(fun erlang:is_integer/1, Values),
%     |     ^                          ^

I’m working with warnings_as_errors, this is a disaster for me :cold_sweat:

1 Like

Hm, that is strange, you should open an issue at OTP to report it.

Debugging it is hard, for me at least, as said here,

When the inline_list_funcs option is given, the compiler uses hard-coded knowledge of a few of the functions in the lists module.


Anyway, with a little trial and error, I found that it seems to be related to your use of erlang:is_integer/1 as predicate function. Using functions from other modules than erlang or an anonymous function does not result in that warning.

You can work around your problem for now by wrapping erlang:is_integer/1 in an anonymous function, like

lists:all(fun(X) -> is_integer(X) end, Values)
1 Like

Btw, your topic headline is misleading, boolean expressions have nothing to do with it as far as I can tell. That is, you can remove the is_list(Values) andalso part (maybe stick it in a function guard if you need it), and you will still get that warning.

1 Like

OK, I will do it

And edited :slightly_smiling_face:

3 Likes

For later reference:

1 Like