Skip to content

Commit ac072e9

Browse files
committed
compiler: Fix bug in beam_types:subtract/2 for bitstrings
Fix #11494. The bug caused a mismatch between type pass and validator. Valid code would be rejected by the validator.
1 parent c388a2d commit ac072e9

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

lib/compiler/src/beam_types.erl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -399,11 +399,10 @@ subtract(#t_atom{elements=[_|_]=Set0}, #t_atom{elements=[_|_]=Set1}) ->
399399
end;
400400
subtract(#t_bitstring{size_unit=UnitA}=T, #t_bs_matchable{tail_unit=UnitB}) ->
401401
subtract_matchable(T, UnitA, UnitB);
402-
subtract(#t_bitstring{appendable=App,size_unit=UnitA}=T,
403-
#t_bitstring{appendable=App,size_unit=UnitB}) ->
404-
subtract_matchable(T, UnitA, UnitB);
405-
subtract(#t_bitstring{}=T, #t_bitstring{}) ->
402+
subtract(#t_bitstring{appendable=false}=T, #t_bitstring{appendable=true}) ->
406403
T;
404+
subtract(#t_bitstring{size_unit=UnitA}=T, #t_bitstring{size_unit=UnitB}) ->
405+
subtract_matchable(T, UnitA, UnitB);
407406
subtract(#t_bs_context{tail_unit=UnitA}=T, #t_bs_matchable{tail_unit=UnitB}) ->
408407
subtract_matchable(T, UnitA, UnitB);
409408
subtract(#t_bs_context{tail_unit=UnitA}=T, #t_bs_context{tail_unit=UnitB}) ->

lib/compiler/test/beam_ssa_SUITE.erl

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
mapfoldl/0,mapfoldl/1,
2828
grab_bag/1,redundant_br/1,
2929
coverage/1,normalize/1,
30-
trycatch/1,gh_6599/1]).
30+
trycatch/1,gh_6599/1,gh_11494/1]).
3131

3232
suite() -> [{ct_hooks,[ts_install_cth]}].
3333

@@ -51,7 +51,8 @@ groups() ->
5151
coverage,
5252
normalize,
5353
trycatch,
54-
gh_6599
54+
gh_6599,
55+
gh_11494
5556
]}].
5657

5758
init_per_suite(Config) ->
@@ -1555,6 +1556,17 @@ gh_6599_7(X, Y) ->
15551556
ok
15561557
end.
15571558

1559+
gh_11494(_Config) ->
1560+
inspect([100]),
1561+
inspect(<<>>),
1562+
ok.
1563+
1564+
inspect(Value) ->
1565+
case Value of
1566+
Res when erlang:is_integer(Res);
1567+
erlang:is_bitstring(Res) -> Res;
1568+
[Num] -> inspect(Num)
1569+
end.
15581570

15591571
%% The identity function.
15601572
id(I) -> I.

0 commit comments

Comments
 (0)