Skip to content

Commit aea1a47

Browse files
committed
Only infer size in pinned variable when needed (#13423)
1 parent eeba8e9 commit aea1a47

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

lib/elixir/src/elixir_bitstring.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ expand(BitstrMeta, Fun, [{'::', Meta, [Left, Right]} | T], Acc, S, E, Alignment,
3636
MatchOrRequireSize = RequireSize or is_match_size(T, EL),
3737
EType = expr_type(ELeft),
3838
ExpectSize = case ELeft of
39+
_ when not MatchOrRequireSize -> optional;
3940
{'^', _, [{_, _, _}]} -> {infer, ELeft};
40-
_ when MatchOrRequireSize -> required;
41-
_ -> optional
41+
_ -> required
4242
end,
4343
{ERight, EAlignment, SS, ES} = expand_specs(EType, Meta, Right, SL, OriginalS, EL, ExpectSize),
4444

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,12 @@ defmodule Kernel.BinaryTest do
255255
assert <<1::size((^foo).bar)>> = <<1::5>>
256256
end
257257

258+
test "bitsyntax size with pinned integer" do
259+
a = 1
260+
b = <<2, 3>>
261+
assert <<^a, ^b::binary>> = <<1, 2, 3>>
262+
end
263+
258264
test "automatic size computation of matched bitsyntax variable" do
259265
var = "foo"
260266
<<^var::binary, rest::binary>> = "foobar"

0 commit comments

Comments
 (0)