12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286(**************************************************************************)(* *)(* 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_privatetypet=|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_matchofstring(* 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_principalofstring(* 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(* 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 *)(* 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;;(* 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=73typedescription={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};]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:(Std.String.Set.t*bool);(* false:set complement *)alert_errors:(Std.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=(Std.String.Set.empty,false);alert_errors=(Std.String.Set.empty,true);(* all soft *)}letdisabled=reffalseletwithout_warningsf=Misc.protect_refs[Misc.R(disabled,true)]fletbackup()=!currentletrestorex=current:=x(* Some warnings are not properly implemented in merlin, just disable *)letis_disabledx=Config.merlin&&((x>=32&&x<=39)||x=60||x=69)letis_activex=not!disabled&&letx=numberxinnot(is_disabledx)&&(!current).active.(x)letis_errorx=not!disabled&&letx=numberxinnot(is_disabledx)&&(!current).error.(x)letalert_is_active{kind;_}=not!disabled&&let(set,pos)=(!current).alertsinStd.String.Set.memkindset=posletalert_is_error{kind;_}=not!disabled&&let(set,pos)=(!current).alert_errorsinStd.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"->(Std.String.Set.empty,notenable)|s->let(set,pos)=iferrorthen(!current).alert_errorselse(!current).alertsinletf=ifenable=posthenStd.String.Set.addelseStd.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"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_alertsletmessage=function|Comment_start->"this `(*' is the start of a comment.\n\
Hint: Did you forget spaces when writing the infix operator `( * )'?"|Comment_not_end->"this is not the end of a comment."|Fragile_match""->"this pattern-matching is fragile."|Fragile_matchs->"this pattern-matching is fragile.\n\
It will remain exhaustive when constructors are added to type "^s^"."|Ignored_partial_application->"this function application is partial,\n\
maybe some arguments are missing."|Labels_omitted[]->assertfalse|Labels_omitted[l]->"label "^l^" was omitted in the application of this function."|Labels_omittedls->"labels "^String.concat", "ls^" were omitted in the application of this function."|Method_override[lab]->"the method "^lab^" is overridden."|Method_override(cname::slist)->String.concat" "("the following methods are overridden by the class"::cname::":\n "::slist)|Method_override[]->assertfalse|Partial_match""->"this pattern-matching is not exhaustive."|Partial_matchs->"this pattern-matching is not exhaustive.\n\
Here is an example of a case that is not matched:\n"^s|Missing_record_field_patterns->"the following labels are not bound in this record pattern:\n"^s^"\nEither bind these labels explicitly or add '; _' to the pattern."|Non_unit_statement->"this expression should have type unit."|Redundant_case->"this match case is unused."|Redundant_subpat->"this sub-pattern is unused."|Instance_variable_override[lab]->"the instance variable "^lab^" is overridden."|Instance_variable_override(cname::slist)->String.concat" "("the following instance variables are overridden by the class"::cname::":\n "::slist)|Instance_variable_override[]->assertfalse|Illegal_backslash->"illegal backslash escape in string.\n\
Hint: Single backslashes \\ are reserved for escape sequences\n\
(\\n, \\r, ...). Did you check the list of OCaml escape sequences?\n\
To get a backslash character, escape it with a second backslash: \\\\."|Implicit_public_methodsl->"the following private methods were made public implicitly:\n "^String.concat" "l^"."|Unerasable_optional_argument->"this optional argument cannot be erased."|Undeclared_virtual_methodm->"the virtual method "^m^" is not declared."|Not_principals->s^" is not principal."|Non_principal_labelss->s^" without principality."|Ignored_extra_argument->"this argument will not be used by the function."|Nonreturning_statement->"this statement never returns (or has an unsound type.)"|Preprocessors->s|Useless_record_with->"all the fields are explicitly listed in this record:\n\
the 'with' clause is useless."|Bad_module_name(modname)->"bad source file name: \""^modname^"\" is not a valid module name."|All_clauses_guarded->"this pattern-matching is not exhaustive.\n\
All clauses in this pattern-matching are guarded."|Unused_varv|Unused_var_strictv->"unused variable "^v^"."|Wildcard_arg_to_constant_constr->"wildcard pattern given as argument to a constant constructor"|Eol_in_string->"unescaped end-of-line in a string constant (non-portable code)"|Duplicate_definitions(kind,cname,tc1,tc2)->Printf.sprintf"the %s %s is defined in both types %s and %s."kindcnametc1tc2|Unused_value_declarationv->"unused value "^v^"."|Unused_opens->"unused open "^s^"."|Unused_open_bangs->"unused open! "^s^"."|Unused_type_declarations->"unused type "^s^"."|Unused_for_indexs->"unused for-loop index "^s^"."|Unused_ancestors->"unused ancestor variable "^s^"."|Unused_constructor(s,Unused)->"unused constructor "^s^"."|Unused_constructor(s,Not_constructed)->"constructor "^s^" is never used to build values.\n\
(However, this constructor appears in patterns.)"|Unused_constructor(s,Only_exported_private)->"constructor "^s^" is never used to build values.\n\
Its type is exported as a private type."|Unused_extension(s,is_exception,complaint)->letkind=ifis_exceptionthen"exception"else"extension constructor"inletname=kind^" "^sinbeginmatchcomplaintwith|Unused->"unused "^name|Not_constructed->name^" is never used to build values.\n\
(However, this constructor appears in patterns.)"|Only_exported_private->name^" is never used to build values.\n\
It is exported or rebound as a private extension."end|Unused_rec_flag->"unused rec flag."|Name_out_of_scope(ty,[nm],false)->nm^" was selected from type "^ty^".\nIt is not visible in the current scope, and will not \n\
be selected if the type becomes unknown."|Name_out_of_scope(_,_,false)->assertfalse|Name_out_of_scope(ty,slist,true)->"this record of type "^ty^" contains fields that are \n\
not visible in the current scope: "^String.concat" "slist^".\n\
They will not be selected if the type becomes unknown."|Ambiguous_name([s],tl,false,expansion)->s^" belongs to several types: "^String.concat" "tl^"\nThe first one was selected. Please disambiguate if this is wrong."^expansion|Ambiguous_name(_,_,false,_)->assertfalse|Ambiguous_name(_slist,tl,true,expansion)->"these field labels belong to several types: "^String.concat" "tl^"\nThe first one was selected. Please disambiguate if this is wrong."^expansion|Disambiguated_names->"this use of "^s^" relies on type-directed disambiguation,\n\
it will not compile with OCaml 4.00 or earlier."|Nonoptional_labels->"the label "^s^" is not optional."|Open_shadow_identifier(kind,s)->Printf.sprintf"this open statement shadows the %s identifier %s (which is later used)"kinds|Open_shadow_label_constructor(kind,s)->Printf.sprintf"this open statement shadows the %s %s (which is later used)"kinds|Bad_env_variable(var,s)->Printf.sprintf"illegal environment variable %s : %s"vars|Attribute_payload(a,s)->Printf.sprintf"illegal payload for attribute '%s'.\n%s"as|Eliminated_optional_argumentssl->Printf.sprintf"implicit elimination of optional argument%s %s"(ifList.lengthsl=1then""else"s")(String.concat", "sl)|No_cmi_file(name,None)->"no cmi file was found in path for module "^name|No_cmi_file(name,Somemsg)->Printf.sprintf"no valid cmi file was found in path for module %s. %s"namemsg|Unexpected_docstringunattached->ifunattachedthen"unattached documentation comment (ignored)"else"ambiguous documentation comment"|Wrong_tailcall_expectationb->Printf.sprintf"expected %s"(ifbthen"tailcall"else"non-tailcall")|Fragile_literal_pattern->let[@manual.ref"ss:warn52"]ref_manual=[13;5;3]inFormat.asprintf"Code should not depend on the actual values of\n\
this constructor's arguments. They are only for information\n\
and may change in future versions. %a"Misc.print_see_manualref_manual|Unreachable_case->"this match case is unreachable.\n\
Consider replacing it with a refutation case '<pat> -> .'"|Misplaced_attributeattr_name->Printf.sprintf"the %S attribute cannot appear in this context"attr_name|Duplicated_attributeattr_name->Printf.sprintf"the %S attribute is used more than once on this \
expression"attr_name|Inlining_impossiblereason->Printf.sprintf"Cannot inline: %s"reason|Ambiguous_var_in_pattern_guardvars->let[@manual.ref"ss:warn57"]ref_manual=[13;5;4]inletvars=List.sortString.comparevarsinletvars_explanation=letin_different_places="in different places in different or-pattern alternatives"inmatchvarswith|[]->assertfalse|[x]->"variable "^x^" appears "^in_different_places|_::_->letvars=String.concat", "varsin"variables "^vars^" appear "^in_different_placesinFormat.asprintf"Ambiguous or-pattern variables under guard;\n\
%s.\n\
Only the first match will be used to evaluate the guard expression.\n\
%a"vars_explanationMisc.print_see_manualref_manual|No_cmx_filename->Printf.sprintf"no cmx file was found in path for module %s, \
and its interface was not compiled with -opaque"name|Flambda_assignment_to_non_mutable_value->"A potential assignment to a non-mutable value was detected \n\
in this source file. Such assignments may generate incorrect code \n\
when using Flambda."|Unused_modules->"unused module "^s^"."|Unboxable_type_in_prim_declt->Printf.sprintf"This primitive declaration uses type %s, whose representation\n\
may be either boxed or unboxed. Without an annotation to indicate\n\
which representation is intended, the boxed representation has been\n\
selected by default. This default choice may change in future\n\
versions of the compiler, breaking the primitive implementation.\n\
You should explicitly annotate the declaration of %s\n\
with [@@boxed] or [@@unboxed], so that its external interface\n\
remains stable in the future."tt|Constraint_on_gadt->"Type constraints do not apply to GADT cases of variant types."|Erroneous_printed_signatures->"The printed interface differs from the inferred interface.\n\
The inferred interface contained items which could not be printed\n\
properly due to name collisions between identifiers."^s^"\nBeware that this warning is purely informational and will not catch\n\
all instances of erroneous printed interface."|Unsafe_array_syntax_without_parsing->"option -unsafe used with a preprocessor returning a syntax tree"|Redefining_unitname->Printf.sprintf"This type declaration is defining a new '()' constructor\n\
which shadows the existing one.\n\
Hint: Did you mean 'type %s = unit'?"name|Unused_functor_parameters->"unused functor parameter "^s^"."|Match_on_mutable_state_prevent_uncurry->"This pattern depends on mutable state.\n\
It prevents the remaining arguments from being uncurried, which will \
cause additional closure allocations."|Unused_field(s,Unused)->"unused record field "^s^"."|Unused_field(s,Not_read)->"record field "^s^" is never read.\n\
(However, this field is used to build or mutate values.)"|Unused_field(s,Not_mutated)->"mutable record field "^s^" is never mutated."|Missing_mli->"Cannot find interface file."|Unused_tmc_attribute->"This function is marked @tail_mod_cons\n\
but is never applied in TMC position."|Tmc_breaks_tailcall->"This call\n\
is in tail-modulo-cons position in a TMC function,\n\
but the function called is not itself specialized for TMC,\n\
so the call will not be transformed into a tail call.\n\
Please either mark the called function with the [@tail_mod_cons]\n\
attribute, or mark this call with the [@tailcall false] attribute\n\
to make its non-tailness explicit."|Generative_application_expects_unit->"A generative functor\n\
should be applied to '()'; using '(struct end)' is deprecated.";;letnerrors=ref0typereporting_information={id:string;message:string;is_error:bool;sub_locs:(loc*string)list;}letid_namew=letn=numberwin(* (* Merlin: let's keep our messages compact. *)
match List.find_opt (fun {number; _} -> number = n) descriptions with
| Some {names = s :: _; _} ->
Printf.sprintf "%d [%s]" n s
| _ ->
string_of_int n
*)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=Misc.normalise_eolalert.messagein(* 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,"Definition";alert.use,"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(* merlin *)letdump?(verbose=false)()=letopenStdinletactivesarr=letacc=ref[]infori=1tolast_warning_numberdoifarr.(i)then(letx=tryifverbosethenlet{description;_}=List.find~f:(fun{number;_}->number=i)descriptionsin`String(string_of_inti^": "^description)else`IntiwithNot_found->`Intiinacc:=x::!acc)done;List.rev!accinletalerts(set,enabled)=`Assoc["alerts",Json.listJson.string(String.Set.elementsset);"complement",Json.bool(notenabled)]in`Assoc["actives",`List(actives!current.active);"warn_error",`List(actives!current.error);"alerts",alerts!current.alerts;"alerts_error",alerts!current.alert_errors;]