LoginSignup
0
0

More than 5 years have passed since last update.

dialyzerのエラーサンプル集 その1 #Erlang

Posted at

現在編集中です。

ソースコード

error_sample.erl
-module(error_sample).

%%----------------------------------------------------------------------------------------------------------------------
%% Exported API
%%----------------------------------------------------------------------------------------------------------------------
-export([
         h/1
        ]).

%%----------------------------------------------------------------------------------------------------------------------
%% Macros & Records & Types
%%----------------------------------------------------------------------------------------------------------------------
-record(r, {
             item :: term()
           }).
-record(s, {
             item1 :: term(),
             item2 :: term()
           }).

-type r_list() :: [#r{}].
-type s_list() :: [#s{}].

%%----------------------------------------------------------------------------------------------------------------------
%% Exported Functions
%%----------------------------------------------------------------------------------------------------------------------
-spec h([term()]) -> ok.
h(List) ->
    {_, F} = f(List),
    g(F).

%%----------------------------------------------------------------------------------------------------------------------
%% Internal Function
%%----------------------------------------------------------------------------------------------------------------------
-spec f([term()]) -> {[1], r_list()}. % XXX: r_list() がおかしい
f(List) ->
    f(List, {[], []}).

-spec f([term()], {[1], s_list()}) -> {[1], s_list()}.
f([], R) ->
    R;
f([H|T], {R1, R2}) ->
    f(T, {[1|R1], [#s{item1=H}|R2]}).

-spec g(s_list()) -> ok.
g([]) ->
    ok;
g([H|T]) -> % error_sample.erl:xx: The pattern [H | T] can never match the type []
    io:format("~p", [H#s.item1]),
    g(T).

エラー

$ dialyzer ...
error_sample.erl:xx: The pattern [H | T] can never match the type []
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0