Ensure arithmetic constants are supported in function heads
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user