Skip to content

Commit f00cb3a

Browse files
committed
Properly handle bitstrings inside guards, closes #15052
1 parent 9af054f commit f00cb3a

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

lib/elixir/lib/module/types/of.ex

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ defmodule Module.Types.Of do
1212
@suffix quote(do: ...)
1313

1414
@integer_or_float union(integer(), float())
15-
@integer_or_binary union(integer(), binary())
1615
@integer integer()
1716
@float float()
1817
@binary binary()
@@ -543,7 +542,7 @@ defmodule Module.Types.Of do
543542
Module.Types.Pattern.of_match_var(left, type, expr, stack, context)
544543

545544
:guard ->
546-
Module.Types.Pattern.of_guard(left, {false, type}, expr, stack, context)
545+
Module.Types.Pattern.of_guard(left, type, expr, stack, context)
547546

548547
:expr ->
549548
left = annotate_interpolation(left, right)
@@ -591,9 +590,9 @@ defmodule Module.Types.Of do
591590
defp specifier_type(:match, {:utf32, _, _}), do: {@integer, :aligned}
592591
defp specifier_type(:match, {:float, _, _}), do: {@float, :aligned}
593592
defp specifier_type(_kind, {:float, _, _}), do: {@integer_or_float, :aligned}
594-
defp specifier_type(_kind, {:utf8, _, _}), do: {@integer_or_binary, :aligned}
595-
defp specifier_type(_kind, {:utf16, _, _}), do: {@integer_or_binary, :aligned}
596-
defp specifier_type(_kind, {:utf32, _, _}), do: {@integer_or_binary, :aligned}
593+
defp specifier_type(_kind, {:utf8, _, _}), do: {@integer, :aligned}
594+
defp specifier_type(_kind, {:utf16, _, _}), do: {@integer, :aligned}
595+
defp specifier_type(_kind, {:utf32, _, _}), do: {@integer, :aligned}
597596
defp specifier_type(_kind, {:integer, _, _}), do: {@integer, :integer}
598597
defp specifier_type(_kind, {:bits, _, _}), do: {@bitstring, :bitstring}
599598
defp specifier_type(_kind, {:bitstring, _, _}), do: {@bitstring, :bitstring}

lib/elixir/test/elixir/module/types/pattern_test.exs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,11 @@ defmodule Module.Types.PatternTest do
831831
assert typecheck!([x], not (x !== "foo"), x) == dynamic(binary())
832832
end
833833

834+
test "with binaries" do
835+
assert typecheck!([sep, token], token == <<sep::utf8>>, {sep, token}) ==
836+
dynamic(tuple([integer(), term()]))
837+
end
838+
834839
test "with number literals" do
835840
assert typecheck!([x], x == 1, x) == dynamic(union(integer(), float()))
836841
assert typecheck!([x], x === 1, x) == dynamic(integer())

0 commit comments

Comments
 (0)