-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Suggestion: mnemonic aliases for warning codes #7823
Description
Original bug ID: 7823
Reporter: @mjambon
Status: new
Resolution: open
Priority: normal
Severity: feature
Category: misc
Monitored by: @nojb @gasche @alainfrisch
Bug description
The identifiers of warnings emitted by the OCaml compilers are currently numeric and require looking them up whenever they're encountered in code. Having numeric IDs is fine when a warning takes place and it's reported by the compiler with a description of the problem. But in other cases, having only a numeric code is unhelpful and requires the reader to look it up. These situations include:
- Instructions to the build system which override the default set of warnings or errors e.g.
FLAGS = -w +42 - Inline annotations to locally disable a warning e.g.
[@@@warning "-56"]
One solution is to have the programmer add a comment reminding the reader what the warning is about, but it's a bit of work for the programmer to copy-paste the description of the warning or make up their own. Instead, I'm suggesting that English-based aliases be provided as an alternative to numeric warning codes.
I understand there's a whole art involved in creating aliases that are not too long and yet sufficiently helpful in remembering what they mean. For instance, perhaps warning 42 "Disambiguated constructor or label name." could be aliased to --disamb-cons.
In terms of syntax, we could mix numeric and non-numeric codes as in -w +41+-disamb-cons--something-else. Or maybe -w +41+:disamb-cons:+:something-else:. Visually, I find -w +41+{disamb-cons,something-else} more satisfying but it doesn't play well with unix shells. Yet another option, since there's not much value in supporting a notion of range with non-numeric identifiers, is to have one command line option for each warning that we want to add or remove: -w +disamb-cons -w -something-else would be used to turn on "disamb-cons" and turn off "something-else". In this case, a lowercase letter following a plus or minus is what would indicate the beginning of a multi-character warning identifier. For inline overrides, perhaps then we could have [@@@warning "+disamb-cons -something-else +15..20-18"].