Skip to content

Commit 33ee657

Browse files
committed
Properly handle column for 'in' in 'not in' operator
Closes #14681.
1 parent b87a9fa commit 33ee657

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

lib/elixir/src/elixir_parser.yrl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -752,8 +752,9 @@ build_op({UOp, _, [Left]}, {_Kind, {Line, Column, _} = Location, 'in'}, Right) w
752752
{UOp, Meta, [{'in', Meta, [Left, Right]}]};
753753

754754
build_op(Left, {_Kind, Location, 'not in'}, Right) ->
755-
Meta = meta_from_location(Location),
756-
{'not', Meta, [{'in', Meta, [Left, Right]}]};
755+
NotMeta = meta_from_location(Location),
756+
InMeta = meta_from_location(element(3, Location)),
757+
{'not', NotMeta, [{'in', InMeta, [Left, Right]}]};
757758

758759
build_op(Left, {_Kind, Location, Op}, Right) ->
759760
{Op, newlines_op(Location) ++ meta_from_location(Location), [Left, Right]}.

lib/elixir/src/elixir_tokenizer.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,8 +1670,8 @@ tokenize_keyword(Kind, Rest, Line, Column, Atom, Length, Scope, Tokens) ->
16701670

16711671
_ ->
16721672
case {Kind, Tokens} of
1673-
{in_op, [{unary_op, NotInfo, 'not'} | T]} ->
1674-
add_token_with_eol({in_op, NotInfo, 'not in'}, T);
1673+
{in_op, [{unary_op, {NotLine, NotColumn, _}, 'not'} | T]} ->
1674+
add_token_with_eol({in_op, {NotLine, NotColumn, {Line, Column, nil}}, 'not in'}, T);
16751675

16761676
{_, _} ->
16771677
add_token_with_eol({Kind, {Line, Column, previous_was_eol(Tokens)}, Atom}, Tokens)

lib/elixir/test/elixir/kernel/parser_test.exs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,22 @@ defmodule Kernel.ParserTest do
447447
{:ok, {:=, context, [List.to_string(nfd_abba), 1]}}
448448
end
449449

450+
test "not in" do
451+
assert Code.string_to_quoted!("a not in b", columns: true) ==
452+
{:not, [line: 1, column: 3],
453+
[
454+
{:in, [line: 1, column: 7],
455+
[{:a, [line: 1, column: 1], nil}, {:b, [line: 1, column: 10], nil}]}
456+
]}
457+
458+
assert Code.string_to_quoted!("a not in b", columns: true) ==
459+
{:not, [line: 1, column: 3],
460+
[
461+
{:in, [line: 1, column: 8],
462+
[{:a, [line: 1, column: 1], nil}, {:b, [line: 1, column: 11], nil}]}
463+
]}
464+
end
465+
450466
test "handles maps and structs" do
451467
assert Code.string_to_quoted("%{}", columns: true) ==
452468
{:ok, {:%{}, [line: 1, column: 1], []}}

0 commit comments

Comments
 (0)