1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366(**************************************************************************)(* *)(* OCaml *)(* *)(* Pierre Weis && Damien Doligez, INRIA Rocquencourt *)(* *)(* Copyright 1998 Institut National de Recherche en Informatique et *)(* en Automatique. *)(* *)(* All rights reserved. This file is distributed under the terms of *)(* the GNU Lesser General Public License version 2.1, with the *)(* special exception on linking described in the file LICENSE. *)(* *)(**************************************************************************)(* When you change this, you need to update:
- the list 'description' at the bottom of this file
- man/ocamlc.m
*)typeloc={loc_start:Lexing.position;loc_end:Lexing.position;loc_ghost:bool;}typefield_usage_warning=|Unused|Not_read|Not_mutatedtypeconstructor_usage_warning=|Unused|Not_constructed|Only_exported_privatetypetype_declaration_usage_warning=|Declaration|Aliastypet=|Comment_start(* 1 *)|Comment_not_end(* 2 *)(*| Deprecated --> alert "deprecated" *)(* 3 *)|Fragile_matchofstring(* 4 *)|Ignored_partial_application(* 5 *)|Labels_omittedofstringlist(* 6 *)|Method_overrideofstringlist(* 7 *)|Partial_matchofFormat_doc.t(* 8 *)|Missing_record_field_patternofstring(* 9 *)|Non_unit_statement(* 10 *)|Redundant_case(* 11 *)|Redundant_subpat(* 12 *)|Instance_variable_overrideofstringlist(* 13 *)|Illegal_backslash(* 14 *)|Implicit_public_methodsofstringlist(* 15 *)|Unerasable_optional_argument(* 16 *)|Undeclared_virtual_methodofstring(* 17 *)|Not_principalofFormat_doc.t(* 18 *)|Non_principal_labelsofstring(* 19 *)|Ignored_extra_argument(* 20 *)|Nonreturning_statement(* 21 *)|Preprocessorofstring(* 22 *)|Useless_record_with(* 23 *)|Bad_module_nameofstring(* 24 *)|All_clauses_guarded(* 8, used to be 25 *)|Unused_varofstring(* 26 *)|Unused_var_strictofstring(* 27 *)|Wildcard_arg_to_constant_constr(* 28 *)|Eol_in_string(* 29 *)|Duplicate_definitionsofstring*string*string*string(*30 *)(* [Module_linked_twice of string * string * string] (* 31 *)
was turned into a hard error *)|Unused_value_declarationofstring(* 32 *)|Unused_openofstring(* 33 *)|Unused_type_declarationofstring*type_declaration_usage_warning(* 34 *)|Unused_for_indexofstring(* 35 *)|Unused_ancestorofstring(* 36 *)|Unused_constructorofstring*constructor_usage_warning(* 37 *)|Unused_extensionofstring*bool*constructor_usage_warning(* 38 *)|Unused_rec_flag(* 39 *)|Name_out_of_scopeofstring*stringlist*bool(* 40 *)|Ambiguous_nameofstringlist*stringlist*bool*string(* 41 *)|Disambiguated_nameofstring(* 42 *)|Nonoptional_labelofstring(* 43 *)|Open_shadow_identifierofstring*string(* 44 *)|Open_shadow_label_constructorofstring*string(* 45 *)|Bad_env_variableofstring*string(* 46 *)|Attribute_payloadofstring*string(* 47 *)|Eliminated_optional_argumentsofstringlist(* 48 *)|No_cmi_fileofstring*stringoption(* 49 *)|Unexpected_docstringofbool(* 50 *)|Wrong_tailcall_expectationofbool(* 51 *)|Fragile_literal_pattern(* 52 *)|Misplaced_attributeofstring(* 53 *)|Duplicated_attributeofstring(* 54 *)|Inlining_impossibleofstring(* 55 *)|Unreachable_case(* 56 *)|Ambiguous_var_in_pattern_guardofstringlist(* 57 *)|No_cmx_fileofstring(* 58 *)|Flambda_assignment_to_non_mutable_value(* 59 *)|Unused_moduleofstring(* 60 *)|Unboxable_type_in_prim_declofstring(* 61 *)|Constraint_on_gadt(* 62 *)|Erroneous_printed_signatureofstring(* 63 *)|Unsafe_array_syntax_without_parsing(* 64 *)|Redefining_unitofstring(* 65 *)|Unused_open_bangofstring(* 66 *)|Unused_functor_parameterofstring(* 67 *)|Match_on_mutable_state_prevent_uncurry(* 68 *)|Unused_fieldofstring*field_usage_warning(* 69 *)|Missing_mli(* 70 *)|Unused_tmc_attribute(* 71 *)|Tmc_breaks_tailcall(* 72 *)|Generative_application_expects_unit(* 73 *)|Degraded_to_partial_match(* 74 *)|Unnecessarily_partial_tuple_pattern(* 75 *)(* If you remove a warning, leave a hole in the numbering. NEVER change
the numbers of existing warnings.
If you add a new warning, add it at the end with a new number;
do NOT reuse one of the holes.
*)typealert={kind:string;message:string;def:loc;use:loc}letnumber=function|Comment_start->1|Comment_not_end->2|Fragile_match_->4|Ignored_partial_application->5|Labels_omitted_->6|Method_override_->7|Partial_match_->8|Missing_record_field_pattern_->9|Non_unit_statement->10|Redundant_case->11|Redundant_subpat->12|Instance_variable_override_->13|Illegal_backslash->14|Implicit_public_methods_->15|Unerasable_optional_argument->16|Undeclared_virtual_method_->17|Not_principal_->18|Non_principal_labels_->19|Ignored_extra_argument->20|Nonreturning_statement->21|Preprocessor_->22|Useless_record_with->23|Bad_module_name_->24|All_clauses_guarded->8(* used to be 25 *)|Unused_var_->26|Unused_var_strict_->27|Wildcard_arg_to_constant_constr->28|Eol_in_string->29|Duplicate_definitions_->30|Unused_value_declaration_->32|Unused_open_->33|Unused_type_declaration_->34|Unused_for_index_->35|Unused_ancestor_->36|Unused_constructor_->37|Unused_extension_->38|Unused_rec_flag->39|Name_out_of_scope_->40|Ambiguous_name_->41|Disambiguated_name_->42|Nonoptional_label_->43|Open_shadow_identifier_->44|Open_shadow_label_constructor_->45|Bad_env_variable_->46|Attribute_payload_->47|Eliminated_optional_arguments_->48|No_cmi_file_->49|Unexpected_docstring_->50|Wrong_tailcall_expectation_->51|Fragile_literal_pattern->52|Misplaced_attribute_->53|Duplicated_attribute_->54|Inlining_impossible_->55|Unreachable_case->56|Ambiguous_var_in_pattern_guard_->57|No_cmx_file_->58|Flambda_assignment_to_non_mutable_value->59|Unused_module_->60|Unboxable_type_in_prim_decl_->61|Constraint_on_gadt->62|Erroneous_printed_signature_->63|Unsafe_array_syntax_without_parsing->64|Redefining_unit_->65|Unused_open_bang_->66|Unused_functor_parameter_->67|Match_on_mutable_state_prevent_uncurry->68|Unused_field_->69|Missing_mli->70|Unused_tmc_attribute->71|Tmc_breaks_tailcall->72|Generative_application_expects_unit->73|Degraded_to_partial_match->74|Unnecessarily_partial_tuple_pattern->75;;(* DO NOT REMOVE the ;; above: it is used by
the testsuite/ests/warnings/mnemonics.mll test to determine where
the definition of the number function above ends *)letlast_warning_number=75typedescription={number:int;names:stringlist;(* The first element of the list is the current name, any following ones are
deprecated. The current name should always be derived mechanically from
the constructor name. *)description:string;since:Sys.ocaml_release_infooption;(* The compiler version introducing this warning; only tagged for warnings
created after 3.12, which introduced the numbered syntax. *)}letsincemajorminor=Some{Sys.major;minor;patchlevel=0;extra=None}letdescriptions=[{number=1;names=["comment-start"];description="Suspicious-looking start-of-comment mark.";since=None};{number=2;names=["comment-not-end"];description="Suspicious-looking end-of-comment mark.";since=None};{number=3;names=[];description="Deprecated synonym for the 'deprecated' alert.";since=None};{number=4;names=["fragile-match"];description="Fragile pattern matching: matching that will remain complete even\n\
\ if additional constructors are added to one of the variant types\n\
\ matched.";since=None};{number=5;names=["ignored-partial-application"];description="Partially applied function: expression whose result has function\n\
\ type and is ignored.";since=None};{number=6;names=["labels-omitted"];description="Label omitted in function application.";since=None};{number=7;names=["method-override"];description="Method overridden.";since=None};{number=8;names=["partial-match"];description="Partial match: missing cases in pattern-matching.";since=None};{number=9;names=["missing-record-field-pattern"];description="Missing fields in a record pattern.";since=None};{number=10;names=["non-unit-statement"];description="Expression on the left-hand side of a sequence that doesn't have type\n\
\ \"unit\" (and that is not a function, see warning number 5).";since=None};{number=11;names=["redundant-case"];description="Redundant case in a pattern matching (unused match case).";since=None};{number=12;names=["redundant-subpat"];description="Redundant sub-pattern in a pattern-matching.";since=None};{number=13;names=["instance-variable-override"];description="Instance variable overridden.";since=None};{number=14;names=["illegal-backslash"];description="Illegal backslash escape in a string constant.";since=None};{number=15;names=["implicit-public-methods"];description="Private method made public implicitly.";since=None};{number=16;names=["unerasable-optional-argument"];description="Unerasable optional argument.";since=None};{number=17;names=["undeclared-virtual-method"];description="Undeclared virtual method.";since=None};{number=18;names=["not-principal"];description="Non-principal type.";since=None};{number=19;names=["non-principal-labels"];description="Type without principality.";since=None};{number=20;names=["ignored-extra-argument"];description="Unused function argument.";since=None};{number=21;names=["nonreturning-statement"];description="Non-returning statement.";since=None};{number=22;names=["preprocessor"];description="Preprocessor warning.";since=None};{number=23;names=["useless-record-with"];description="Useless record \"with\" clause.";since=None};{number=24;names=["bad-module-name"];description="Bad module name: the source file name is not a valid OCaml module name.";since=None};{number=25;names=[];description="Ignored: now part of warning 8.";since=None};{number=26;names=["unused-var"];description="Suspicious unused variable: unused variable that is bound\n\
\ with \"let\" or \"as\", and doesn't start with an underscore (\"_\")\n\
\ character.";since=None};{number=27;names=["unused-var-strict"];description="Innocuous unused variable: unused variable that is not bound with\n\
\ \"let\" nor \"as\", and doesn't start with an underscore (\"_\")\n\
\ character.";since=None};{number=28;names=["wildcard-arg-to-constant-constr"];description="Wildcard pattern given as argument to a constant constructor.";since=None};{number=29;names=["eol-in-string"];description="Unescaped end-of-line in a string constant (non-portable code).";since=None};{number=30;names=["duplicate-definitions"];description="Two labels or constructors of the same name are defined in two\n\
\ mutually recursive types.";since=None};{number=31;names=["module-linked-twice"];description="A module is linked twice in the same executable.\n\
\ Ignored: now a hard error (since 5.1).";since=None};{number=32;names=["unused-value-declaration"];description="Unused value declaration.";since=since40};{number=33;names=["unused-open"];description="Unused open statement.";since=since40};{number=34;names=["unused-type-declaration"];description="Unused type declaration.";since=since40};{number=35;names=["unused-for-index"];description="Unused for-loop index.";since=since40};{number=36;names=["unused-ancestor"];description="Unused ancestor variable.";since=since40};{number=37;names=["unused-constructor"];description="Unused constructor.";since=since40};{number=38;names=["unused-extension"];description="Unused extension constructor.";since=since40};{number=39;names=["unused-rec-flag"];description="Unused rec flag.";since=since40};{number=40;names=["name-out-of-scope"];description="Constructor or label name used out of scope.";since=since41};{number=41;names=["ambiguous-name"];description="Ambiguous constructor or label name.";since=since41};{number=42;names=["disambiguated-name"];description="Disambiguated constructor or label name (compatibility warning).";since=since41};{number=43;names=["nonoptional-label"];description="Nonoptional label applied as optional.";since=since41};{number=44;names=["open-shadow-identifier"];description="Open statement shadows an already defined identifier.";since=since41};{number=45;names=["open-shadow-label-constructor"];description="Open statement shadows an already defined label or constructor.";since=since41};{number=46;names=["bad-env-variable"];description="Error in environment variable.";since=since41};{number=47;names=["attribute-payload"];description="Illegal attribute payload.";since=since42};{number=48;names=["eliminated-optional-arguments"];description="Implicit elimination of optional arguments.";since=since42};{number=49;names=["no-cmi-file"];description="Absent cmi file when looking up module alias.";since=since42};{number=50;names=["unexpected-docstring"];description="Unexpected documentation comment.";since=since43};{number=51;names=["wrong-tailcall-expectation"];description="Function call annotated with an incorrect @tailcall attribute.";since=since43};{number=52;names=["fragile-literal-pattern"];description="Fragile constant pattern.";since=since43};{number=53;names=["misplaced-attribute"];description="Attribute cannot appear in this context.";since=since43};{number=54;names=["duplicated-attribute"];description="Attribute used more than once on an expression.";since=since43};{number=55;names=["inlining-impossible"];description="Inlining impossible.";since=since43};{number=56;names=["unreachable-case"];description="Unreachable case in a pattern-matching (based on type information).";since=since43};{number=57;names=["ambiguous-var-in-pattern-guard"];description="Ambiguous or-pattern variables under guard.";since=since43};{number=58;names=["no-cmx-file"];description="Missing cmx file.";since=since43};{number=59;names=["flambda-assignment-to-non-mutable-value"];description="Assignment to non-mutable value.";since=since43};{number=60;names=["unused-module"];description="Unused module declaration.";since=since44};{number=61;names=["unboxable-type-in-prim-decl"];description="Unboxable type in primitive declaration.";since=since44};{number=62;names=["constraint-on-gadt"];description="Type constraint on GADT type declaration.";since=since46};{number=63;names=["erroneous-printed-signature"];description="Erroneous printed signature.";since=since48};{number=64;names=["unsafe-array-syntax-without-parsing"];description="-unsafe used with a preprocessor returning a syntax tree.";since=since48};{number=65;names=["redefining-unit"];description="Type declaration defining a new '()' constructor.";since=since48};{number=66;names=["unused-open-bang"];description="Unused open! statement.";since=since48};{number=67;names=["unused-functor-parameter"];description="Unused functor parameter.";since=since410};{number=68;names=["match-on-mutable-state-prevent-uncurry"];description="Pattern-matching depending on mutable state prevents the remaining \n\
\ arguments from being uncurried.";since=since412};{number=69;names=["unused-field"];description="Unused record field.";since=since413};{number=70;names=["missing-mli"];description="Missing interface file.";since=since413};{number=71;names=["unused-tmc-attribute"];description="Unused @tail_mod_cons attribute.";since=since414};{number=72;names=["tmc-breaks-tailcall"];description="A tail call is turned into a non-tail call \
by the @tail_mod_cons transformation.";since=since414};{number=73;names=["generative-application-expects-unit"];description="A generative functor is applied to an empty structure \
(struct end) rather than to ().";since=since51};{number=74;names=["degraded-to-partial-match"];description="A pattern-matching is compiled as partial \
even if it appears to be total.";since=since53};{number=75;names=["unnecessarily-partial-tuple-pattern"];description="A tuple pattern ends in .. but fully matches its expected \
type.";since=since54};]letname_to_number=leth=Hashtbl.createlast_warning_numberinList.iter(fun{number;names;_}->List.iter(funname->Hashtbl.addhnamenumber)names)descriptions;funs->Hashtbl.find_opths(* Must be the max number returned by the [number] function. *)letletter=function|'a'->letrecloopi=ifi=0then[]elsei::loop(i-1)inlooplast_warning_number|'b'->[]|'c'->[1;2]|'d'->[3]|'e'->[4]|'f'->[5]|'g'->[]|'h'->[]|'i'->[]|'j'->[]|'k'->[32;33;34;35;36;37;38;39]|'l'->[6]|'m'->[7]|'n'->[]|'o'->[]|'p'->[8]|'q'->[]|'r'->[9]|'s'->[10]|'t'->[]|'u'->[11;12]|'v'->[13]|'w'->[]|'x'->[14;15;16;17;18;19;20;21;22;23;24;30]|'y'->[26]|'z'->[27]|_->assertfalsetypestate={active:boolarray;error:boolarray;alerts:(Misc.Stdlib.String.Set.t*bool);(* false:set complement *)alert_errors:(Misc.Stdlib.String.Set.t*bool);(* false:set complement *)}letcurrent=ref{active=Array.make(last_warning_number+1)true;error=Array.make(last_warning_number+1)false;alerts=(Misc.Stdlib.String.Set.empty,false);alert_errors=(Misc.Stdlib.String.Set.empty,true);(* all soft *)}letdisabled=reffalseletwithout_warningsf=Misc.protect_refs[Misc.R(disabled,true)]fletbackup()=!currentletrestorex=current:=xletis_activex=not!disabled&&(!current).active.(numberx)letis_errorx=not!disabled&&(!current).error.(numberx)letalert_is_active{kind;_}=not!disabled&&let(set,pos)=(!current).alertsinMisc.Stdlib.String.Set.memkindset=posletalert_is_error{kind;_}=not!disabled&&let(set,pos)=(!current).alert_errorsinMisc.Stdlib.String.Set.memkindset=posletwith_statestatef=letprev=backup()inrestorestate;tryletr=f()inrestoreprev;rwithexn->restoreprev;raiseexnletmk_lazyf=letstate=backup()inlazy(with_statestatef)letset_alert~error~enables=letupd=matchswith|"all"->(Misc.Stdlib.String.Set.empty,notenable)|s->let(set,pos)=iferrorthen(!current).alert_errorselse(!current).alertsinletf=ifenable=posthenMisc.Stdlib.String.Set.addelseMisc.Stdlib.String.Set.removein(fsset,pos)iniferrorthencurrent:={(!current)withalert_errors=upd}elsecurrent:={(!current)withalerts=upd}letparse_alert_options=letn=String.lengthsinletid_char=function|'a'..'z'|'A'..'Z'|'_'|'\''|'0'..'9'->true|_->falseinletrecparse_idi=ifi<n&&id_chars.[i]thenparse_id(i+1)elseiinletrecscani=ifi=nthen()elseifi+1=nthenraise(Arg.Bad"Ill-formed list of alert settings")elsematchs.[i],s.[i+1]with|'+','+'->id(set_alert~error:true~enable:true)(i+2)|'+',_->id(set_alert~error:false~enable:true)(i+1)|'-','-'->id(set_alert~error:true~enable:false)(i+2)|'-',_->id(set_alert~error:false~enable:false)(i+1)|'@',_->id(funs->set_alert~error:true~enable:trues;set_alert~error:false~enable:trues)(i+1)|_->raise(Arg.Bad"Ill-formed list of alert settings")andidfi=letj=parse_idiinifj=ithenraise(Arg.Bad"Ill-formed list of alert settings");letid=String.subsi(j-i)infid;scanjinscan0typemodifier=|Set(** +a *)|Clear(** -a *)|Set_all(** @a *)typetoken=|Letterofchar*modifieroption|Numofint*int*modifierletghost_loc_in_filename=letpos={Lexing.dummy_poswithpos_fname=name}in{loc_start=pos;loc_end=pos;loc_ghost=true}letletter_alerttokens=letprint_warning_charppfc=letlowercase=Char.lowercase_asciic=cinFormat.fprintfppf"%c%c"(iflowercasethen'-'else'+')cinletprint_modifierppf=function|Set_all->Format.fprintfppf"@"|Clear->Format.fprintfppf"-"|Set->Format.fprintfppf"+"inletprint_tokenppf=function|Num(a,b,m)->ifa=bthenFormat.fprintfppf"%a%d"print_modifiermaelseFormat.fprintfppf"%a%d..%d"print_modifiermab|Letter(l,Somem)->Format.fprintfppf"%a%c"print_modifierml|Letter(l,None)->print_warning_charppflinletconsecutive_letters=(* we are tracking sequences of 2 or more consecutive unsigned letters
in warning strings, for instance in '-w "not-principa"'. *)letcommit_chunkl=function|[]|[_]->l|_::_::_aschunk->List.revchunk::linletgroup_consecutive_letters(l,current)=function|Letter(x,None)->(l,x::current)|_->(commit_chunklcurrent,[])inletl,on_going=List.fold_leftgroup_consecutive_letters([],[])tokensincommit_chunklon_goinginmatchconsecutive_letterswith|[]->None|example::_->letnowhere=ghost_loc_in_file"_none_"inletspelling_hintppf=letmax_seq_len=List.fold_left(funlx->Int.maxl(List.lengthx))0consecutive_lettersinifmax_seq_len>=5thenFormat.fprintfppf"@ @[Hint: Did you make a spelling mistake \
when using a mnemonic name?@]"else()inletmessage=Format.asprintf"@[<v>@[Setting a warning with a sequence of lowercase \
or uppercase letters,@ like '%a',@ is deprecated.@]@ \
@[Use the equivalent signed form:@ %t.@]@ \
@[Hint: Enabling or disabling a warning by its mnemonic name \
requires a + or - prefix.@]\
%t@?@]"Format.(pp_print_list~pp_sep:(fun_->ignore)pp_print_char)example(funppf->List.iter(print_tokenppf)tokens)spelling_hintinSome{kind="ocaml_deprecated_cli";use=nowhere;def=nowhere;message}letparse_warningss=leterror()=raise(Arg.Bad"Ill-formed list of warnings")inletrecget_numni=ifi>=String.lengthstheni,nelsematchs.[i]with|'0'..'9'->get_num(10*n+Char.codes.[i]-Char.code'0')(i+1)|_->i,ninletget_rangei=leti,n1=get_num0iinifi+2<String.lengths&&s.[i]='.'&&s.[i+1]='.'thenleti,n2=get_num0(i+2)inifn2<n1thenerror();i,n1,n2elsei,n1,n1inletreclooptokensi=ifi>=String.lengthsthenList.revtokenselsematchs.[i]with|'A'..'Z'|'a'..'z'->loop(Letter(s.[i],None)::tokens)(i+1)|'+'->loop_letter_numtokensSet(i+1)|'-'->loop_letter_numtokensClear(i+1)|'@'->loop_letter_numtokensSet_all(i+1)|_->error()andloop_letter_numtokensmodifieri=ifi>=String.lengthsthenerror()elsematchs.[i]with|'0'..'9'->leti,n1,n2=get_rangeiinloop(Num(n1,n2,modifier)::tokens)i|'A'..'Z'|'a'..'z'->loop(Letter(s.[i],Somemodifier)::tokens)(i+1)|_->error()inloop[]0letparse_opterroractiveerrflags=letflags=iferrflagthenerrorelseactiveinletactionmodifieri=matchmodifierwith|Set->ifi=3thenset_alert~error:errflag~enable:true"deprecated"elseflags.(i)<-true|Clear->ifi=3thenset_alert~error:errflag~enable:false"deprecated"elseflags.(i)<-false|Set_all->ifi=3thenbeginset_alert~error:false~enable:true"deprecated";set_alert~error:true~enable:true"deprecated"endelsebeginactive.(i)<-true;error.(i)<-trueendinleteval=function|Letter(c,m)->letlc=Char.lowercase_asciicinletmodifier=matchmwith|None->ifc=lcthenClearelseSet|Somem->minList.iter(actionmodifier)(letterlc)|Num(n1,n2,modifier)->forn=n1toInt.minn2last_warning_numberdoactionmodifierndoneinletparse_and_evals=lettokens=parse_warningssinList.iterevaltokens;letter_alerttokensinmatchname_to_numberswith|Somen->actionSetn;None|None->ifs=""thenparse_and_evalselsebeginletrest=String.subs1(String.lengths-1)inmatchs.[0],name_to_numberrestwith|'+',Somen->actionSetn;None|'-',Somen->actionClearn;None|'@',Somen->actionSet_alln;None|_->parse_and_evalsendletparse_optionserrflags=leterror=Array.copy(!current).errorinletactive=Array.copy(!current).activeinletalerts=parse_opterroractiveerrflagsincurrent:={(!current)witherror;active};alerts(* If you change these, don't forget to change them in man/ocamlc.m *)letdefaults_w="+a-4-7-9-27-29-30-32..42-44-45-48-50-60-66..70-74"letdefaults_warn_error="-a"letdefault_disabled_alerts=["unstable";"unsynchronized_access"]let()=ignore@@parse_optionsfalsedefaults_wlet()=ignore@@parse_optionstruedefaults_warn_errorlet()=List.iter(set_alert~error:false~enable:false)default_disabled_alertsmoduleFmt=Format_docmoduleStyle=Misc.Styleletmsg=Fmt.doc_printfletcomma_inline_list=Fmt.(pp_print_list~pp_sep:commaStyle.inline_code)letspace_inline_listppfl=letpp_sep=Fmt.pp_print_spaceinFmt.fprintfppf"@[%a@]"(Fmt.pp_print_list~pp_sepStyle.inline_code)lletexpandppfs=ifs=""then()elseFmt.fprintfppf"@ %s"sletmessage=function|Comment_start->msg"this %a is the start of a comment.@ \
%t: Did you forget spaces when writing the infix operator %a?"Style.inline_code"(*"Style.hintStyle.inline_code"( * )"|Comment_not_end->msg"this is not the end of a comment."|Fragile_match""->msg"this pattern-matching is fragile."|Fragile_matchs->msg"this pattern-matching is fragile.@ \
It will remain exhaustive when constructors are added to type %a."Style.inline_codes|Ignored_partial_application->msg"this function application is partial,@ \
maybe@ some@ arguments@ are@ missing."|Labels_omitted[]->assertfalse|Labels_omitted[l]->msg"label %a@ was omitted@ in@ the@ application@ of@ this@ function."Style.inline_codel|Labels_omittedls->msg"labels %a@ were omitted@ in@ the@ application@ of@ this@ function."comma_inline_listls|Method_override[lab]->msg"the method %a is overridden."Style.inline_codelab|Method_override(cname::slist)->msg"the following methods are overridden@ by@ the@ class@ %a:@;<1 2>%a"Style.inline_codecnamespace_inline_listslist|Method_override[]->assertfalse|Partial_matchdoc->ifdoc=Format_doc.Doc.emptythenmsg"this pattern-matching is not exhaustive."elsemsg"this pattern-matching is not exhaustive.@ \
@[Here is an example of a case that is not matched:@;<1 2>%a@]"Format_doc.pp_docdoc|Missing_record_field_patterns->msg"the following labels are not bound@ in@ this@ \
record@ pattern:@;<1 2>%a.@ \
@[Either bind these labels explicitly or add %a to the pattern.@]"Style.inline_codesStyle.inline_code"; _"|Non_unit_statement->msg"this expression should have type unit."|Redundant_case->msg"this match case is unused."|Redundant_subpat->msg"this sub-pattern is unused."|Instance_variable_override[lab]->msg"the instance variable %a is overridden."Style.inline_codelab|Instance_variable_override(cname::slist)->msg"the following instance variables@ are overridden@ \
by the class %a:@;<1 2>%a"Style.inline_codecnamespace_inline_listslist|Instance_variable_override[]->assertfalse|Illegal_backslash->msg"illegal backslash escape in string.@ \
%t: Single backslashes %a are reserved for escape sequences@ \
(%a, %a, ...).@ Did you check the list of OCaml escape sequences?@ \
To get a backslash character, escape it with a second backslash: %a."Style.hintStyle.inline_code{|\|}Style.inline_code{|\n|}Style.inline_code{|\r|}Style.inline_code{|\\|}|Implicit_public_methodsl->msg"the following private methods@ were@ made@ public@ \
implicitly:@;<1 2>%a."space_inline_listl|Unerasable_optional_argument->msg"this optional argument cannot be erased."|Undeclared_virtual_methodm->msg"the virtual method %a is not declared."Style.inline_codem|Not_principalemsg->msg"%a@ is@ not@ principal."Fmt.pp_docemsg|Non_principal_labelss->msg"%s without principality."s|Ignored_extra_argument->msg"this argument will not be used by the function."|Nonreturning_statement->msg"this statement never returns (or has an unsound type.)"|Preprocessors->msg"%s"s|Useless_record_with->msg"all the fields are explicitly listed in this record:@ \
the %a clause is useless."Style.inline_code"with"|Bad_module_name(modname)->msg"bad source file name: %a is not a valid module name."Style.inline_codemodname|All_clauses_guarded->msg"this pattern-matching is not exhaustive.@ \
All clauses in this pattern-matching are guarded."|Unused_varv|Unused_var_strictv->msg"unused variable %a."Style.inline_codev|Wildcard_arg_to_constant_constr->msg"wildcard pattern given as argument to a constant constructor"|Eol_in_string->msg"unescaped end-of-line in a string constant@ \
(non-portable behavior before OCaml 5.2)"|Duplicate_definitions(kind,cname,tc1,tc2)->msg"the %s %a is defined in both types %a and %a."kindStyle.inline_codecnameStyle.inline_codetc1Style.inline_codetc2|Unused_value_declarationv->msg"unused value %a."Style.inline_codev|Unused_opens->msg"unused open %a."Style.inline_codes|Unused_open_bangs->msg"unused open! %a."Style.inline_codes|Unused_type_declaration(s,Declaration)->msg"unused type %a."Style.inline_codes|Unused_type_declaration(s,Alias)->msg"unused type alias %a."Style.inline_codes|Unused_for_indexs->msg"unused for-loop index %a."Style.inline_codes|Unused_ancestors->msg"unused ancestor variable %a."Style.inline_codes|Unused_constructor(s,Unused)->msg"unused constructor %a."Style.inline_codes|Unused_constructor(s,Not_constructed)->msg"constructor %a is never used to build values.@ \
(However, this constructor appears in patterns.)"Style.inline_codes|Unused_constructor(s,Only_exported_private)->msg"constructor %a is never used to build values.@ \
Its type is exported as a private type."Style.inline_codes|Unused_extension(s,is_exception,complaint)->letkind=ifis_exceptionthen"exception"else"extension constructor"inbeginmatchcomplaintwith|Unused->msg"unused %s %a"kindStyle.inline_codes|Not_constructed->msg"%s %a is never used@ to@ build@ values.@ \
(However, this constructor appears in patterns.)"kindStyle.inline_codes|Only_exported_private->msg"%s %a is never used@ to@ build@ values.@ \
It is exported or rebound as a private extension."kindStyle.inline_codesend|Unused_rec_flag->msg"unused rec flag."|Name_out_of_scope(ty,[nm],false)->msg"%a was selected from type %a.@ \
@[It is not visible in the current scope,@ and@ will@ not@ \
be@ selected@ if the type becomes unknown@]."Style.inline_codenmStyle.inline_codety|Name_out_of_scope(_,_,false)->assertfalse|Name_out_of_scope(ty,slist,true)->msg"this record of type %a@ contains@ fields@ that@ are@ \
not@ visible in the current scope:@;<1 2>%a.@ \
@[They will not be selected@ if the type@ becomes@ unknown.@]"Style.inline_codetyspace_inline_listslist|Ambiguous_name([s],tl,false,expansion)->msg"%a belongs to several types:@;<1 2>%a.@ \
The first one was selected.@ \
@[Please disambiguate@ if@ this@ is wrong.%a@]"Style.inline_codesspace_inline_listtlexpandexpansion|Ambiguous_name(_,_,false,_)->assertfalse|Ambiguous_name(_slist,tl,true,expansion)->msg"these field labels belong to several types:@;<1 2>%a.@ \
@[The first one was selected.@ \
Please disambiguate@ if@ this@ is@ wrong.%a@]"space_inline_listtlexpandexpansion|Disambiguated_names->msg"this use of %a@ relies@ on@ type-directed@ disambiguation,@ \
@[it@ will@ not@ compile@ with@ OCaml@ 4.00@ or@ earlier.@]"Style.inline_codes|Nonoptional_labels->msg"the label %a is not optional."Style.inline_codes|Open_shadow_identifier(kind,s)->msg"this open statement shadows@ the@ %s identifier@ %a@ \
(which is later used)"kindStyle.inline_codes|Open_shadow_label_constructor(kind,s)->msg"this open statement shadows@ the@ %s %a@ (which is later used)"kindStyle.inline_codes|Bad_env_variable(var,s)->msg"illegal environment variable %a : %s"Style.inline_codevars|Attribute_payload(a,s)->msg"illegal payload for attribute %a.@ %s"Style.inline_codeas|Eliminated_optional_argumentssl->msg"implicit elimination@ of optional argument%s@ %a"(ifList.lengthsl=1then""else"s")comma_inline_listsl|No_cmi_file(name,None)->msg"no cmi file was found@ in path for module %a"Style.inline_codename|No_cmi_file(name,Somewmsg)->msg"no valid cmi file was found@ in path for module %a.@ %s"Style.inline_codenamewmsg|Unexpected_docstringunattached->ifunattachedthenmsg"unattached documentation comment (ignored)"elsemsg"ambiguous documentation comment"|Wrong_tailcall_expectationb->msg"expected %s"(ifbthen"tailcall"else"non-tailcall")|Fragile_literal_pattern->let[@manual.ref"ss:warn52"]ref_manual=[13;5;3]inmsg"Code should not depend@ on@ the@ actual@ values of@ \
this@ constructor's arguments.@ @[They are only for@ information@ \
and@ may@ change@ in@ future versions.@ %a@]"Misc.print_see_manualref_manual|Unreachable_case->msg"this match case is unreachable.@ \
Consider replacing it with a refutation case %a"Style.inline_code"<pat> -> ."|Misplaced_attributeattr_name->msg"the %a attribute cannot appear in this context"Style.inline_codeattr_name|Duplicated_attributeattr_name->msg"the %a attribute is used more than once@ on@ this@ \
expression"Style.inline_codeattr_name|Inlining_impossiblereason->msg"Cannot inline:@ %s"reason|Ambiguous_var_in_pattern_guardvars->let[@manual.ref"ss:warn57"]ref_manual=[13;5;4]inletvars=List.sortString.comparevarsinletvars_explanation=matchvarswith|[]->assertfalse|[x]->Fmt.dprintf"variable %a appears in@ different@ places@ in@ \
different@ or-pattern@ alternatives."Style.inline_codex|_::_->Fmt.dprintf"variables %a appears in@ different@ places@ in@ \
different@ or-pattern@ alternatives."comma_inline_listvarsinmsg"Ambiguous or-pattern variables under@ guard;@ \
%t@ \
@[Only the first match will be used to evaluate@ \
the@ guard@ expression.@ %a@]"vars_explanationMisc.print_see_manualref_manual|No_cmx_filename->msg"no cmx file was found@ in@ path@ for@ module@ %a,@ \
and@ its@ interface@ was@ not@ compiled@ with %a"Style.inline_codenameStyle.inline_code"-opaque"|Flambda_assignment_to_non_mutable_value->msg"A potential@ assignment@ to@ a@ non-mutable@ value@ was@ detected@ \
in@ this@ source@ file.@ \
Such@ assignments@ may@ generate@ incorrect@ code@ \
when@ using@ Flambda."|Unused_modules->msg"unused module %a."Style.inline_codes|Unboxable_type_in_prim_declt->msg"This primitive declaration uses type %a,@ whose@ representation@ \
may be either boxed or unboxed.@ Without@ an@ annotation@ to@ \
indicate@ which@ representation@ is@ intended,@ the@ boxed@ \
representation@ has@ been@ selected@ by@ default.@ This@ default@ \
choice@ may@ change@ in@ future@ versions@ of@ the@ compiler,@ \
breaking@ the@ primitive@ implementation.@ You@ should@ explicitly@ \
annotate@ the@ declaration@ of@ %a@ with@ %a@ or@ %a,@ so@ that@ its@ \
external@ interface@ remains@ stable@ in@ the future."Style.inline_codetStyle.inline_codetStyle.inline_code"[@@boxed]"Style.inline_code"[@@unboxed]"|Constraint_on_gadt->msg"Type constraints do not apply to@ GADT@ cases@ of@ variant types."|Erroneous_printed_signatures->msg"The printed@ interface@ differs@ from@ the@ inferred@ interface.@ \
The@ inferred@ interface@ contained@ items@ which@ could@ not@ be@ \
printed@ properly@ due@ to@ name@ collisions@ between@ identifiers.@ \
%s@ \
Beware@ that@ this@ warning@ is@ purely@ informational@ and@ will@ \
not@ catch@ all@ instances@ of@ erroneous@ printed@ interface."s|Unsafe_array_syntax_without_parsing->msg"option@ %a@ used with a preprocessor returning@ a@ syntax tree"Style.inline_code"-unsafe"|Redefining_unitname->letdefppfname=Fmt.fprintfppf"type %s = unit"nameinmsg"This type declaration is@ defining@ a new %a constructor@ \
which@ shadows@ the@ existing@ one.@ \
%t: Did you mean %a?"Style.inline_code"()"Style.hint(Style.as_inline_codedef)name|Unused_functor_parameters->msg"unused functor parameter %a."Style.inline_codes|Match_on_mutable_state_prevent_uncurry->msg"This pattern depends on@ mutable@ state.@ It prevents@ the@ \
remaining@ arguments@ from@ being@ uncurried,@ which will@ cause@ \
additional@ closure@ allocations."|Unused_field(s,Unused)->msg"unused record field %a."Style.inline_codes|Unused_field(s,Not_read)->msg"record field %a is never read.@ \
(However, this field is used to build or mutate values.)"Style.inline_codes|Unused_field(s,Not_mutated)->msg"mutable record field %a is never mutated."Style.inline_codes|Missing_mli->msg"Cannot find interface file."|Unused_tmc_attribute->msg"This function is marked %a@ \
but is never applied in TMC position."Style.inline_code"@tail_mod_cons"|Tmc_breaks_tailcall->msg"This call@ is@ in@ tail-modulo-cons@ position@ in@ a@ TMC@ \
function,@ but@ the@ function@ called@ is@ not@ itself@ \
specialized@ for@ TMC,@ so@ the@ call@ will@ not@ be@ transformed@ \
into@ a@ tail@ call.@ \
@[Please@ either@ mark@ the@ called@ function@ with@ the %a@ \
attribute,@ or@ mark@ this@ call@ with@ the@ %a@ attribute@ to@ \
make@ its@ non-tailness@ explicit.@]"Style.inline_code"[@tail_mod_cons]"Style.inline_code"[@tailcall false]"|Generative_application_expects_unit->msg"A generative functor@ \
should be applied@ to@ %a;@ using@ %a@ is deprecated."Style.inline_code"()"Style.inline_code"(struct end)"|Degraded_to_partial_match->let[@manual.ref"ss:warn74"]ref_manual=[13;5;5]inmsg"This pattern-matching@ is@ compiled@ as@ partial,@ even@ if@ it@ \
appears@ to@ be@ total.@ It@ may@ generate@ a@ %a@ exception.@ This@ \
typically@ occurs@ due@ to@ complex@ matches@ on@ mutable@ fields.@ %a"Style.inline_code"Match_failure"Misc.print_see_manualref_manual|Unnecessarily_partial_tuple_pattern->msg"This tuple pattern@ unnecessarily@ ends in %a,@ as@ it@ explicitly@ \
matches@ all@ components@ of@ its@ expected@ type."Style.inline_code"..";;letnerrors=ref0typereporting_information={id:string;message:Fmt.doc;is_error:bool;sub_locs:(loc*Fmt.doc)list;}letid_namew=letn=numberwinmatchList.find_opt(fun{number;_}->number=n)descriptionswith|Some{names=s::_;_}->Printf.sprintf"%d [%s]"ns|_->string_of_intnletreportw=matchis_activewwith|false->`Inactive|true->ifis_errorwthenincrnerrors;`Active{id=id_namew;message=messagew;is_error=is_errorw;sub_locs=[];}letreport_alert(alert:alert)=matchalert_is_activealertwith|false->`Inactive|true->letis_error=alert_is_erroralertinifis_errorthenincrnerrors;letmessage=msg"%s"(Misc.normalise_eolalert.message)in(* Reduce \r\n to \n:
- Prevents any \r characters being printed on Unix when processing
Windows sources
- Prevents \r\r\n being generated on Windows, which affects the
testsuite
*)letsub_locs=ifnotalert.def.loc_ghost&¬alert.use.loc_ghostthen[alert.def,msg"Definition";alert.use,msg"Expected signature";]else[]in`Active{id=alert.kind;message;is_error;sub_locs;}exceptionErrorsletreset_fatal()=nerrors:=0letcheck_fatal()=if!nerrors>0thenbeginnerrors:=0;raiseErrors;endletpp_sinceoutrelease_info=Printf.fprintfout" (since %d.%0*d)"release_info.Sys.major(ifrelease_info.Sys.major>=5then0else2)release_info.Sys.minorlethelp_warnings()=List.iter(fun{number;description;names;since}->letname=matchnameswith|s::_->" ["^s^"]"|[]->""inPrintf.printf"%3i%s %s%a\n"numbernamedescription(funout->Option.iter(pp_sinceout))since)descriptions;print_endline" A all warnings";fori=Char.code'b'toChar.code'z'doletc=Char.chriinmatchlettercwith|[]->()|[n]->Printf.printf" %c Alias for warning %i.\n"(Char.uppercase_asciic)n|l->Printf.printf" %c warnings %s.\n"(Char.uppercase_asciic)(String.concat", "(List.mapInt.to_stringl))done;exit0