|Anonymous | Login | Signup for a new account||2014-03-10 08:01 CET|
|Main | My View | View Issues | Change Log | Roadmap|
|View Issue Details|
|ID||Project||Category||View Status||Date Submitted||Last Update|
|0006202||OCaml||OCaml general||public||2013-10-03 17:26||2014-02-19 15:51|
|Priority||normal||Severity||minor||Reproducibility||have not tried|
|Target Version||Fixed in Version|
|Summary||0006202: Controlling warnings locally|
|Description||It would be useful to specify the warning behavior (which ones are enabled, which ones are turned into errors) locally, within the source code itself, and even better, to have local control within a single unit.|
For instance, it makes sense to disable some "unused stuff" warnings locally on a piece of code under development. Or locally disable warning 40 (label/constructor used out of scope) in a specific piece of code which makes heavy use of this feature (while not allowing it for the whole project or unit).
What about using attributes to control this behavior? One could either rely on "floating item attributes":
;;[@@warning "-32..39" ]
and/or interpret attributes on expressions/module expression/etc:
let x =
module X = struct end [@warning "-32..39"]
|Tags||No tags attached.|
|I think this would be very useful for the reasons you mentioned. It could also be useful for open!-like use of the M.(...) syntax.|
I think this is a good idea, but we must be very careful about readability and clarity of the semantics.
This changes the compiler behaviour, so you want to now exactly the scope of the change, at first sight.
From this point of view, your "begin" example would nice.
Having the attribute after the expression might make this less clear.
Commit 14214 on trunk: the 'warning' attribute is interpreted on expressions (the scope is restricted to the target expression) and in floating signature/structure attributes (with a global scope, not even restricted to the current signature or structure). There is a subtle interaction between the two: when an expression has a 'warning' attribute, the state of warnings before the expression is type-checked is restored after the expression has been type-checked, which cancels the effect of floating attributes within the expression (in a local module expression under that expression).
- The 'warning' attribute on expression will probably be used with the form:
but this is strictly equivalent to the postfix notation:
(...) [@warning "..."]
- The 'warning' attribute is not interpreted on other syntactic categories (patterns, module expressions, class expressions).
- Floating item attributes can appear at the beginning of a signature or structure (hence at the beginning of a compilation unit), or after a ";;" token within a structure or signature. They can now also be used in the top-level, which means one can simply type [@@warning "..."];; as a toplevel phrase.
- The commit also adds a new warning to report in illegal payload for the 'warning' attribute.
Comments are welcome!
|As a side note, we should start putting a list of these "reserved" attributes somewhere so that people know not to use them for their own extensions.|
A warning could be added to indicate that some warnings were turned off/on locally, so that using this new warning can be used on the command line to remove all locally turned on/off warnings.
+1 on having the possibility to have attributes before items they refer to, not only after.
> we should start putting a list of these "reserved" attributes
Do you think we should use a special namespace convention for attributes which are given a special meaning by the OCaml compiler itself? E.g. [@ocaml.deprecated], [@ocaml.warning] ?
+1000 on Maxence's idea of a new warning that gets triggered every time this feature is used.
Even if we don't do it now, I'm sure the Frama-C developers will demand it.
|A special or reserved attribute prefix for attributes provided by the OCaml compiler is a useful idea. These attributes don't require an extra ppx - it's nice to immediately know which attributes can be used without external tools.|
|2013-10-03 17:26||frisch||New Issue|
|2013-10-03 21:14||hcarty||Note Added: 0010426|
|2013-10-04 01:16||garrigue||Note Added: 0010427|
|2013-10-04 10:25||frisch||Note Added: 0010428|
|2013-10-04 12:49||lpw25||Note Added: 0010429|
|2013-10-04 12:55||guesdon||Note Added: 0010430|
|2013-10-04 13:21||frisch||Note Added: 0010431|
|2013-10-04 13:21||frisch||Assigned To||=> frisch|
|2013-10-04 13:21||frisch||Status||new => assigned|
|2014-02-19 15:32||doligez||Note Added: 0010945|
|2014-02-19 15:51||hcarty||Note Added: 0010946|
|Copyright © 2000 - 2011 MantisBT Group|