Skip to content

Commit 5e44c78

Browse files
authored
Fix compiler crash on invalid nested bitstring (#15280)
1 parent 4d56bdd commit 5e44c78

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/elixir/src/elixir_bitstring.erl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ concat_or_prepend_bitstring(Meta, {'<<>>', PartsMeta, Parts} = ELeft, ERight, Ac
115115
[{'::', Meta, [ELeft, ERight]} | Acc]
116116
end;
117117
{bitstring, _, nil} ->
118-
lists:reverse(Parts, Acc)
118+
lists:reverse(Parts, Acc);
119+
_ ->
120+
[{'::', Meta, [ELeft, ERight]} | Acc]
119121
end;
120122
concat_or_prepend_bitstring(Meta, ELeft, ERight, Acc, _E, _RequireSize) ->
121123
[{'::', Meta, [ELeft, ERight]} | Acc].

lib/elixir/test/elixir/kernel/binary_test.exs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,12 @@ defmodule Kernel.BinaryTest do
196196
assert_compile_error(message, fn ->
197197
Code.eval_string(~s[<<"foo"::float>>])
198198
end)
199+
200+
assert_compile_error(message, fn ->
201+
# We need to wrap the example below in a module because
202+
# we attempt to continue compilation when inside a function
203+
Code.compile_string("defmodule Repro do\n def run, do: <<(<<1>>)::integer>>\nend")
204+
end)
199205
end
200206

201207
@bitstring <<"foo", 16::4>>

0 commit comments

Comments
 (0)