Quantcast

Why Erlang compiler don't check functions in module?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Why Erlang compiler don't check functions in module?

Howld
Dear Developers:
     As a new developer, the result of the compile I hope is clear to indicate the functions in module if exist when I use compiler cmd like "erlc test.erl". But hopeless, if I write code like "elang:spwan(fun test:foo/0)" in erl file, it happens nothing even warning. I think it increases uncertainty with non-English speaking countrie's developers. And if you think so, I will shame on you. What I real want to express is you should have an idea and there is a long way to improve compiler.

Best blessing!

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Why Erlang compiler don't check functions in module?

Brujo Benavides-2
Hi HowId,

There is a reason why the compiler can’t tell you that erlang:spwan/1 is not defined.
Fully qualified function calls are bound (I’m not sure if that’s the right word) in runtime.
That way you can have ghost functions or use meck and many other goodies.
That said, there are tools in OTP that would help you find those issues.
To achieve precisely what you are asking for, you have xref (and if it seem to complex for you, don’t panic… you can always use xrefr).
But if you want to catch many other kinds of errors (not just typos in function names) you can should use dialyzer.
And one last thing, if you want those check to happen automatically (which is something truly desirable), you can include the meta suite from katana-test in your common test suites.
Hope this helps :)

On Feb 10, 2017, at 07:21, Howld <[hidden email]> wrote:

Dear Developers:
     As a new developer, the result of the compile I hope is clear to indicate the functions in module if exist when I use compiler cmd like "erlc test.erl". But hopeless, if I write code like "elang:spwan(fun test:foo/0)" in erl file, it happens nothing even warning. I think it increases uncertainty with non-English speaking countrie's developers. And if you think so, I will shame on you. What I real want to express is you should have an idea and there is a long way to improve compiler.

Best blessing!
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Why Erlang compiler don't check functions in module?

John Doe
In reply to this post by Howld
it is not really possible. The module may not exist in compile time at all, it can be dynamically generated or downloaded from, say, remote http server. Or it may exist but the app in runtime can generate another module with the same name and load it instead of еру old one. 
IDEs, such as Intellij IDEA with erlang plugin do generate warnings in these case. But it is not the job for the compiler, as it would make hard to compile apps with stop on warning compile option.

2017-02-10 13:21 GMT+03:00 Howld <[hidden email]>:
Dear Developers:
     As a new developer, the result of the compile I hope is clear to indicate the functions in module if exist when I use compiler cmd like "erlc test.erl". But hopeless, if I write code like "elang:spwan(fun test:foo/0)" in erl file, it happens nothing even warning. I think it increases uncertainty with non-English speaking countrie's developers. And if you think so, I will shame on you. What I real want to express is you should have an idea and there is a long way to improve compiler.

Best blessing!

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions



_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Why Erlang compiler don't check functions in module?

Alex S.
In reply to this post by Howld

> 10 февр. 2017 г., в 13:21, Howld <[hidden email]> написал(а):
>
> Dear Developers:
>      As a new developer, the result of the compile I hope is clear to indicate the functions in module if exist when I use compiler cmd like "erlc test.erl". But hopeless, if I write code like "elang:spwan(fun test:foo/0)" in erl file, it happens nothing even warning. I think it increases uncertainty with non-English speaking countrie's developers. And if you think so, I will shame on you. What I real want to express is you should have an idea and there is a long way to improve compiler.
>
> Best blessing!
Hey HowId,
there’s a nifty «xref» tool you can use that does static analysis necessary to detect such cases. Since functions are loaded in runtime through the code server, the analysis is complex enough that it was decided to be left out of the compiler.

You can either use xref module directly, or use your build system’s support for it, if it has such.

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Loading...