Skip to content

Commit 37321cd

Browse files
ggcampinhojosevalim
authored andcommitted
Do not crash for unknown var inside binary pattern in match (#6459)
1 parent 8023b5e commit 37321cd

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/elixir/src/elixir_bitstring.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ expand(BitstrMeta, Fun, [{'::', Meta, [Left, Right]} | T], Acc, E, RequireSize)
2222
%% on subparts, however we can't assign new variables.
2323
{ER, MatchSize} =
2424
case E of
25-
{EExtracted, _} -> {EExtracted, false}; %% expand_arg, no assigns
26-
_ -> {E#{context := nil}, T /= []} %% expand, revert assigns
25+
{EExtracted, _} -> {EExtracted, false}; %% expand_arg, no assigns
26+
_ -> {E#{context := nil, match_vars := warn}, T /= []} %% expand, revert assigns
2727
end,
2828

2929
ERight = expand_specs(expr_type(ELeft), Meta, Right, ER, RequireSize or MatchSize),

lib/elixir/test/elixir/kernel/expansion_test.exs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,6 +1180,14 @@ defmodule Kernel.ExpansionTest do
11801180
assert_raise CompileError, ~r"unhandled operator ->", fn ->
11811181
expand(quote do: (foo -> bar))
11821182
end
1183+
1184+
assert_raise CompileError,
1185+
~r"size in bitstring expects an integer or a variable as argument, got: foo\(\)",
1186+
fn ->
1187+
expand(quote do
1188+
fn <<_::size(foo)>> -> :ok end
1189+
end)
1190+
end
11831191
end
11841192

11851193
## Helpers

0 commit comments

Comments
 (0)