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
14 changes: 8 additions & 6 deletions lib/iex/lib/iex/evaluator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -129,18 +129,20 @@ defmodule IEx.Evaluator do
end
end

defp adjust_operator([{op_type, _, token} | _] = _tokens, line, column, _file, _opts, :match)
when op_type in @op_tokens,
# We use elem operations, instead of pattern matching,
# because "not in" tokenizer tuples have four elements.
defp adjust_operator([token | _] = _tokens, line, column, _file, _opts, :match)
Comment thread
josevalim marked this conversation as resolved.
when elem(token, 0) in @op_tokens,
do:
{:error,
{[line: line, column: column],
"pipe shorthand is not allowed immediately after a match expression in IEx. To make it work, surround the whole pipeline with parentheses ",
"'#{token}'"}}
"'#{elem(token, 2)}'"}}

defp adjust_operator([{op_type, _, _} | _] = tokens, line, column, file, opts, _last_op)
when op_type in @op_tokens do
defp adjust_operator([token | _] = tokens, line, column, file, opts, _last_op)
when elem(token, 0) in @op_tokens do
{:ok, prefix, _warnings} = :elixir.string_to_tokens(~c"v(-1)", line, column, file, opts)
{:ok, prefix ++ tokens, op_type}
{:ok, prefix ++ tokens, elem(token, 0)}
end

defp adjust_operator(tokens, _line, _column, _file, _opts, _last_op), do: {:ok, tokens, nil}
Expand Down
4 changes: 4 additions & 0 deletions lib/iex/test/iex/helpers_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1339,6 +1339,7 @@ defmodule IEx.HelpersTest do
assert capture_iex("42\n |> IO.inspect(label: \"foo\")") =~ "foo: 42"
assert capture_iex("[42]\n++ [24]\n|> IO.inspect(label: \"foo\")") =~ "foo: [42, 24]"
assert capture_iex("|> IO.puts()") =~ "(RuntimeError) v(-1) is out of bounds"
assert capture_iex("4\nnot in [1, 2]") == "4\ntrue"
end

test "raises if previous expression was a match" do
Expand All @@ -1350,6 +1351,9 @@ defmodule IEx.HelpersTest do

assert capture_iex("%{x: x} = map = %{x: 42}\n|> IO.puts()") =~
"surround the whole pipeline with parentheses '|>'"

assert capture_iex("x = 4\nnot in [1, 2]") =~
"surround the whole pipeline with parentheses 'not in'"
end
end

Expand Down
Loading