Skip to content

Commit fc7d8de

Browse files
authored
Remove dialyzer workarounds (#12014)
1 parent c47b731 commit fc7d8de

File tree

1 file changed

+14
-23
lines changed

1 file changed

+14
-23
lines changed

lib/ex_unit/lib/ex_unit/assertions.ex

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,6 @@ defmodule ExUnit.Assertions do
106106
defmacro assert({:=, meta, [left, right]} = assertion) do
107107
code = escape_quoted(:assert, meta, assertion)
108108

109-
# If the match works, we need to check if the value
110-
# is not nil nor false. We need to rewrite the if
111-
# to avoid silly dialyzer warnings though.
112109
check =
113110
quote generated: true do
114111
if right do
@@ -151,15 +148,13 @@ defmodule ExUnit.Assertions do
151148
{args, value} = extract_args(assertion, __CALLER__)
152149

153150
quote generated: true do
154-
case unquote(value) do
155-
value when value in [nil, false] ->
156-
raise ExUnit.AssertionError,
157-
args: unquote(args),
158-
expr: unquote(escape_quoted(:assert, [], assertion)),
159-
message: "Expected truthy, got #{inspect(value)}"
160-
161-
value ->
162-
value
151+
if value = unquote(value) do
152+
value
153+
else
154+
raise ExUnit.AssertionError,
155+
args: unquote(args),
156+
expr: unquote(escape_quoted(:assert, [], assertion)),
157+
message: "Expected truthy, got #{inspect(value)}"
163158
end
164159
end
165160
end
@@ -213,18 +208,14 @@ defmodule ExUnit.Assertions do
213208
else
214209
{args, value} = extract_args(assertion, __CALLER__)
215210

216-
# if value, raise
217-
# We need to rewrite it to avoid dialyzer warnings though.
218211
quote generated: true do
219-
case unquote(value) do
220-
value when value in [nil, false] ->
221-
value
222-
223-
value ->
224-
raise ExUnit.AssertionError,
225-
args: unquote(args),
226-
expr: unquote(escape_quoted(:refute, [], assertion)),
227-
message: "Expected false or nil, got #{inspect(value)}"
212+
if value = unquote(value) do
213+
raise ExUnit.AssertionError,
214+
args: unquote(args),
215+
expr: unquote(escape_quoted(:refute, [], assertion)),
216+
message: "Expected false or nil, got #{inspect(value)}"
217+
else
218+
value
228219
end
229220
end
230221
end

0 commit comments

Comments
 (0)