Browse Source

Define `stack_item/0` type explicitly

Takeru Ohta 8 years ago
parent
commit
a996cc9dd6
3 changed files with 19 additions and 7 deletions
  1. 17 5
      src/jsone.erl
  2. 1 1
      src/jsone_decode.erl
  3. 1 1
      src/jsone_encode.erl

+ 17 - 5
src/jsone.erl

@@ -54,7 +54,7 @@
               decode_option/0,
               float_format_option/0,
               datetime_encode_format/0, datetime_format/0,
-              timezone/0, utc_offset_seconds/0
+              timezone/0, utc_offset_seconds/0, stack_item/0
              ]).
 
 %%--------------------------------------------------------------------------------
@@ -242,6 +242,18 @@
 %% - `attempt_atom': Returns existing atom as `existing_atom' but returns a
 %% binary string if fails find one.
 
+
+%% An item in a stack back-trace.
+%%
+%% Note that the `erlang` module already defines the same `stack_item/0` type,
+%% but it is not exported from the module.
+%% So, maybe as a temporary measure, we redefine this type for passing full dialyzer analysis.
+-type stack_item() :: {Module :: module(),
+                       Function :: atom(),
+                       Arity :: arity() | (Args :: [term()]),
+                       Location :: [{file, Filename :: string()} |
+                                    {line, Line :: pos_integer()}]}.
+
 %%--------------------------------------------------------------------------------
 %% Exported Functions
 %%--------------------------------------------------------------------------------
@@ -275,7 +287,7 @@ decode(Json, Options) ->
     end.
 
 %% @equiv try_decode(Json, [])
--spec try_decode(binary()) -> {ok, json_value(), Remainings::binary()} | {error, {Reason::term(), [erlang:stack_item()]}}.
+-spec try_decode(binary()) -> {ok, json_value(), Remainings::binary()} | {error, {Reason::term(), [stack_item()]}}.
 try_decode(Json) ->
     try_decode(Json, []).
 
@@ -290,7 +302,7 @@ try_decode(Json) ->
 %%                               [<<"wrong json">>,1,[],<<>>],
 %%                               [{line,208}]}]}}
 %% '''
--spec try_decode(binary(), [decode_option()]) -> {ok, json_value(), Remainings::binary()} | {error, {Reason::term(), [erlang:stack_item()]}}.
+-spec try_decode(binary(), [decode_option()]) -> {ok, json_value(), Remainings::binary()} | {error, {Reason::term(), [stack_item()]}}.
 try_decode(Json, Options) ->
     jsone_decode:decode(Json, Options).
 
@@ -324,7 +336,7 @@ encode(JsonValue, Options) ->
     end.
 
 %% @equiv try_encode(JsonValue, [])
--spec try_encode(json_value()) -> {ok, binary()} | {error, {Reason::term(), [erlang:stack_item()]}}.
+-spec try_encode(json_value()) -> {ok, binary()} | {error, {Reason::term(), [stack_item()]}}.
 try_encode(JsonValue) ->
     try_encode(JsonValue, []).
 
@@ -339,6 +351,6 @@ try_encode(JsonValue) ->
 %%                               [hoge,[{array_values,[2]}],<<"[1,">>],
 %%                               [{line,86}]}]}}
 %% '''
--spec try_encode(json_value(), [encode_option()]) -> {ok, binary()} | {error, {Reason::term(), [erlang:stack_item()]}}.
+-spec try_encode(json_value(), [encode_option()]) -> {ok, binary()} | {error, {Reason::term(), [stack_item()]}}.
 try_encode(JsonValue, Options) ->
     jsone_encode:encode(JsonValue, Options).

+ 1 - 1
src/jsone_decode.erl

@@ -61,7 +61,7 @@
                          | {object_value, jsone:json_string(), jsone:json_object_members()}
                          | {object_next, jsone:json_object_members()}.
 
--type decode_result() :: {ok, jsone:json_value(), Rest::binary()} | {error, {Reason::term(), [erlang:stack_item()]}}.
+-type decode_result() :: {ok, jsone:json_value(), Rest::binary()} | {error, {Reason::term(), [jsone:stack_item()]}}.
 
 -record(decode_opt_v2,
         {

+ 1 - 1
src/jsone_encode.erl

@@ -55,7 +55,7 @@
 -define(ENCODE_MAP(Value, Nexts, Buf, Opt), object(maps:to_list(Value), Nexts, Buf, Opt)).
 -endif.
 
--type encode_result() :: {ok, binary()} | {error, {Reason::term(), [erlang:stack_item()]}}.
+-type encode_result() :: {ok, binary()} | {error, {Reason::term(), [jsone:stack_item()]}}.
 -type next() :: {array_values, [jsone:json_value()]}
               | {object_value, jsone:json_value(), jsone:json_object_members()}
               | {object_members, jsone:json_object_members()}