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

Brujo Benavides elbrujohalcon@REDACTED
Fri Aug 3 18:32:16 CEST 2018


Well, that’s not happening here…

Erlang/OTP 21 [erts-10.0] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe]

Eshell V10.0  (abort with ^G)
1> <<X, Y/binary>> = <<0>>, {X, Y}.
{0,<<>>}
2> F = fun(<<X, Y/binary>>) -> {X, Y} end.
#Fun<erl_eval.6.127694169>
3> F(<<0>>).
{0,<<>>}
4> {ok, A} = file:read_file("a.erl"), io:format("~s~n", [A]).
-module a.
-export [f/1].

f(<<X, Y/binary>>) -> {X, Y}.

ok
5> c(a).
{ok,a}
6> a:f(<<0>>).
{0,<<>>}
7>

There must be something else happening with your code.

Brujo Benavides <http://about.me/elbrujohalcon>



> On 3 Aug 2018, at 13:08, 格通 <getonga2018@REDACTED> wrote:
> 
> 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 <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 <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.
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20180803/0f2d9416/attachment.htm>


More information about the erlang-questions mailing list