erlang的dialyzer使用中遇到的问题,以及解决方法

来源:互联网 发布:基金从业资格考试知乎 编辑:程序博客网 时间:2024/05/20 18:54
dialyzer错误分析:
错误1: Callback info about the tcp_server_handler behaviour is not available


解决办法:
  在R15之后,自定义类型需要采用新的模式:


例子:


%% User-defined behaviour module
-module(simple_server).
-export([start_link/2,...]).


-callback init(State :: term()) -> 'ok'.
-callback handle_req(Req :: term(), State :: term()) -> {'ok', Reply :: term()}.
-callback terminate() -> 'ok'.


%% Alternatively you may define:
%%
%% -export([behaviour_info/1]).
%% behaviour_info(callbacks) ->
%%     [{init,1},
%%      {handle_req,2},
%%      {terminate,0}].


start_link(Name, Module) ->
    proc_lib:start_link(?MODULE, init, [self(), Name, Module]).


init(Parent, Name, Module) ->
    register(Name, self()),
    ...,
    Dbg = sys:debug_options([]),
    proc_lib:init_ack(Parent, {ok, self()}),
    loop(Parent, Module, Deb, ...).


...
In a callback module:


-module(db).
-behaviour(simple_server).


-export([init/0, handle_req/2, terminate/0]).


错误2:Unknown types
  需要将自定义类型导出:


解决办法:
例子:
-type my_struct_type() :: Type.
-type orddict(Key, Val) :: [{Key, Val}].


-export_type([my_struct_type/0, orddict/2]).


错误3:Unknown functions
  如果是不是开源或者自己开发的库,可以通过 apps参数指定, apps参数还可以指定目录和文件
  例子:--apps $(APPS) ../base_lib ../open_lib/protobuffs ./ebin   
0 0