From e5f700d5ff489347f3bcff3810dff74ae72eaa68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 9 Aug 2016 01:34:37 +0200 Subject: [PATCH] Properly splice binaries inside binaries --- lib/elixir/src/elixir_bitstring.erl | 2 ++ lib/elixir/test/elixir/kernel/binary_test.exs | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/elixir/src/elixir_bitstring.erl b/lib/elixir/src/elixir_bitstring.erl index 2e9c27f3a7..beb3d6a5e2 100644 --- a/lib/elixir/src/elixir_bitstring.erl +++ b/lib/elixir/src/elixir_bitstring.erl @@ -192,6 +192,8 @@ build_bitstr_each(Fun, T, Meta, S, Acc, H, Size, Types) -> case Expr of {bin, _, Elements} when Splice, Size == default, S#elixir_scope.context == match -> build_bitstr_each(Fun, T, Meta, NS, lists:reverse(Elements, Acc)); + {bin, _, _} when Types == default -> + build_bitstr_each(Fun, T, Meta, NS, [{bin_element, ?ann(Meta), Expr, Size, [bitstring]} | Acc]); _ -> build_bitstr_each(Fun, T, Meta, NS, [{bin_element, ?ann(Meta), Expr, Size, Types} | Acc]) end. diff --git a/lib/elixir/test/elixir/kernel/binary_test.exs b/lib/elixir/test/elixir/kernel/binary_test.exs index 82eca01bea..f10eea8b6d 100644 --- a/lib/elixir/test/elixir/kernel/binary_test.exs +++ b/lib/elixir/test/elixir/kernel/binary_test.exs @@ -124,10 +124,12 @@ bar \""" end test "literal" do - assert <<106, 111, 115, 195, 169>> == <<"josé"::binary >> - assert <<106, 111, 115, 195, 169>> == <<"josé"::bits >> - assert <<106, 111, 115, 195, 169>> == <<"josé"::bitstring >> - assert <<106, 111, 115, 195, 169>> == <<"josé"::bytes >> + assert <<106, 111, 115, 195, 169>> == <<"josé">> + assert <<106, 111, 115, 195, 169>> == <<"#{:"josé"}">> + assert <<106, 111, 115, 195, 169>> == <<"josé"::binary>> + assert <<106, 111, 115, 195, 169>> == <<"josé"::bits>> + assert <<106, 111, 115, 195, 169>> == <<"josé"::bitstring>> + assert <<106, 111, 115, 195, 169>> == <<"josé"::bytes>> assert <<106, 111, 115, 195, 169>> == <<"josé"::utf8>> assert <<0, 106, 0, 111, 0, 115, 0, 233>> == <<"josé"::utf16>>