erlangdialyzer

What are the requirements for position of custom attributes in an Erlang module?


It seems:

Shell session demonstrating:

~ cat sample.erl
-my_attr(my_value).
-module(sample).
-compile([export_all, nowarn_export_all]).

main(_) ->
    ok.

~ erlc sample.erl
sample.erl:1:2: no module definition
%    1| -my_attr(my_value).
%     |  ^

~ dialyzer sample.erl
  Checking whether the PLT /Users/mheiber/Library/Caches/erlang/.dialyzer_plt is up-to-date... yes
  Proceeding with analysis...
dialyzer: Analysis failed with error:
Could not scan the following file(s):
/Users/mheiber/sample.erl:1:2: no module definition

Last messages in the log cache:
  Reading files and computing callgraph...

Is the contract for order of user-defined attributes documented anywhere? Or is this a bug?

All I could find in the docs is that predefined attributes must come before function declarations:

https://www.erlang.org/doc/reference_manual/modules.html#pre-defined-module-attributes


Solution

  • -module(Module).

    Module declaration, defining the name of the module. The name Module, an atom, is to be same as the file name minus the extension .erl. Otherwise code loading does not work as intended.

    This attribute is to be specified first and is the only mandatory attribute.