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
10 changes: 10 additions & 0 deletions lib/elixir/lib/code/formatter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,16 @@ defmodule Code.Formatter do
operand_to_algebra_with_comments(pipes, meta, state, fun)
end

# TODO: We can remove this workaround once we remove
# ?rearrange_uop from the parser on v2.0.
# (! left) in right
# (not left) in right
defp binary_op_to_algebra(:in, "in", meta, {op, _, [_]} = left, right, context, state, nesting)
when op in [:not, :!] do
left = {:__block__, [], [left]}
binary_op_to_algebra(:in, "in", meta, left, right, context, state, nesting)
end

defp binary_op_to_algebra(op, op_string, meta, left_arg, right_arg, context, state, nesting) do
op_info = augmented_binary_op(op)
left_context = left_op_context(context)
Expand Down
4 changes: 4 additions & 0 deletions lib/elixir/test/elixir/code_formatter/operators_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ defmodule Code.Formatter.OperatorsTest do
assert_same "foo not in bar"
assert_same "(not foo) in bar"
assert_same "(!foo) in bar"
assert_same "!foo not in bar"

assert_format "!!foo in bar", "!((!foo) in bar)"
assert_format "!not foo in bar", "!((not foo) in bar)"
end

test "bitwise precedence" do
Expand Down
2 changes: 2 additions & 0 deletions lib/elixir/test/elixir/code_normalizer/quoted_ast_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ defmodule Code.Normalizer.QuotedASTTest do

test "not in" do
assert quoted_to_string(quote(do: false not in [])) == "false not in []"
assert quoted_to_string({:in, [], [quote(do: !foo), []]}) == "(!foo) in []"
assert quoted_to_string({:in, [], [quote(do: not foo), []]}) == "(not foo) in []"
end

test "if else" do
Expand Down
Loading