Ensure arithmetic constants are supported in function heads

This commit is contained in:
José Valim
2013-12-15 22:10:33 +01:00
parent c1bcf5dab2
commit 5ce7ee2e3b
2 changed files with 11 additions and 4 deletions
+4 -4
View File
@@ -1046,7 +1046,7 @@ defmodule Kernel do
"""
defmacro left + right do
quote do: :erlang.+(unquote(left), unquote(right))
quote do: __op__(:+, unquote(left), unquote(right))
end
@doc """
@@ -1059,7 +1059,7 @@ defmodule Kernel do
"""
defmacro left - right do
quote do: :erlang.-(unquote(left), unquote(right))
quote do: __op__(:-, unquote(left), unquote(right))
end
@doc """
@@ -1100,7 +1100,7 @@ defmodule Kernel do
"""
defmacro left * right do
quote do: :erlang.*(unquote(left), unquote(right))
quote do: __op__(:*, unquote(left), unquote(right))
end
@doc """
@@ -1117,7 +1117,7 @@ defmodule Kernel do
"""
defmacro left / right do
quote do: :erlang./(unquote(left), unquote(right))
quote do: __op__(:/, unquote(left), unquote(right))
end
@doc """
@@ -4,6 +4,13 @@ defmodule Kernel.FnTest do
use ExUnit.Case, async: true
import CompileAssertion
test "arithmetic constants on match" do
assert (fn 1 + 2 -> :ok end).(3) == :ok
assert (fn 1 - 2 -> :ok end).(-1) == :ok
assert (fn -1 -> :ok end).(-1) == :ok
assert (fn +1 -> :ok end).(1) == :ok
end
test "clause with ^" do
x = 1
assert (fn ^x -> :ok; _ -> :error end).(1) == :ok