From 11d6ea577fd1ca92ee4bcf9fbdfc2c398c2bfc2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 30 Mar 2012 10:02:48 +0200 Subject: [PATCH] Ensure in_guards is properly set to true inside args. --- lib/elixir/special_forms.ex | 3 ++- src/elixir_clauses.erl | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/elixir/special_forms.ex b/lib/elixir/special_forms.ex index f74f8cc5ba..6fcc15b714 100644 --- a/lib/elixir/special_forms.ex +++ b/lib/elixir/special_forms.ex @@ -374,7 +374,8 @@ defmodule Elixir.SpecialForms do unexpected, for this reason, we save the result in a variable. In the example above, `in_guard` is allowing us to customize - the same macro to work inside and outside guards. + the same macro to work inside and outside guards. Notice that + `in_guard` is true when inside the arguments clause. """ defmacro in_guard(do: do_block, else: else_block) end \ No newline at end of file diff --git a/src/elixir_clauses.erl b/src/elixir_clauses.erl index 92fc4bc72c..0562960a81 100644 --- a/src/elixir_clauses.erl +++ b/src/elixir_clauses.erl @@ -22,12 +22,12 @@ assigns_block(Line, Fun, BareArgs, Exprs, S) -> assigns_block(Line, Fun, Args, Exprs, extract_guard_clauses(Guards), S). assigns_block(Line, Fun, Args, Exprs, Guards, S) -> - { TArgs, SA } = elixir_clauses:assigns(Fun, Args, S), - { TExprs, SE } = elixir_translator:translate(Exprs, SA), + { TArgs, SA } = elixir_clauses:assigns(Fun, Args, S#elixir_scope{guard=true}), FArgs = listify(TArgs), - SG = SA#elixir_scope{guard=true}, - FGuards = [translate_guard(Line, Guard, SG) || Guard <- Guards], + FGuards = [translate_guard(Line, Guard, SA) || Guard <- Guards], + + { TExprs, SE } = elixir_translator:translate(Exprs, SA#elixir_scope{guard=false}), % Uncompact expressions from the block. case TExprs of