Skip to content

Commit 8b66976

Browse files
author
José Valim
committed
Ensure Macro.to_binary work with unary not
1 parent 36e6261 commit 8b66976

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

lib/elixir/lib/macro.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,10 @@ defmodule Macro do
246246
end
247247

248248
# Unary ops
249+
def to_binary({ :not, _, [arg] }) do
250+
"not " <> to_binary(arg)
251+
end
252+
249253
def to_binary({ op, _, [arg] }) when op in unary_ops do
250254
atom_to_binary(op, :utf8) <> to_binary(arg)
251255
end

lib/elixir/test/elixir/macro_test.exs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ defmodule MacroTest do
245245
end
246246

247247
test :unary_ops_to_binary do
248+
assert Macro.to_binary(quote do: not 1) == "not 1"
249+
assert Macro.to_binary(quote do: not foo) == "not foo"
248250
assert Macro.to_binary(quote do: -1) == "-1"
249251
assert Macro.to_binary(quote do: @foo(bar)) == "@foo(bar)"
250252
end

0 commit comments

Comments
 (0)