Skip to content

Commit a2baac9

Browse files
committed
Address regressions on 'not in' operator
Closes #14783.
1 parent 5a5e385 commit a2baac9

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

lib/elixir/src/elixir_parser.yrl

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

754-
build_op(Left, {_Kind, Location, 'not in'}, Right) ->
755-
NotMeta = meta_from_location(Location),
756-
InMeta = meta_from_location(element(3, Location)),
754+
build_op(Left, {in_op, NotLocation, 'not in', InLocation}, Right) ->
755+
NotMeta = newlines_op(NotLocation) ++ meta_from_location(NotLocation),
756+
InMeta = meta_from_location(InLocation),
757757
{'not', NotMeta, [{'in', InMeta, [Left, Right]}]};
758758

759759
build_op(Left, {_Kind, Location, Op}, Right) ->

lib/elixir/src/elixir_tokenizer.erl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,12 +1669,14 @@ tokenize_keyword(Kind, Rest, Line, Column, Atom, Length, Scope, Tokens) ->
16691669
[{identifier, {Line, Column, nil}, Atom} | Tokens];
16701670

16711671
_ ->
1672+
Info = {Line, Column, previous_was_eol(Tokens)},
1673+
16721674
case {Kind, Tokens} of
1673-
{in_op, [{unary_op, {NotLine, NotColumn, _}, 'not'} | T]} ->
1674-
add_token_with_eol({in_op, {NotLine, NotColumn, {Line, Column, nil}}, 'not in'}, T);
1675+
{in_op, [{unary_op, NotInfo, 'not'} | T]} ->
1676+
add_token_with_eol({in_op, NotInfo, 'not in', Info}, T);
16751677

16761678
{_, _} ->
1677-
add_token_with_eol({Kind, {Line, Column, previous_was_eol(Tokens)}, Atom}, Tokens)
1679+
add_token_with_eol({Kind, Info, Atom}, Tokens)
16781680
end
16791681
end,
16801682

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,12 +455,33 @@ defmodule Kernel.ParserTest do
455455
[{:a, [line: 1, column: 1], nil}, {:b, [line: 1, column: 10], nil}]}
456456
]}
457457

458-
assert Code.string_to_quoted!("a not in b", columns: true) ==
458+
assert Code.string_to_quoted!("a not in b", columns: true, token_metadata: true) ==
459459
{:not, [line: 1, column: 3],
460460
[
461461
{:in, [line: 1, column: 8],
462462
[{:a, [line: 1, column: 1], nil}, {:b, [line: 1, column: 11], nil}]}
463463
]}
464+
465+
assert Code.string_to_quoted!("a\nnot in b", columns: true, token_metadata: true) ==
466+
{:not, [newlines: 1, line: 2, column: 1],
467+
[
468+
{:in, [line: 2, column: 5],
469+
[{:a, [line: 1, column: 1], nil}, {:b, [line: 2, column: 8], nil}]}
470+
]}
471+
472+
assert Code.string_to_quoted!("a not in\nb", columns: true, token_metadata: true) ==
473+
{:not, [newlines: 1, line: 1, column: 3],
474+
[
475+
{:in, [line: 1, column: 7],
476+
[{:a, [line: 1, column: 1], nil}, {:b, [line: 2, column: 1], nil}]}
477+
]}
478+
479+
assert Code.string_to_quoted!("a\nnot in\nb", columns: true, token_metadata: true) ==
480+
{:not, [newlines: 1, line: 2, column: 1],
481+
[
482+
{:in, [line: 2, column: 5],
483+
[{:a, [line: 1, column: 1], nil}, {:b, [line: 3, column: 1], nil}]}
484+
]}
464485
end
465486

466487
test "handles maps and structs" do

0 commit comments

Comments
 (0)