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
11 changes: 7 additions & 4 deletions lib/elixir/src/elixir_with.erl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ expand(Meta, Args, E) ->

{ECases, EC} = lists:mapfoldl(fun expand/2, E, Cases),
{EDoExpr, _} = elixir_exp:expand(DoExpr, EC),
{EElseExpr, _} = expand_else(ElseExpr, E),
{EElseExpr, _} = expand_else(Meta, ElseExpr, E),
{{with, Meta, ECases ++ [[{do, EDoExpr} | EElseExpr]]}, E}.

expand({'<-', Meta, [Left, Right]}, E) ->
Expand All @@ -55,11 +55,14 @@ expand({'<-', Meta, [Left, Right]}, E) ->
expand(X, E) ->
elixir_exp:expand(X, E).

expand_else(KV, E) when is_list(KV) ->
expand_else(_Meta, KV, E) when is_list(KV) ->
{[{do, EClauses}], EC} = elixir_exp_clauses:'case'([], [{do, KV}], E),
{[{else, EClauses}], EC};
expand_else(nil, E) ->
{[], E}.
expand_else(_Meta, nil, E) ->
{[], E};
expand_else(Meta, _KV, E) ->
Message = "expected -> clauses for else in with",
elixir_errors:compile_error(Meta, ?m(E, file), Message, []).

%% Translation

Expand Down
6 changes: 6 additions & 0 deletions lib/elixir/test/elixir/kernel/with_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ defmodule Kernel.WithTest do
end
end

test "invalid else form" do
assert_raise CompileError, "nofile:1: expected -> clauses for else in with", fn ->
Code.eval_quoted(quote do: with(_ <- true, do: :ok, else: :error))
end
end

defp four() do
4
end
Expand Down