Macros with try/rescue fail to compile when used inside tuples

44 views
Skip to first unread message

Sébastien Merle

unread,
Mar 30, 2015, 6:06:16 PM3/30/15
to elixir-l...@googlegroups.com
Hi,

the following macro compile if used as in good/2 but if used as in bad/2 elixir fail to compile with the error :ambiguous_catch_try_state (see the full error at the end).
Where does the ambiguity is coming from ?

defmodule TestMacro do
  defmacro macro(value) do
    quote do
      try do
        raise ArgumentError, message: "#{inspect unquote(value)}"
      rescue
        ArgumentError -> :error
      end
    end
  end
end

defmodule Test do
  import TestMacro
  def good(a, b) do
    a = TestMacro.macro(a)
    b = TestMacro.macro(b)
    {a, b}
  end
  def bad(a, b) do
    {TestMacro.macro(a), TestMacro.macro(b)}
  end
end


== Compilation error on file test.ex ==
** (FunctionClauseError) no function clause matching in :elixir_errors.handle_file_error/2
    (elixir) src/elixir_errors.erl:170: :elixir_errors.handle_file_error("Elixir.Test", {:beam_validator, {{Test, :bad, 2}, {{:bs_append, {:f, 0}, {:integer, 0}, 0, 1, 8, {:x, 0}, {:field_flags, []}, {:x, 1}}, 54, :ambiguous_catch_try_state}}})
    (stdlib) lists.erl:1336: :lists.foreach/2
    (stdlib) lists.erl:1336: :lists.foreach/2
    (stdlib) erl_eval.erl:657: :erl_eval.do_apply/6

** (exit) shutdown: 1
    (elixir) lib/kernel/parallel_compiler.ex:199: Kernel.ParallelCompiler.handle_failure/5
    (elixir) lib/kernel/parallel_compiler.ex:182: Kernel.ParallelCompiler.wait_for_messages/8
    (elixir) lib/kernel/parallel_compiler.ex:55: Kernel.ParallelCompiler.spawn_compilers/3
       (iex) lib/iex/helpers.ex:94: IEx.Helpers.c/2

José Valim

unread,
Mar 30, 2015, 8:33:22 PM3/30/15
to elixir-l...@googlegroups.com
Definitely a bug. can you please do a bug report on our issues tracker? Thank you!



José Valim
Skype: jv.ptec
Founder and Lead Developer

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/0288eee5-5555-49e7-bcf8-5efa291f8362%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages