Skip to content

Commit 5ce7ee2

Browse files
author
José Valim
committed
Ensure arithmetic constants are supported in function heads
1 parent c1bcf5d commit 5ce7ee2

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

lib/elixir/lib/kernel.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,7 @@ defmodule Kernel do
10461046
10471047
"""
10481048
defmacro left + right do
1049-
quote do: :erlang.+(unquote(left), unquote(right))
1049+
quote do: __op__(:+, unquote(left), unquote(right))
10501050
end
10511051

10521052
@doc """
@@ -1059,7 +1059,7 @@ defmodule Kernel do
10591059
10601060
"""
10611061
defmacro left - right do
1062-
quote do: :erlang.-(unquote(left), unquote(right))
1062+
quote do: __op__(:-, unquote(left), unquote(right))
10631063
end
10641064

10651065
@doc """
@@ -1100,7 +1100,7 @@ defmodule Kernel do
11001100
11011101
"""
11021102
defmacro left * right do
1103-
quote do: :erlang.*(unquote(left), unquote(right))
1103+
quote do: __op__(:*, unquote(left), unquote(right))
11041104
end
11051105

11061106
@doc """
@@ -1117,7 +1117,7 @@ defmodule Kernel do
11171117
11181118
"""
11191119
defmacro left / right do
1120-
quote do: :erlang./(unquote(left), unquote(right))
1120+
quote do: __op__(:/, unquote(left), unquote(right))
11211121
end
11221122

11231123
@doc """

lib/elixir/test/elixir/kernel/fn_test.exs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ defmodule Kernel.FnTest do
44
use ExUnit.Case, async: true
55
import CompileAssertion
66

7+
test "arithmetic constants on match" do
8+
assert (fn 1 + 2 -> :ok end).(3) == :ok
9+
assert (fn 1 - 2 -> :ok end).(-1) == :ok
10+
assert (fn -1 -> :ok end).(-1) == :ok
11+
assert (fn +1 -> :ok end).(1) == :ok
12+
end
13+
714
test "clause with ^" do
815
x = 1
916
assert (fn ^x -> :ok; _ -> :error end).(1) == :ok

0 commit comments

Comments
 (0)