Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/decimal.ex
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ defmodule Decimal do
defmacro is_decimal(term) do
case __CALLER__.context do
nil ->
quote do
quote generated: true do
case unquote(term) do
%Decimal{} -> true
_ -> false
Expand All @@ -299,7 +299,7 @@ defmodule Decimal do
else
# TODO: remove when we require Elixir v1.10
defmacro is_decimal(term) do
quote do
quote generated: true do
case unquote(term) do
%Decimal{} -> true
_ -> false
Expand Down
12 changes: 9 additions & 3 deletions test/decimal_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,10 @@ defmodule DecimalTest do
assert Decimal.new(d(-1, 3, 2)) == d(-1, 3, 2)
assert Decimal.new(123) == d(1, 123, 0)

# apply/3 keeps the intentionally invalid argument opaque to the
# type checker; the raise is the point.
assert_raise FunctionClauseError, fn ->
Decimal.new(:atom)
apply(Decimal, :new, [:atom])
end
end

Expand Down Expand Up @@ -943,8 +945,10 @@ defmodule DecimalTest do
fn -> Decimal.to_integer(d(1, 1001, -2)) end
)

# apply/3 keeps the intentionally invalid argument opaque to the
# type checker; the raise is the point.
assert_raise FunctionClauseError, fn ->
Decimal.to_integer(d(1, :NaN, 0))
apply(Decimal, :to_integer, [d(1, :NaN, 0)])
end
end)
end
Expand Down Expand Up @@ -1401,8 +1405,10 @@ defmodule DecimalTest do
end

test "issue #60" do
# apply/3 keeps the intentionally invalid argument opaque to the
# type checker; the raise is the point.
assert_raise(FunctionClauseError, "no function clause matching in Decimal.decimal/1", fn ->
Decimal.round(nil)
apply(Decimal, :round, [nil])
end)
end

Expand Down