[erlang-questions] Dialyzer
Kostis Sagonas
kostis@REDACTED
Mon May 2 11:55:00 CEST 2011
Carlo Bertoldi wrote:
> On 02/05/2011 11:23, Kostis Sagonas wrote:
>> Carlo Bertoldi wrote:
>>> Hello list,
>>> this is a bad monday, and I'm stuck with this warning from dialyzer:
>>>
>>> The specification for change_interval/2 states that the function
>>> might also return [any()] but the inferred return is none()
>>>
>>> The code:
>>> -spec(change_interval(integer(), [term()]) -> [term()]).
>>>
>>> change_interval(NewInterval, Config) ->
>>> NewPause = {pause, NewInterval},
>>> NewConfig = lists:keyreplace(pause, 1, Config, NewPause),
>>> write_config(NewPause),
>>> NewConfig.
>>>
> I apologize for the incompleteness, here goes the module
Well, probably it's a bad Monday alright for you. Wondering what
exactly it is you did during the weekend... ;)
Anyway, didn't you happen to notice that dialyzer generates an awful lot
of other warnings for this module? Among them, a warning that basically
tells you that the proper way to use file:open/2 is with a list of
options in the second argument, i.e. file:open(File, [write]), instead
of what you've written below? Please fix this.
As to the warning you are getting, can't you see that the function
change_interval/2 is nowhere used in this file? Even erlc will tell you
that.
Kostis
> -module(test).
> -export([test_write_config/0]).
>
> -define(PAUSE_FILE, "test.conf").
>
> -spec(change_interval(integer(), [term()]) -> [term()]).
>
> change_interval(NewInterval, Config) ->
> NewPause = {pause, NewInterval},
> NewConfig = lists:keyreplace(pause, 1, Config, NewPause),
> write_config(NewPause),
> NewConfig.
>
> -spec(write_config(tuple(pause, integer())) -> ok | error).
> write_config(Pause) ->
> File = ?PAUSE_FILE,
> case file:open(File, write) of
> {ok , F} ->
> io:format(F, "~w.", [Pause]),
> file:close(F),
> ok;
> {error, Reason} ->
> io:format("Error opening file ~p: ~p~n", [File, Reason]),
> error
> end.
>
> test_write_config() ->
> Pause = {pause, 6767576},
> write_config(Pause),
> {ok, Config} = file:consult(?PAUSE_FILE),
> Config.
More information about the erlang-questions
mailing list