Skip to content

Commit ba02eb9

Browse files
ericmjJosé Valim
authored andcommitted
Allow any type on the RHS of or/2 (#9706)
Closes #9704.
1 parent fdc7716 commit ba02eb9

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

lib/elixir/lib/module/types.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ defmodule Module.Types do
5757
def of_head(params, guards, stack, context) do
5858
with {:ok, types, context} <-
5959
map_reduce_ok(params, context, &Pattern.of_pattern(&1, stack, &2)),
60-
# TODO: Check that of_guard/3 returns a boolean
60+
# TODO: Check that of_guard/3 returns boolean() | :fail
6161
{:ok, _, context} <- Pattern.of_guard(guards_to_or(guards), stack, context),
6262
do: {:ok, lift_types(types, context), context}
6363
end

lib/elixir/lib/module/types/pattern.ex

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,10 +333,9 @@ defmodule Module.Types.Pattern do
333333
fresh_context = fresh_context(context)
334334

335335
with {:ok, left_type, left_context} <- of_guard(left, stack, fresh_context),
336-
{:ok, right_type, right_context} <- of_guard(right, stack, fresh_context),
336+
{:ok, _right_type, right_context} <- of_guard(right, stack, fresh_context),
337337
{:ok, context} <- merge_context_or(context, stack, left_context, right_context),
338338
{:ok, _, context} <- unify(left_type, :boolean, stack, context),
339-
{:ok, _, context} <- unify(right_type, :boolean, stack, context),
340339
do: {:ok, :boolean, context}
341340
end
342341

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,11 @@ defmodule Module.Types.PatternTest do
225225
assert {:ok, :dynamic, context} = quoted_guard([x], elem(x, 0))
226226
assert Types.lift_type({:var, 0}, context) == :tuple
227227

228+
assert {:ok, {:atom, true}, context} = quoted_guard([], true)
229+
assert {:ok, {:atom, false}, context} = quoted_guard([], false)
230+
assert {:ok, {:atom, :fail}, context} = quoted_guard([], :fail)
231+
assert {:ok, :boolean, context} = quoted_guard([], is_atom(true or :fail))
232+
228233
assert {:error, {_, {:unable_unify, :tuple, :boolean, _, _}, _}} =
229234
quoted_guard([x], is_tuple(x) and is_boolean(x))
230235
end

0 commit comments

Comments
 (0)