Given the following module definition:

defmodule MyMod do
  def fun_1 do
    0
  end

  def fun_2 do
    fon_1 + 1
  endend

…Elixir provides a nice compile-time error informing me that MyMod.fon_1/1
does not exist:

** (CompileError) test/foo_test.exs:7: undefined function fon_1/0
    (stdlib) lists.erl:1337: :lists.foreach/2
    (stdlib) erl_eval.erl:669: :erl_eval.do_apply/6
    (stdlib) erl_eval.erl:122: :erl_eval.exprs/5

But if I call an undefined remote function:

defmodule MyMod do
  def fun_1 do
    0
  end

  def fun_2 do
    MyMod.fon_1 + 1
  endend

…then Elixir does not provide a compile-time error. Instead, a runtime
error is raised when fun_2 is called:

     ** (UndefinedFunctionError) undefined function MyMod.fon_1/0
     stacktrace:
       MyMod.fon_1()
       test/foo_test.exs:7: MyMod.fun_2/0
       test/foo_test.exs:15

Is there anything preventing Elixir from providing a compile-time error in
this case? Obviously, if a remote function call is made using a module
variable (e.g. var.foo()) the compiler can’t statically know what functions
var exports. But if the remote function call is made on a static alias, it
seems like the compiler should be able to figure it out.

Thanks,
Mron
​

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/CADUxQmtuLSokWRJA0prd9bnguSepcYL6fyFWcTA%3Dw%2BntNYn88A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to