Why this erlang prog with type signature can compile?

I have this prog:


-spec add(integer(),integer())->integer().


I can compile this prog with no error.but I think I should got error for the line


in any static type language,it can't compile,so why erlang will compile this?how to
write the type signature so erlang can catch this error?If erlang can't,can elixir write the same prog but can catch this error?Thanks!


Erlang is not statically typed language, it is always dynamically typed. You cannot catch it during compilation as erlc do not care about -spec, at all. It is used only for documentation and Dialyzer (which technically is external tool) can use it to do some (limited) static analysis of the contracts.

For how to use Dialyzer check out:

  • Documentation of Dialyzer application
  • Rebar3 Dialyzer task documentation
  • erlang.mk Dialyzer guide

Previous : VBA loop with deleting items
Next : Analyse the action of 'set -- $args'