     quote do
       case Macro.Env.in_guard?(__CALLER__) do
         true -> unquote(literal_quote(unquote_every_ref(expr, vars)))
-        false -> unquote(literal_quote(unquote_refs_once(expr, vars)))
+        false -> unquote(literal_quote(unquote_refs_once(expr, vars, env.module)))
       end
     end
   end


                %{} ->
                  generated = String.to_atom("arg" <> Integer.to_string(map_size(acc) + 1))
                  new_var = Macro.unique_var(generated, Elixir)
                  {new_var, Map.put(acc, pair, {new_var, var})}
              end


  end

  # Prefaces `guard` with unquoted versions of `refs`.
  defp unquote_refs_once(guard, refs, module) do
    {guard, used_refs} =
      Macro.postwalk(guard, %{}, fn
        {ref, meta, context} = var, acc when is_atom(ref) and is_atom(context) ->
