[erlang-questions] erlang 21 binary matching bug in functin definition

格通 getonga2018@REDACTED
Fri Aug 3 18:08:23 CEST 2018


I try to fix the mysql-otp  for erlang 21, but found a bug  like this:
```
-module(a).
-export([decode_binary/2]).
decode_binary(_, <<Length, Data/binary>>) ->
    %% Coded in the same way as DATETIME and TIMESTAMP below, but returned
in
    %% a simple triple.

    case {Length, Data} of
        {0, _} -> io:format("~p length:~p, Data:~p, ~n" , [?LINE, Length,
Data]),{{0, 0, 0}, Data};
        {4, <<Y:16/little, M, D, Rest/binary>>} -> io:format("~p~n" ,
[?LINE]),{{Y, M, D}, Rest}
    end.

```
A function copy from
https://github.com/mysql-otp/mysql-otp/blob/master/src/mysql_protocol.erl#L789-L795
My erlang version is 21.0.4, and the pr address is
https://github.com/mysql-otp/mysql-otp/pull/84 .
compile it and run:
```
erlc a.erl
erl
1> a:decode_binary(test, <<0>>).
8 length:0, Data:<<0>>,
{{0,0,0},<<0>>}
```
But in pattern matching:
```
2> <<Length, Data/binary>> = <<0>>.
<<0>>
3>Length.
0
4>Data.
<<>>
```
It must be a bug in erlang 21 binary matching in function definition.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20180804/6ad1f19c/attachment.htm>


More information about the erlang-questions mailing list