3

Test under Erlang R15B.

-spec parse_packet(integer(), binary()) -> list().

parse_packet(16013, <<0:16, _/binary>>) -> [];
parse_packet(16013, <<ListNum:16, ListBin/binary>>) ->
SizePerMount = byte_size(ListBin) div ListNum,
(1)Fun = fun(_, [<<MountBin:SizePerMount/binary, T/binary>>, Acc]) ->
              <<MountId:32, _:32, GoodsTypeId:32, _/binary>> = MountBin,
              [T, [{GoodsTypeId, MountId}|Acc]]
      end,
[_, MountIds] = lists:foldl(Fun, [ListBin, []], lists:seq(1, ListNum)),
(2)lager:info("MountList:~p", [MountIds]),
MountIds.

Dialyzer complaints that "The created fun has no local return" at (1) and (2).

I supposed that the following update should enough to go through (1):

Fun = fun(_, [<<MountBin:SizePerMount/binary, T/binary>>, Acc]) ->
              <<MountId:32, _:32, GoodsTypeId:32, _/binary>> = MountBin,
              [T, [{GoodsTypeId, MountId}|Acc]]
         (_, [T, Acc]) ->
              [T, Acc]
      end,

But I think there should be other way to tell Dialyzer more type information.

Can anyone give some advice? Thank you in advance.

Yejun Su
  • 2,237
  • 3
  • 25
  • 43

0 Answers0