[erlang-patches] add compiler checked atoms
Richard Carlsson
carlsson.richard@REDACTED
Sun Feb 5 22:15:43 CET 2012
Sorry, pressed send too soon in the last attempt. Here is the code:
git fetch git@REDACTED:richcarl/otp.git warn-unknown-atom
Here is a suggested patch to the compiler, that I'm throwing out there
as a request for comments. In any large code base, it can be hard to
maintain atom hygiene - you may have hidden errors due to misspelled
atoms, people may be adding atoms without much thought, and it can be
hard to track which atoms are being used where and for what (e.g., atoms
used for options, error indicators, message tags, callback module and
function names, etc. This allows you to declare your atoms like so:
-atoms([foo, bar]).
You can have any number of such declarations, and an atom may occur
multiple times and/or in different declarations - it's the union of
known atoms that matters. Note that this declaration is backwards
compatible; the current compiler will accept it as a generic attribute
with no particular meaning.
If you specify the compiler option `warn_unused_atom' when compiling a
module (you can put `-compile([warn_unused_atom]).' in the module if you
want to enable the checking in that module only), you will get a warning
for each atom that has not been explicitly declared. The compiler knows
about standard atoms such as `ok', `true', `false', `undefined' etc.,
and it does not check function and module names in calls, or record
names and fields of records, since these are checked in other ways already.
I don't think this addition warrants an EEP, since it doesn't change the
language as such; it only adds a backwards compatible feature to the
compiler. However, I'd like to get some initial feedback before I bother
to update the documentation and submit it as a full patch.
git@REDACTED:richcarl/otp.git
/Richard
More information about the erlang-patches
mailing list