Skip to content

Instantly share code, notes, and snippets.

@kuenishi
Created February 8, 2014 06:03
Show Gist options
  • Save kuenishi/8877319 to your computer and use it in GitHub Desktop.
Save kuenishi/8877319 to your computer and use it in GitHub Desktop.
-module(d).
-export([sum_user/0]).
-spec sum_user() -> {ok, [{binary(), integer()}]}
| {error, term()}.
sum_user() ->
BucketUsages = [maybe_sum_bucket()],
{ok, BucketUsages}.
-spec maybe_sum_bucket() ->
{string(), string()} |
{string(), [{string(), integer()}]}.
maybe_sum_bucket() ->
Bucket = <<"binary">>,
case sum_bucket() of
{struct, _} = BucketUsage -> {Bucket, BucketUsage};
{error, _} = E ->
{Bucket, iolist_to_binary(io_lib:format("~p", [E]))}
end.
-spec sum_bucket() ->
{struct, [{binary(), non_neg_integer()}]} |
{error, term()}.
sum_bucket() ->
{ok, Results} = {ok, [{1, [{int(), int()}]}]},
{1, [{Objects, Bytes}]} = lists:keyfind(1, 1, Results),
{struct, [{<<"Objects">>, Objects},
{<<"Bytes">>, Bytes}]}.
-spec int() -> non_neg_integer().
int() -> 23.
$ erlc +debug_info d.erl && dialyzer --build_plt d.beam
d.erl:32: Warning: this clause cannot match because a previous clause at line 28 always matches
Creating PLT /home/kuenishi/.dialyzer_plt ... done in 0m0.14s
done (passed successfully)
$ dialyzer .
Checking whether the PLT /home/kuenishi/.dialyzer_plt is up-to-date... yes
Proceeding with analysis...
d.erl:5: Invalid type specification for function d:sum_user/0. The success typing is () -> {'ok',[{<<_:48>>,{_,_}},...]}
d.erl:11: Invalid type specification for function d:maybe_sum_bucket/0. The success typing is () -> {<<_:48>>,{'struct',[{_,_},...]}}
d.erl:19: The pattern E = {'error', _} can never match the type {'struct',[{<<_:40,_:_*16>>,23},...]}
d.erl:32: The pattern {'error', Error} can never match the type {'ok',[{1,[{23,23},...]},...]}
done in 0m0.14s
done (warnings were emitted)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment