From 22c20a60cfeb8674d50a5606dc85b3e20709c52c Mon Sep 17 00:00:00 2001 From: Lukasz Samson Date: Thu, 16 Apr 2026 11:00:11 +0200 Subject: [PATCH 1/3] Fix compiler crash on invalid nested bitstring --- lib/elixir/src/elixir_bitstring.erl | 4 +++- lib/elixir/test/elixir/kernel/binary_test.exs | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/elixir/src/elixir_bitstring.erl b/lib/elixir/src/elixir_bitstring.erl index d78250d4463..b12c259bb8e 100644 --- a/lib/elixir/src/elixir_bitstring.erl +++ b/lib/elixir/src/elixir_bitstring.erl @@ -115,7 +115,9 @@ concat_or_prepend_bitstring(Meta, {'<<>>', PartsMeta, Parts} = ELeft, ERight, Ac [{'::', Meta, [ELeft, ERight]} | Acc] end; {bitstring, _, nil} -> - lists:reverse(Parts, Acc) + lists:reverse(Parts, Acc); + _ -> + [{'::', Meta, [ELeft, ERight]} | Acc] end; concat_or_prepend_bitstring(Meta, ELeft, ERight, Acc, _E, _RequireSize) -> [{'::', Meta, [ELeft, ERight]} | Acc]. diff --git a/lib/elixir/test/elixir/kernel/binary_test.exs b/lib/elixir/test/elixir/kernel/binary_test.exs index c48c2b9613c..66e3c83cb83 100644 --- a/lib/elixir/test/elixir/kernel/binary_test.exs +++ b/lib/elixir/test/elixir/kernel/binary_test.exs @@ -196,6 +196,12 @@ defmodule Kernel.BinaryTest do assert_compile_error(message, fn -> Code.eval_string(~s[<<"foo"::float>>]) end) + + assert_compile_error(message, fn -> + Code.compile_string( + "defmodule Repro do\n def run do\n <<(<<1>>)::integer>>\n end\nend\n" + ) + end) end @bitstring <<"foo", 16::4>> From b7dbdb47c655dc996ebbd84dd7df5f5e726b5004 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 16 Apr 2026 13:47:07 +0200 Subject: [PATCH 2/3] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: José Valim --- lib/elixir/test/elixir/kernel/binary_test.exs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/elixir/test/elixir/kernel/binary_test.exs b/lib/elixir/test/elixir/kernel/binary_test.exs index 66e3c83cb83..ec326050cf6 100644 --- a/lib/elixir/test/elixir/kernel/binary_test.exs +++ b/lib/elixir/test/elixir/kernel/binary_test.exs @@ -198,8 +198,10 @@ defmodule Kernel.BinaryTest do end) assert_compile_error(message, fn -> + # We need to wrap the example below in a module because + # we attempt to continue compilation when inside a function Code.compile_string( - "defmodule Repro do\n def run do\n <<(<<1>>)::integer>>\n end\nend\n" + "defmodule Repro do\n def run, do: <<(<<1>>)::integer>>\nend\n" ) end) end From 87f16d1f0ac239d2efd81f2e6d5600d20b922dd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 16 Apr 2026 13:50:35 +0200 Subject: [PATCH 3/3] Apply suggestion from @josevalim --- lib/elixir/test/elixir/kernel/binary_test.exs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/elixir/test/elixir/kernel/binary_test.exs b/lib/elixir/test/elixir/kernel/binary_test.exs index ec326050cf6..6d68b45095a 100644 --- a/lib/elixir/test/elixir/kernel/binary_test.exs +++ b/lib/elixir/test/elixir/kernel/binary_test.exs @@ -200,9 +200,7 @@ defmodule Kernel.BinaryTest do assert_compile_error(message, fn -> # We need to wrap the example below in a module because # we attempt to continue compilation when inside a function - Code.compile_string( - "defmodule Repro do\n def run, do: <<(<<1>>)::integer>>\nend\n" - ) + Code.compile_string("defmodule Repro do\n def run, do: <<(<<1>>)::integer>>\nend") end) end