[erlang-questions] Dialyzer
Carlo Bertoldi
carlo.bertoldi@REDACTED
Mon May 2 11:41:56 CEST 2011
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
-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.
?PAUSE_FILE's content:
{pause,2000}.
Dialyzer version is 2.3.0
Carlo
More information about the erlang-questions
mailing list