Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn unknown atom #1265

Closed
wants to merge 3 commits into from
Closed

Warn unknown atom #1265

wants to merge 3 commits into from

Conversation

richcarl
Copy link
Contributor

@richcarl richcarl commented Dec 1, 2016

Reworked an old suggestion of mine to have an option warn_unknown_atom, which can be useful for avoiding misspelled atoms, or just ensuring all used atoms are documented (such as options/flags, or tagged tuples). This version uses Kenneth's suggestion to rely on the -type specifications rather than adding a new kind of declaration. See http://erlang.org/pipermail/erlang-questions/2012-February/064117.html for the discussion.

@bjorng bjorng added the waiting waiting for changes/input from author label Dec 6, 2016
@bjorng
Copy link
Contributor

bjorng commented Dec 6, 2016

Did you notice "All checks have failed"? Not sure why, but your changes in erl_lint breaks dialyzer.

@kostis
Copy link
Contributor

kostis commented Dec 6, 2016

It may well be that this is a Travis hiccup. Perhaps it's a good idea for somebody (with proper authority) to press the Restart build button on Travis and see whether that fixes the problem or reproduces the same symptoms.

@richcarl
Copy link
Contributor Author

richcarl commented Dec 6, 2016

No, one of my changes triggered an error for recursively defined records. Fixing...

Richard Carlsson added 2 commits December 6, 2016 13:27
Also need to ensure that recursive record definitions are accepted.
@richcarl
Copy link
Contributor Author

richcarl commented Dec 6, 2016

Had to make some larger changes to how record fields are processed. Might interest Kostis.

@kostis
Copy link
Contributor

kostis commented Dec 6, 2016

Kostis has recently made sure that dialyzer is enabled on Travis to catch even logical errors such as the one that the test failure currently indicates. (I believe that the atoms field of the lint record can never have the value undefined, right?)

More interesting to commenting on the code, to me at least, would be to see the effect that this change has to various Erlang/OTP files when enabled. I would be willing to take it for a test drive to HiPE and Dialyzer (but also to PropEr and CutEr) files once this gets merged to the repository. Hope this happens soon.

This option is off by default. If enabled, a warning will be generated for
each atom in a module that does not occur in some type declaration; for
example -type foobar() :: foo | {bar, any()} declares atoms foo and bar.
The compiler knows about standard atoms that occur in most Erlang/OTP
modules, such as `true', `false', `ok', `undefined', etc.
@@ -112,6 +112,10 @@ value_option(Flag, Default, On, OnVal, Off, OffVal, Opts) ->
on_load=[] :: [fa()], %On-load function
on_load_line=erl_anno:new(0) %Line for on_load
:: erl_anno:anno(),
atoms=undefined %Declared atoms
:: undefined
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not do that. It's fundamentally not OK to mix an opaque type with a structured one because it requires that you pattern match on a structure to distinguish between them (which breaks the opacity of the opaque type). It's probably the case that the current version of dialyzer does not disallow this, but it's quite likely that a future version will. It's much better that the code is ready for that time.

@KennethL
Copy link
Contributor

KennethL commented Dec 9, 2016

For the same reason as I don't think checking of remote calls should be done in the linter I don't think this check should be in the linter even if I suggested that in an old post.
The reason is that the specs and type in the module under compilation might refer to types defined i other modules and the principle we want to keep is that the compiler should not look into other modules while compiling one module.
This is also about having a deterministic behavior. It is not well defined which modules the compiler will look into.
Checking like this should be done in a separate pass in a separate tool when all modules that should be involved are already built and the set of modules is explicitly specified.

A possible step in the direction where checking like this could span over module borders would be an introduction of a "compile_application" function which takes all modules in an application an handles them together possibly producing an archive as output and maybe as input as well.

@richcarl
Copy link
Contributor Author

richcarl commented Dec 9, 2016

@KennethL Glad to note that you see where I'm going with this. :-)

@bjorng bjorng closed this Dec 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature waiting waiting for changes/input from author
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants