diff --git a/changes/malformed-warning-reported-once.fix.md b/changes/malformed-warning-reported-once.fix.md new file mode 100644 index 0000000000..eef5bc9231 --- /dev/null +++ b/changes/malformed-warning-reported-once.fix.md @@ -0,0 +1,2 @@ +- Report a malformed `@warning` or `@warnerror` payload and `@@ppwarning` only once. +- Apply `@warning` and `@@warning` to warnings reported during translation, such as warning 102, also on modules, includes, type constraints, expression statements and floating `@@warning` items. diff --git a/compiler/frontend/bs_ast_invariant.ml b/compiler/frontend/bs_ast_invariant.ml index b21a4a8b9b..7ad62aae81 100644 --- a/compiler/frontend/bs_ast_invariant.ml +++ b/compiler/frontend/bs_ast_invariant.ml @@ -26,25 +26,19 @@ type iterator = Ast_iterator.iterator let super = Ast_iterator.default_iterator -let rec iter_warnings_on_stru (stru : Parsetree.structure) = +(* The floating attributes at the start of a structure or signature, which + the built-in PPX respects, in source order *) +let rec leading_attributes_of_structure (stru : Parsetree.structure) = match stru with - | [] -> () - | head :: rest -> ( - match head.pstr_desc with - | Pstr_attribute attr -> - Builtin_attributes.warning_attribute attr; - iter_warnings_on_stru rest - | _ -> ()) + | {pstr_desc = Pstr_attribute attr} :: rest -> + attr :: leading_attributes_of_structure rest + | _ -> [] -let rec iter_warnings_on_sigi (stru : Parsetree.signature) = - match stru with - | [] -> () - | head :: rest -> ( - match head.psig_desc with - | Psig_attribute attr -> - Builtin_attributes.warning_attribute attr; - iter_warnings_on_sigi rest - | _ -> ()) +let rec leading_attributes_of_signature (sigi : Parsetree.signature) = + match sigi with + | {psig_desc = Psig_attribute attr} :: rest -> + attr :: leading_attributes_of_signature rest + | _ -> [] let emit_external_warnings_on_structure (stru : Parsetree.structure) = Ast_checks.iterator.structure Ast_checks.iterator stru diff --git a/compiler/frontend/bs_ast_invariant.mli b/compiler/frontend/bs_ast_invariant.mli index 520e39ed51..ab724a784e 100644 --- a/compiler/frontend/bs_ast_invariant.mli +++ b/compiler/frontend/bs_ast_invariant.mli @@ -24,9 +24,13 @@ type iterator = Ast_iterator.iterator -val iter_warnings_on_stru : Parsetree.structure -> unit +val leading_attributes_of_structure : + Parsetree.structure -> Parsetree.attributes +(** The floating attributes at the start of a structure, in source order *) -val iter_warnings_on_sigi : Parsetree.signature -> unit +val leading_attributes_of_signature : + Parsetree.signature -> Parsetree.attributes +(** The floating attributes at the start of a signature, in source order *) (** Run [Ast_checks.iterator] over a file after its PPXes. It skips FFI externals, which the type checker checks in their resolved form. *) diff --git a/compiler/frontend/ppx_entry.ml b/compiler/frontend/ppx_entry.ml index e59a6ec5a0..f48e8ba125 100644 --- a/compiler/frontend/ppx_entry.ml +++ b/compiler/frontend/ppx_entry.ml @@ -24,8 +24,14 @@ let unsafe_mapper = Bs_builtin_ppx.mapper +(* The built-in PPX runs in the scope of the leading [@@warning] items. The + type checker applies and reports them, so here they are only applied, and + the scope ends before type checking. [replay_warning_scope] applies its + list from the end. *) let rewrite_signature (ast : Parsetree.signature) : Parsetree.signature = - Bs_ast_invariant.iter_warnings_on_sigi ast; + Builtin_attributes.replay_warning_scope + (List.rev (Bs_ast_invariant.leading_attributes_of_signature ast)) + @@ fun () -> Ast_config.process_sig ast; let ast = match !((Js_config.current ()).jsx_version) with @@ -44,7 +50,9 @@ let rewrite_signature (ast : Parsetree.signature) : Parsetree.signature = result let rewrite_implementation (ast : Parsetree.structure) : Parsetree.structure = - Bs_ast_invariant.iter_warnings_on_stru ast; + Builtin_attributes.replay_warning_scope + (List.rev (Bs_ast_invariant.leading_attributes_of_structure ast)) + @@ fun () -> Ast_config.process_str ast; let ast = match !((Js_config.current ()).jsx_version) with diff --git a/compiler/typing/builtin_attributes.ml b/compiler/typing/builtin_attributes.ml index 71239565a7..f4b2b8e8cd 100644 --- a/compiler/typing/builtin_attributes.ml +++ b/compiler/typing/builtin_attributes.ml @@ -141,35 +141,39 @@ let rec deprecated_of_str = function | Some _ as r -> r) | _ -> None -let warning_attribute ?(ppwarning = true) = +(* Applies a [@warning] or [@warnerror] attribute to the warning state. With + [report], also reports a malformed payload and a [@ppwarning]. *) +let apply_warning_attribute ~report = let process loc txt errflag payload = + let malformed msg = + if report then + Loc_report.prerr_warning loc (Warnings.Attribute_payload (txt, msg)) + in match string_of_payload payload with | Some s -> ( try Warnings.parse_options errflag s - with Arg.Bad _ -> - Loc_report.prerr_warning loc - (Warnings.Attribute_payload (txt, "Ill-formed list of warnings"))) - | None -> - Loc_report.prerr_warning loc - (Warnings.Attribute_payload (txt, "A single string literal is expected")) + with Arg.Bad _ -> malformed "Ill-formed list of warnings") + | None -> malformed "A single string literal is expected" in function | {txt = "warning" as txt; loc}, payload -> process loc txt false payload | {txt = "warnerror" as txt; loc}, payload -> process loc txt true payload - | {txt = "ppwarning"}, (PStr [{pstr_loc; _}] as payload) when ppwarning -> ( + | {txt = "ppwarning"}, (PStr [{pstr_loc; _}] as payload) when report -> ( match string_of_payload payload with | Some s -> Loc_report.prerr_warning pstr_loc (Warnings.Preprocessor s) | None -> ()) | _ -> () -let warning_scope ?ppwarning attrs f = +let warning_attribute = apply_warning_attribute ~report:true +let replay_warning_attribute = apply_warning_attribute ~report:false + +let scope apply attrs f = let prev = Warnings.backup () in try - (* Most nodes have no attributes; skipping them also saves the closure the - partial application would allocate on every call *) + (* Most nodes have no attributes *) (match attrs with | [] -> () - | _ -> List.iter (warning_attribute ?ppwarning) (List.rev attrs)); + | _ -> List.iter apply (List.rev attrs)); let ret = f () in Warnings.restore prev; ret @@ -177,6 +181,9 @@ let warning_scope ?ppwarning attrs f = Warnings.restore prev; raise exn +let warning_scope attrs f = scope warning_attribute attrs f +let replay_warning_scope attrs f = scope replay_warning_attribute attrs f + let warn_on_literal_pattern = List.exists (function | {txt = "warn_on_literal_pattern"; _}, _ -> true diff --git a/compiler/typing/builtin_attributes.mli b/compiler/typing/builtin_attributes.mli index 3288ea8d61..196e0132c6 100644 --- a/compiler/typing/builtin_attributes.mli +++ b/compiler/typing/builtin_attributes.mli @@ -57,25 +57,21 @@ val error_of_extension : Parsetree.extension -> Loc_report.error val uninterpreted_extension : loc:Location.t -> string -> Loc_report.error (** The error for an extension that nothing interpreted. *) -val warning_attribute : ?ppwarning:bool -> Parsetree.attribute -> unit -(** Apply warning settings from the specified attribute. - "warning" and "warnerror" are processed and other attributes are - ignored. +val warning_attribute : Parsetree.attribute -> unit +(** Apply the warning settings of a [@warning] or [@warnerror] attribute, and + report a malformed payload and a [@ppwarning]. Other attributes are + ignored. Only the type checker's first pass over a node uses it; other + passes over the same attributes use [replay_warning_scope]. *) - Also implement ppwarning (unless ~ppwarning:false is passed). - *) +val warning_scope : Parsetree.attributes -> (unit -> 'a) -> 'a +(** Run a function in a new scope for warning settings: the warning state is + restored when it returns. The attributes are applied with + [warning_attribute] first. The list is applied from its end. *) -val warning_scope : - ?ppwarning:bool -> Parsetree.attributes -> (unit -> 'a) -> 'a -(** Execute a function in a new scope for warning settings. This - means that the effect of any call to [warning_attribute] during - the execution of this function will be discarded after - execution. - - The function also takes a list of attributes which are processed - with [warning_attribute] in the fresh scope before the function - is executed. - *) +val replay_warning_scope : Parsetree.attributes -> (unit -> 'a) -> 'a +(** Like [warning_scope], but applies the attributes without reporting + anything: for attributes that another scope reports, such as on a later + pass over the same node. *) val warn_on_literal_pattern : Parsetree.attributes -> bool diff --git a/compiler/typing/inline_not_stored.ml b/compiler/typing/inline_not_stored.ml index c2b1d57e54..a97067b894 100644 --- a/compiler/typing/inline_not_stored.ml +++ b/compiler/typing/inline_not_stored.ml @@ -15,15 +15,12 @@ let has_inline (attributes : Parsetree.attributes) = let record_binding (attributes : Parsetree.attributes) (inner_attributes : Parsetree.attributes) ids = if has_inline attributes || has_inline inner_attributes then - (* Type checking applied these scopes already and reported what they - report, such as [@ppwarning] or a malformed [@warning]; here they are + (* Type checking reported what these attributes report; here they are only read. *) let state = - Warnings.without_warnings (fun () -> - Builtin_attributes.warning_scope ~ppwarning:false attributes - (fun () -> - Builtin_attributes.warning_scope ~ppwarning:false inner_attributes - Warnings.backup)) + Builtin_attributes.replay_warning_scope attributes (fun () -> + Builtin_attributes.replay_warning_scope inner_attributes + Warnings.backup) in List.iter (fun id -> Hashtbl.replace (Domain.DLS.get states_key) id state) diff --git a/compiler/typing/translcore.ml b/compiler/typing/translcore.ml index f4741f028f..b50eb03221 100644 --- a/compiler/typing/translcore.ml +++ b/compiler/typing/translcore.ml @@ -1229,12 +1229,11 @@ let jsx_call env (funct : expression) (p : Primitive.description) (* A primitive applied in place is not translated with [transl_exp], so check its attributes here, in the warning scope [transl_exp] would use *) let check_callee_attributes (funct : expression) = - Builtin_attributes.warning_scope ~ppwarning:false funct.exp_attributes - (fun () -> + Builtin_attributes.replay_warning_scope funct.exp_attributes (fun () -> List.iter (Translattribute.check_attribute funct) funct.exp_attributes) let rec transl_exp e = - Builtin_attributes.warning_scope ~ppwarning:false e.exp_attributes (fun () -> + Builtin_attributes.replay_warning_scope (exp_warning_attributes e) (fun () -> List.iter (Translattribute.check_attribute e) e.exp_attributes; transl_exp0 e) @@ -1730,10 +1729,9 @@ and transl_let rec_flag pat_expr_list body = | [] -> body | {vb_pat = pat; vb_expr = expr; vb_attributes = attr; vb_loc} :: rem -> let lam = - Builtin_attributes.warning_scope ~ppwarning:false attr (fun () -> - transl_exp expr) + Builtin_attributes.replay_warning_scope attr (fun () -> + Translattribute.add_inline_attribute (transl_exp expr) vb_loc attr) in - let lam = Translattribute.add_inline_attribute lam vb_loc attr in Matching.for_let pat.pat_loc lam pat (transl rem) in transl pat_expr_list @@ -1749,10 +1747,10 @@ and transl_let rec_flag pat_expr_list body = *) in let lam = - Builtin_attributes.warning_scope ~ppwarning:false vb_attributes - (fun () -> transl_exp expr) + Builtin_attributes.replay_warning_scope vb_attributes (fun () -> + Translattribute.add_inline_attribute (transl_exp expr) vb_loc + vb_attributes) in - let lam = Translattribute.add_inline_attribute lam vb_loc vb_attributes in (id, lam) in Lambda_scc.bind_rec (List.map transl_case pat_expr_list) body diff --git a/compiler/typing/translmod.ml b/compiler/typing/translmod.ml index 651ff8ec24..8c6b170f3e 100644 --- a/compiler/typing/translmod.ml +++ b/compiler/typing/translmod.ml @@ -249,8 +249,7 @@ let rec compile_functor mexp coercion root_path loc = (* Compile a module expression, in the warning scope of its attributes like [Translcore.transl_exp] *) and transl_module cc rootpath mexp = - Builtin_attributes.warning_scope ~ppwarning:false mexp.mod_attributes - (fun () -> + Builtin_attributes.replay_warning_scope mexp.mod_attributes (fun () -> List.iter (Translattribute.check_attribute_on_module mexp) mexp.mod_attributes; @@ -347,9 +346,13 @@ and transl_structure loc fields cc rootpath final_env = function | _ -> Misc.fatal_error "Translmod.transl_structure") | item :: rem -> ( match item.str_desc with - | Tstr_eval (expr, _) -> + | Tstr_eval (expr, attrs) -> let body, size = transl_structure loc fields cc rootpath final_env rem in - (Lambda.seq (Translcore.transl_exp expr) body, size) + let lam = + Builtin_attributes.replay_warning_scope attrs (fun () -> + Translcore.transl_exp expr) + in + (Lambda.seq lam body, size) | Tstr_value (rec_flag, pat_expr_list) -> let ext_fields = rev_let_bound_idents pat_expr_list @ fields in let body, size = @@ -392,11 +395,10 @@ and transl_structure loc fields cc rootpath final_env = function cc rootpath final_env rem in let module_body = - transl_module Tcoerce_none (field_path rootpath id) mb.mb_expr - in - let module_body = - Translattribute.add_inline_attribute module_body mb.mb_loc - mb.mb_attributes + Builtin_attributes.replay_warning_scope mb.mb_attributes (fun () -> + Translattribute.add_inline_attribute + (transl_module Tcoerce_none (field_path rootpath id) mb.mb_expr) + mb.mb_loc mb.mb_attributes) in (Lambda.let_ (pure_module mb.mb_expr) id module_body body, size) | Tstr_recmodule bindings -> @@ -409,7 +411,9 @@ and transl_structure loc fields cc rootpath final_env = function let lam = Transl_recmodule.compile_recmodule (fun id modl _loc -> - transl_module Tcoerce_none (field_path rootpath id) modl) + let mb = List.find (fun mb -> Ident.same mb.mb_id id) bindings in + Builtin_attributes.replay_warning_scope mb.mb_attributes (fun () -> + transl_module Tcoerce_none (field_path rootpath id) modl)) bindings body in (lam, size) @@ -431,11 +435,15 @@ and transl_structure loc fields cc rootpath final_env = function in let body, size = rebind_idents 0 fields ids in ( Lambda.let_ (pure_module modl) mid - (transl_module Tcoerce_none None modl) + (Builtin_attributes.replay_warning_scope incl.incl_attributes + (fun () -> transl_module Tcoerce_none None modl)) body, size ) - | Tstr_primitive _ | Tstr_type _ | Tstr_modtype _ | Tstr_open _ - | Tstr_attribute _ -> + | Tstr_attribute attr -> + (* A floating attribute applies to the rest of the structure *) + Builtin_attributes.replay_warning_scope [attr] (fun () -> + transl_structure loc fields cc rootpath final_env rem) + | Tstr_primitive _ | Tstr_type _ | Tstr_modtype _ | Tstr_open _ -> transl_structure loc fields cc rootpath final_env rem) (* Update forward declaration in Translcore *) diff --git a/compiler/typing/typecore.ml b/compiler/typing/typecore.ml index ecc8bb1d93..d9f7434e67 100644 --- a/compiler/typing/typecore.ml +++ b/compiler/typing/typecore.ml @@ -1983,8 +1983,7 @@ let type_pattern ~lev env spat expected_ty = the pattern's warning scope: enter it again so that [@warning] on the pattern covers its variables. *) let new_env, unpacks = - Builtin_attributes.warning_scope ~ppwarning:false spat.ppat_attributes - (fun () -> + Builtin_attributes.replay_warning_scope spat.ppat_attributes (fun () -> add_pattern_variables !new_env ~check:(fun s -> Warnings.Unused_var_strict s) ~check_as:(fun s -> Warnings.Unused_var s)) @@ -1995,7 +1994,7 @@ let type_pattern_list env spatl expected_tys allow = reset_pattern allow; let new_env = ref env in let type_pat (attrs, pat) ty = - Builtin_attributes.warning_scope ~ppwarning:false attrs (fun () -> + Builtin_attributes.replay_warning_scope attrs (fun () -> type_pat new_env pat ty) in let patl = List.map2 type_pat spatl expected_tys in @@ -5013,7 +5012,7 @@ and type_let ~context ?(check = fun s -> Warnings.Unused_var s) let warn_about_unused_bindings = List.exists (fun attrs -> - Builtin_attributes.warning_scope ~ppwarning:false attrs (fun () -> + Builtin_attributes.replay_warning_scope attrs (fun () -> Warnings.is_active (check "") || Warnings.is_active (check_strict "") || (is_recursive && Warnings.is_active Warnings.Unused_rec_flag))) @@ -5038,7 +5037,7 @@ and type_let ~context ?(check = fun s -> Warnings.Unused_var s) *) List.map2 (fun attrs pat -> - Builtin_attributes.warning_scope ~ppwarning:false attrs (fun () -> + Builtin_attributes.replay_warning_scope attrs (fun () -> if not warn_about_unused_bindings then (pat, None) else let some_used = ref false in @@ -5118,11 +5117,11 @@ and type_let ~context ?(check = fun s -> Warnings.Unused_var s) then let {pvb_pat; pvb_attributes} = List.hd spat_sexp_list in (* See PR#6677 *) - Builtin_attributes.warning_scope ~ppwarning:false pvb_attributes (fun () -> + Builtin_attributes.replay_warning_scope pvb_attributes (fun () -> Loc_report.prerr_warning pvb_pat.ppat_loc Warnings.Unused_rec_flag)); List.iter2 (fun pat (attrs, exp) -> - Builtin_attributes.warning_scope ~ppwarning:false attrs (fun () -> + Builtin_attributes.replay_warning_scope attrs (fun () -> let partial_match_warning_hint = if Experimental_features.is_enabled Experimental_features.LetUnwrap then diff --git a/compiler/typing/typedtree.ml b/compiler/typing/typedtree.ml index 99ce8e8556..1a688c604c 100644 --- a/compiler/typing/typedtree.ml +++ b/compiler/typing/typedtree.ml @@ -510,6 +510,15 @@ let rec bound_idents pat = iter_pattern_desc bound_idents pat.pat_desc | d -> iter_pattern_desc bound_idents d +let exp_warning_attributes e = + match e.exp_extra with + | [] -> e.exp_attributes + | extra -> + (* [warning_scope] applies a list from its end, so the innermost + attributes go first *) + e.exp_attributes + @ List.concat_map (fun (_, _, attrs) -> attrs) (List.rev extra) + let pat_bound_idents pat = idents () := []; bound_idents pat; diff --git a/compiler/typing/typedtree.mli b/compiler/typing/typedtree.mli index 4c45443d73..558cc3821f 100644 --- a/compiler/typing/typedtree.mli +++ b/compiler/typing/typedtree.mli @@ -594,3 +594,8 @@ val mknoloc : 'a -> 'a Asttypes.loc val mkloc : 'a -> Location.t -> 'a Asttypes.loc val pat_bound_idents : pattern -> Ident.t list + +val exp_warning_attributes : expression -> attributes +(** The attributes whose warning settings apply to an expression, in the order + [Builtin_attributes.warning_scope] takes them: its own, then those of the + type constraints around it, which [exp_extra] holds outermost first. *) diff --git a/compiler/typing/typemod.ml b/compiler/typing/typemod.ml index 92ae8cebdb..74c924c6a8 100644 --- a/compiler/typing/typemod.ml +++ b/compiler/typing/typemod.ml @@ -1474,18 +1474,9 @@ and type_structure funct_body anchor env sstr = warning state of [@inline] bindings here. *) List.iter (fun (vb : value_binding) -> - (* A type constraint keeps its attributes in [exp_extra], the - outermost first. [warning_scope] applies a list from its end, - so the innermost attributes go first. *) - let expression_attributes = - match vb.vb_expr.exp_extra with - | [] -> vb.vb_expr.exp_attributes - | extra -> - vb.vb_expr.exp_attributes - @ List.concat_map (fun (_, _, attrs) -> attrs) (List.rev extra) - in Inline_not_stored.record_binding vb.vb_attributes - expression_attributes (fun () -> pat_bound_idents vb.vb_pat)) + (exp_warning_attributes vb.vb_expr) (fun () -> + pat_bound_idents vb.vb_pat)) defs; let () = if rec_flag = Recursive then Rec_check.check_recursive_bindings defs @@ -1679,8 +1670,9 @@ and type_structure funct_body anchor env sstr = let bindings1 = List.map2 (fun {md_id = id; md_type = mty} (name, _, smodl, attrs, loc) -> + (* [transl_recmodule_modtypes] reported these attributes *) let modl = - Builtin_attributes.warning_scope attrs (fun () -> + Builtin_attributes.replay_warning_scope attrs (fun () -> type_module true funct_body (anchor_recmodule id) newenv smodl) in let mty' = diff --git a/tests/error_tests/single/expected/warning_102_attribute_scopes.res.expected b/tests/error_tests/single/expected/warning_102_attribute_scopes.res.expected new file mode 100644 index 0000000000..e4b87af034 --- /dev/null +++ b/tests/error_tests/single/expected/warning_102_attribute_scopes.res.expected @@ -0,0 +1,38 @@ + + Warning number 102 + /.../fixtures/warning_102_attribute_scopes.res:39:19-28 + + 37 │ module Inner = { + 38 │ @@warning("+102") + 39 │ let reported3 = [1] == [2] + 40 │ } + 41 │ + + Polymorphic comparison introduced (maybe unsafe) + + + Warning number 102 + /.../fixtures/warning_102_attribute_scopes.res:31:17-26 + + 29 │ let silencedInnermost = @warning("+102") ({(@warning("-102") ([1] == [2 + │ ]: bool))}: bool) + 30 │ + 31 │ let reported2 = [1] == [2] + 32 │ + 33 │ @@warning("-102") + + Polymorphic comparison introduced (maybe unsafe) + + + Warning number 102 + /.../fixtures/warning_102_attribute_scopes.res:28:55-64 + + 26 │ + 27 │ // The innermost attribute wins + 28 │ let reported1 = @warning("-102") ({(@warning("+102") ([1] == [2]: bool) + │ )}: bool) + 29 │ let silencedInnermost = @warning("+102") ({(@warning("-102") ([1] == [2 + │ ]: bool))}: bool) + 30 │ + + Polymorphic comparison introduced (maybe unsafe) \ No newline at end of file diff --git a/tests/error_tests/single/expected/warning_47_warning_payload_once.res.expected b/tests/error_tests/single/expected/warning_47_warning_payload_once.res.expected new file mode 100644 index 0000000000..5a01a26953 --- /dev/null +++ b/tests/error_tests/single/expected/warning_47_warning_payload_once.res.expected @@ -0,0 +1,86 @@ + + Warning number 47 + /.../fixtures/warning_47_warning_payload_once.res:1:1-9 + + 1 │ @@warning(3) + 2 │ @@ppwarning("reported once") + 3 │ + + illegal payload for attribute @warning. +A single string literal is expected + + + Warning number 22 + /.../fixtures/warning_47_warning_payload_once.res:2:13-27 + + 1 │ @@warning(3) + 2 │ @@ppwarning("reported once") + 3 │ + 4 │ @warning(3) let x = 1 + + reported once + + + Warning number 47 + /.../fixtures/warning_47_warning_payload_once.res:4:1-8 + + 2 │ @@ppwarning("reported once") + 3 │ + 4 │ @warning(3) let x = 1 + 5 │ @warnerror("bad!") let y = 1 + 6 │ let z = @warning(3) 1 + + illegal payload for attribute @warning. +A single string literal is expected + + + Warning number 47 + /.../fixtures/warning_47_warning_payload_once.res:5:1-10 + + 3 │ + 4 │ @warning(3) let x = 1 + 5 │ @warnerror("bad!") let y = 1 + 6 │ let z = @warning(3) 1 + 7 │ module M = @warning(3) {} + + illegal payload for attribute @warnerror. +Ill-formed list of warnings + + + Warning number 47 + /.../fixtures/warning_47_warning_payload_once.res:6:9-16 + + 4 │ @warning(3) let x = 1 + 5 │ @warnerror("bad!") let y = 1 + 6 │ let z = @warning(3) 1 + 7 │ module M = @warning(3) {} + 8 │ + + illegal payload for attribute @warning. +A single string literal is expected + + + Warning number 47 + /.../fixtures/warning_47_warning_payload_once.res:7:12-19 + + 5 │ @warnerror("bad!") let y = 1 + 6 │ let z = @warning(3) 1 + 7 │ module M = @warning(3) {} + 8 │ + 9 │ @warning(3) + + illegal payload for attribute @warning. +A single string literal is expected + + + Warning number 47 + /.../fixtures/warning_47_warning_payload_once.res:9:1-8 + + 7 │ module M = @warning(3) {} + 8 │ + 9 │ @warning(3) + 10 │ module rec R: { + 11 │ let a: int + + illegal payload for attribute @warning. +A single string literal is expected \ No newline at end of file diff --git a/tests/error_tests/single/expected/warning_47_warning_payload_order.res.expected b/tests/error_tests/single/expected/warning_47_warning_payload_order.res.expected new file mode 100644 index 0000000000..c06f97fcac --- /dev/null +++ b/tests/error_tests/single/expected/warning_47_warning_payload_order.res.expected @@ -0,0 +1,23 @@ + + Warning number 47 + /.../fixtures/warning_47_warning_payload_order.res:2:1-9 + + 1 │ // A later @@warning does not hide what an earlier one reports. + 2 │ @@warning(3) + 3 │ @@warning("-47") + 4 │ @@ppwarning("reported") + + illegal payload for attribute @warning. +A single string literal is expected + + + Warning number 22 + /.../fixtures/warning_47_warning_payload_order.res:4:13-22 + + 2 │ @@warning(3) + 3 │ @@warning("-47") + 4 │ @@ppwarning("reported") + 5 │ @@warning("-22") + 6 │ + + reported \ No newline at end of file diff --git a/tests/error_tests/single/expected/warning_53_inline_attribute_scope.res.expected b/tests/error_tests/single/expected/warning_53_inline_attribute_scope.res.expected new file mode 100644 index 0000000000..9a506ebfa5 --- /dev/null +++ b/tests/error_tests/single/expected/warning_53_inline_attribute_scope.res.expected @@ -0,0 +1,10 @@ + + Warning number 53 + /.../fixtures/warning_53_inline_attribute_scope.res:10:1-30 + + 8 │ } + 9 │ + 10 │ @inline let reported = Some(1) + 11 │ + + the @inline attribute cannot appear in this context \ No newline at end of file diff --git a/tests/error_tests/single/fixtures/warning_102_attribute_scopes.res b/tests/error_tests/single/fixtures/warning_102_attribute_scopes.res new file mode 100644 index 0000000000..cdb03d9f0c --- /dev/null +++ b/tests/error_tests/single/fixtures/warning_102_attribute_scopes.res @@ -0,0 +1,42 @@ +// Warning 102 is reported while translating, outside type checking. Each +// attribute below must still apply to it: only `reported1`, `reported2` and +// `reported3` are reported. + +@warning("-102") +module OnModule = { + let silenced = [1] == [2] +} + +@warning("-102") +module rec OnRecModule: { + let silenced: bool +} = { + let silenced = [1] == [2] +} + +@warning("-102") +include { + let silencedInclude = [1] == [2] +} + +let silencedConstraint = @warning("-102") ([1] == [2]: bool) + +@warning("-102") +ignore([1] == [2]) + +// The innermost attribute wins +let reported1 = @warning("-102") ({(@warning("+102") ([1] == [2]: bool))}: bool) +let silencedInnermost = @warning("+102") ({(@warning("-102") ([1] == [2]: bool))}: bool) + +let reported2 = [1] == [2] + +@@warning("-102") + +let silencedFloating = [1] == [2] + +module Inner = { + @@warning("+102") + let reported3 = [1] == [2] +} + +let silencedAfterInner = [1] == [2] diff --git a/tests/error_tests/single/fixtures/warning_47_warning_payload_once.res b/tests/error_tests/single/fixtures/warning_47_warning_payload_once.res new file mode 100644 index 0000000000..946d7abd5d --- /dev/null +++ b/tests/error_tests/single/fixtures/warning_47_warning_payload_once.res @@ -0,0 +1,14 @@ +@@warning(3) +@@ppwarning("reported once") + +@warning(3) let x = 1 +@warnerror("bad!") let y = 1 +let z = @warning(3) 1 +module M = @warning(3) {} + +@warning(3) +module rec R: { + let a: int +} = { + let a = 1 +} diff --git a/tests/error_tests/single/fixtures/warning_47_warning_payload_order.res b/tests/error_tests/single/fixtures/warning_47_warning_payload_order.res new file mode 100644 index 0000000000..4739471a61 --- /dev/null +++ b/tests/error_tests/single/fixtures/warning_47_warning_payload_order.res @@ -0,0 +1,7 @@ +// A later @@warning does not hide what an earlier one reports. +@@warning(3) +@@warning("-47") +@@ppwarning("reported") +@@warning("-22") + +let x = 1 diff --git a/tests/error_tests/single/fixtures/warning_53_inline_attribute_scope.res b/tests/error_tests/single/fixtures/warning_53_inline_attribute_scope.res new file mode 100644 index 0000000000..7060930af9 --- /dev/null +++ b/tests/error_tests/single/fixtures/warning_53_inline_attribute_scope.res @@ -0,0 +1,10 @@ +// @warning on a binding covers the checks of its @inline attribute. Only +// `reported` is reported. +@warning("-53") @inline let silencedLet = Some(1) + +@warning("-53") @inline +module SilencedModule = { + let x = 1 +} + +@inline let reported = Some(1)