diff --git a/compiler/core/lam_compile_primitive.ml b/compiler/core/lam_compile_primitive.ml index e7c377e97a7..47aabff81a3 100644 --- a/compiler/core/lam_compile_primitive.ml +++ b/compiler/core/lam_compile_primitive.ml @@ -389,23 +389,19 @@ let translate output_prefix loc (cxt : Lam_compile_context.t) || E.is_null_undefined_constant e2) -> E.neq_null_undefined_boolean e1 e2 | [e1; e2] -> - Location.prerr_warning loc Warnings.Bs_polymorphic_comparison; E.runtime_call Primitive_modules.object_ (Lam_compile_util.runtime_of_comp cmp) args | _ -> assert false) | Pobjorder -> ( - Location.prerr_warning loc Warnings.Bs_polymorphic_comparison; match args with | [a; b] -> E.runtime_call Primitive_modules.object_ "compare" args | _ -> assert false) | Pobjmin -> ( - Location.prerr_warning loc Warnings.Bs_polymorphic_comparison; match args with | [a; b] -> E.runtime_call Primitive_modules.object_ "min" args | _ -> assert false) | Pobjmax -> ( - Location.prerr_warning loc Warnings.Bs_polymorphic_comparison; match args with | [a; b] -> E.runtime_call Primitive_modules.object_ "max" args | _ -> assert false) diff --git a/compiler/frontend/bs_ast_invariant.ml b/compiler/frontend/bs_ast_invariant.ml index cbe5a4432ee..48ccb422a16 100644 --- a/compiler/frontend/bs_ast_invariant.ml +++ b/compiler/frontend/bs_ast_invariant.ml @@ -50,6 +50,21 @@ type iterator = Ast_iterator.iterator let super = Ast_iterator.default_iterator +let warning_attribute_iterator = + let structure_item self (structure_item : Parsetree.structure_item) = + (match structure_item.pstr_desc with + | Pstr_attribute attr -> Builtin_attributes.warning_attribute attr + | _ -> ()); + super.structure_item self structure_item + in + let signature_item self (signature_item : Parsetree.signature_item) = + (match signature_item.psig_desc with + | Psig_attribute attr -> Builtin_attributes.warning_attribute attr + | _ -> ()); + super.signature_item self signature_item + in + {super with structure_item; signature_item} + let check_constant loc (const : Parsetree.constant) = match const with | Pconst_string (_, Some s) -> @@ -148,28 +163,14 @@ let emit_external_warnings : iterator = | _ -> super.pat self pat); } -let rec iter_warnings_on_stru (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 - | _ -> ()) +let iter_warnings_on_structure (structure : Parsetree.structure) = + warning_attribute_iterator.structure warning_attribute_iterator structure -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 iter_warnings_on_signature (signature : Parsetree.signature) = + warning_attribute_iterator.signature warning_attribute_iterator signature -let emit_external_warnings_on_structure (stru : Parsetree.structure) = - emit_external_warnings.structure emit_external_warnings stru +let emit_external_warnings_on_structure (structure : Parsetree.structure) = + emit_external_warnings.structure emit_external_warnings structure -let emit_external_warnings_on_signature (sigi : Parsetree.signature) = - emit_external_warnings.signature emit_external_warnings sigi +let emit_external_warnings_on_signature (signature : Parsetree.signature) = + emit_external_warnings.signature emit_external_warnings signature diff --git a/compiler/frontend/bs_ast_invariant.mli b/compiler/frontend/bs_ast_invariant.mli index b3b580ebfa5..667d6b863d2 100644 --- a/compiler/frontend/bs_ast_invariant.mli +++ b/compiler/frontend/bs_ast_invariant.mli @@ -30,9 +30,9 @@ type iterator = Ast_iterator.iterator val warn_discarded_unused_attributes : Parsetree.attributes -> unit (** Ast invariant checking for detecting errors *) -val iter_warnings_on_stru : Parsetree.structure -> unit +val iter_warnings_on_structure : Parsetree.structure -> unit -val iter_warnings_on_sigi : Parsetree.signature -> unit +val iter_warnings_on_signature : Parsetree.signature -> unit val emit_external_warnings_on_structure : Parsetree.structure -> unit diff --git a/compiler/frontend/ppx_entry.ml b/compiler/frontend/ppx_entry.ml index e86949064f7..4afeaf2d442 100644 --- a/compiler/frontend/ppx_entry.ml +++ b/compiler/frontend/ppx_entry.ml @@ -25,7 +25,7 @@ let unsafe_mapper = Bs_builtin_ppx.mapper let rewrite_signature (ast : Parsetree.signature) : Parsetree.signature = - Bs_ast_invariant.iter_warnings_on_sigi ast; + Bs_ast_invariant.iter_warnings_on_signature ast; Ast_config.process_sig ast; let ast = match !Js_config.jsx_version with @@ -44,7 +44,7 @@ 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; + Bs_ast_invariant.iter_warnings_on_structure ast; Ast_config.process_str ast; let ast = match !Js_config.jsx_version with diff --git a/compiler/ml/builtin_attributes.ml b/compiler/ml/builtin_attributes.ml index a4d073104b4..c3e3b93411d 100644 --- a/compiler/ml/builtin_attributes.ml +++ b/compiler/ml/builtin_attributes.ml @@ -182,17 +182,20 @@ let rec deprecated_of_str = function | Some _ as r -> r) | _ -> None -let warning_attribute ?(ppwarning = true) = +let warning_attribute ?(ppwarning = true) ?(report_attribute_errors = true) = let process loc txt errflag payload = match string_of_payload payload with | Some s -> ( try Warnings.parse_options errflag s with Arg.Bad _ -> - Location.prerr_warning loc - (Warnings.Attribute_payload (txt, "Ill-formed list of warnings"))) + if report_attribute_errors then + Location.prerr_warning loc + (Warnings.Attribute_payload (txt, "Ill-formed list of warnings"))) | None -> - Location.prerr_warning loc - (Warnings.Attribute_payload (txt, "A single string literal is expected")) + if report_attribute_errors then + Location.prerr_warning loc + (Warnings.Attribute_payload + (txt, "A single string literal is expected")) in function | {txt = ("ocaml.warning" | "warning") as txt; loc}, payload -> @@ -212,10 +215,12 @@ let warning_attribute ?(ppwarning = true) = Location.prerr_warning pstr_loc (Warnings.Preprocessor s) | _ -> () -let warning_scope ?ppwarning attrs f = +let warning_scope ?ppwarning ?report_attribute_errors attrs f = let prev = Warnings.backup () in try - List.iter (warning_attribute ?ppwarning) (List.rev attrs); + List.iter + (warning_attribute ?ppwarning ?report_attribute_errors) + (List.rev attrs); let ret = f () in Warnings.restore prev; ret @@ -223,6 +228,9 @@ let warning_scope ?ppwarning attrs f = Warnings.restore prev; raise exn +let warning_scope_without_attribute_diagnostics attrs f = + warning_scope ~ppwarning:false ~report_attribute_errors:false attrs f + let warn_on_literal_pattern = List.exists (function | {txt = "ocaml.warn_on_literal_pattern" | "warn_on_literal_pattern"; _}, _ diff --git a/compiler/ml/builtin_attributes.mli b/compiler/ml/builtin_attributes.mli index 63bf7623315..aa6282749a5 100644 --- a/compiler/ml/builtin_attributes.mli +++ b/compiler/ml/builtin_attributes.mli @@ -67,17 +67,29 @@ val check_duplicated_labels : (Parsetree.label_declaration list -> string Asttypes.loc option) ref val error_of_extension : Parsetree.extension -> Location.error -val warning_attribute : ?ppwarning:bool -> Parsetree.attribute -> unit +val warning_attribute : + ?ppwarning:bool -> + ?report_attribute_errors:bool -> + Parsetree.attribute -> + unit (** Apply warning settings from the specified attribute. "ocaml.warning"/"ocaml.warnerror" (and variants without the prefix) are processed and other attributes are ignored. Also implement ocaml.ppwarning (unless ~ppwarning:false is passed). + + [report_attribute_errors] only controls whether malformed warning + attributes emit diagnostics; valid warning settings are still applied + regardless. *) val warning_scope : - ?ppwarning:bool -> Parsetree.attributes -> (unit -> 'a) -> 'a + ?ppwarning:bool -> + ?report_attribute_errors: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 @@ -88,6 +100,14 @@ val warning_scope : is executed. *) +val warning_scope_without_attribute_diagnostics : + Parsetree.attributes -> (unit -> 'a) -> 'a +(** Like [warning_scope], but suppresses diagnostics that have already been + emitted during the frontend warning-attribute pass (such as + [@@ppwarning] and malformed warning payloads). The warning settings are + still applied to the nested computation. + *) + val warn_on_literal_pattern : Parsetree.attributes -> bool val explicit_arity : Parsetree.attributes -> bool diff --git a/compiler/ml/translcore.ml b/compiler/ml/translcore.ml index 078cbf133a0..42ed7a23a9f 100644 --- a/compiler/ml/translcore.ml +++ b/compiler/ml/translcore.ml @@ -404,6 +404,37 @@ let primitives_table = let find_primitive prim_name = Hashtbl.find primitives_table prim_name +let is_null_undefined_constant (exp : Typedtree.expression) = + match exp.exp_desc with + | Texp_ident + ( _, + _, + { + val_kind = + Val_prim + {prim_name = "%null" | "%undefined" | "#null" | "#undefined"; _}; + _; + } ) -> + true + | _ -> false + +let warn_on_polymorphic_comparison loc prim_name args = function + (* Skip warning 102 for `==` / `!=` when one side is a nullish constant: + those cases lower to dedicated null/undefined checks, not object comparison. *) + | Pobjcomp (Ceq | Cneq) + when prim_name = "%equal_null" + || prim_name = "%equal_undefined" + || prim_name = "%equal_nullable" + || List.exists is_null_undefined_constant args -> + () + | Pobjcomp _ | Pobjorder | Pobjmin | Pobjmax -> + Location.prerr_warning loc Warnings.Bs_polymorphic_comparison + | _ -> () + +let emit_primitive_warnings loc prim_name args primitive = + warn_on_polymorphic_comparison loc prim_name args primitive; + primitive + let specialize_comparison ({objcomp; intcomp; floatcomp; stringcomp; bigintcomp; boolcomp} : specialized) env ty = @@ -444,8 +475,9 @@ let specialize_primitive p env ty (* ~has_constant_constructor *) = let transl_primitive loc p env ty = (* Printf.eprintf "----transl_primitive %s----\n" p.prim_name; *) let prim = - try specialize_primitive p env ty (* ~has_constant_constructor:false *) - with Not_found -> Pccall p + (try specialize_primitive p env ty (* ~has_constant_constructor:false *) + with Not_found -> Pccall p) + |> emit_primitive_warnings loc p.prim_name [] in match prim with | Ploc kind -> ( @@ -492,7 +524,7 @@ let transl_primitive_application loc prim env ty args = | [arg1] | [arg1; _] -> translate_unified_ops prim env arg1.exp_type | _ -> None in - match unified with + (match unified with | Some primitive -> primitive | None -> ( try @@ -524,7 +556,8 @@ let transl_primitive_application loc prim env ty args = with Not_found -> if String.length prim_name > 0 && prim_name.[0] = '%' then raise (Error (loc, Unknown_builtin_primitive prim_name)); - Pccall prim) + Pccall prim)) + |> emit_primitive_warnings loc prim_name args (* To propagate structured constants *) @@ -653,8 +686,10 @@ let extract_directive_for_fn exp = else None) let rec transl_exp e = - List.iter (Translattribute.check_attribute e) e.exp_attributes; - transl_exp0 e + Builtin_attributes.warning_scope_without_attribute_diagnostics + e.exp_attributes (fun () -> + List.iter (Translattribute.check_attribute e) e.exp_attributes; + transl_exp0 e) and transl_exp0 (e : Typedtree.expression) : Lambda.lambda = match e.exp_desc with diff --git a/compiler/ml/translmod.ml b/compiler/ml/translmod.ml index 87471ac26bf..dd1bc533a1c 100644 --- a/compiler/ml/translmod.ml +++ b/compiler/ml/translmod.ml @@ -446,9 +446,11 @@ and transl_structure loc fields cc rootpath final_env = function transl_module Tcoerce_none None modl, body ), size ) - | Tstr_primitive _ | Tstr_type _ | Tstr_modtype _ | Tstr_open _ - | Tstr_attribute _ -> - 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 + | Tstr_attribute x -> + Builtin_attributes.warning_scope_without_attribute_diagnostics [x] + (fun () -> transl_structure loc fields cc rootpath final_env rem)) (* Update forward declaration in Translcore *) let _ = Translcore.transl_module := transl_module diff --git a/compiler/ml/typemod.ml b/compiler/ml/typemod.ml index 0932c62f347..c88c7201637 100644 --- a/compiler/ml/typemod.ml +++ b/compiler/ml/typemod.ml @@ -870,9 +870,10 @@ and transl_signature env sg = let trem, rem, final_env = transl_sig newenv srem in (mksig (Tsig_include incl) env loc :: trem, sg @ rem, final_env) | Psig_attribute x -> - Builtin_attributes.warning_attribute x; - let trem, rem, final_env = transl_sig env srem in - (mksig (Tsig_attribute x) env loc :: trem, rem, final_env) + Builtin_attributes.warning_scope_without_attribute_diagnostics [x] + (fun () -> + let trem, rem, final_env = transl_sig env srem in + (mksig (Tsig_attribute x) env loc :: trem, rem, final_env)) | Psig_extension (ext, _attrs) -> raise (Error_forward (Builtin_attributes.error_of_extension ext))) in @@ -1590,14 +1591,24 @@ and type_structure ?(toplevel = false) funct_body anchor env sstr scope = (Tstr_include incl, sg, new_env) | Pstr_extension (ext, _attrs) -> raise (Error_forward (Builtin_attributes.error_of_extension ext)) - | Pstr_attribute x -> - Builtin_attributes.warning_attribute x; - (Tstr_attribute x, [], env) + | Pstr_attribute x -> (Tstr_attribute x, [], env) in let rec type_struct env sstr = Ctype.init_def (Ident.current_time ()); match sstr with | [] -> ([], [], env) + | {pstr_desc = Pstr_attribute x; pstr_loc; _} :: srem -> + let previous_saved_types = Cmt_format.get_saved_types () in + let str = + {str_desc = Tstr_attribute x; str_loc = pstr_loc; str_env = env} + in + Cmt_format.set_saved_types + (Cmt_format.Partial_structure_item str :: previous_saved_types); + let str_rem, sig_rem, final_env = + Builtin_attributes.warning_scope_without_attribute_diagnostics [x] + (fun () -> type_struct env srem) + in + (str :: str_rem, sig_rem, final_env) | pstr :: srem -> let previous_saved_types = Cmt_format.get_saved_types () in let desc, sg, new_env = type_str_item env srem pstr in diff --git a/tests/build_tests/super_errors/expected/malformed_warning_attribute.res.expected b/tests/build_tests/super_errors/expected/malformed_warning_attribute.res.expected new file mode 100644 index 00000000000..428a538da67 --- /dev/null +++ b/tests/build_tests/super_errors/expected/malformed_warning_attribute.res.expected @@ -0,0 +1,10 @@ + + Warning number 47 + /.../fixtures/malformed_warning_attribute.res:1:1-9 + + 1 │ @@warning(123) + 2 │ + 3 │ let x = 1 + + illegal payload for attribute 'warning'. +A single string literal is expected \ No newline at end of file diff --git a/tests/build_tests/super_errors/expected/malformed_warning_attribute.resi.expected b/tests/build_tests/super_errors/expected/malformed_warning_attribute.resi.expected new file mode 100644 index 00000000000..d64681c8120 --- /dev/null +++ b/tests/build_tests/super_errors/expected/malformed_warning_attribute.resi.expected @@ -0,0 +1,10 @@ + + Warning number 47 + /.../fixtures/malformed_warning_attribute.resi:1:1-9 + + 1 │ @@warning(123) + 2 │ + 3 │ let x: int + + illegal payload for attribute 'warning'. +A single string literal is expected \ No newline at end of file diff --git a/tests/build_tests/super_errors/expected/nested_malformed_warning_signature_attribute.resi.expected b/tests/build_tests/super_errors/expected/nested_malformed_warning_signature_attribute.resi.expected new file mode 100644 index 00000000000..721f234b4be --- /dev/null +++ b/tests/build_tests/super_errors/expected/nested_malformed_warning_signature_attribute.resi.expected @@ -0,0 +1,12 @@ + + Warning number 47 + /.../fixtures/nested_malformed_warning_signature_attribute.resi:3:3-11 + + 1 │ module M: { + 2 │ let y: int + 3 │ @@warning(123) + 4 │ } + 5 │ + + illegal payload for attribute 'warning'. +A single string literal is expected \ No newline at end of file diff --git a/tests/build_tests/super_errors/expected/nested_malformed_warning_structure_attribute.res.expected b/tests/build_tests/super_errors/expected/nested_malformed_warning_structure_attribute.res.expected new file mode 100644 index 00000000000..0d60d9eb9bd --- /dev/null +++ b/tests/build_tests/super_errors/expected/nested_malformed_warning_structure_attribute.res.expected @@ -0,0 +1,12 @@ + + Warning number 47 + /.../fixtures/nested_malformed_warning_structure_attribute.res:3:3-11 + + 1 │ module M = { + 2 │ let y = 1 + 3 │ @@warning(123) + 4 │ } + 5 │ + + illegal payload for attribute 'warning'. +A single string literal is expected \ No newline at end of file diff --git a/tests/build_tests/super_errors/expected/nested_ppwarning_signature_attribute.resi.expected b/tests/build_tests/super_errors/expected/nested_ppwarning_signature_attribute.resi.expected new file mode 100644 index 00000000000..dc8bd5968d4 --- /dev/null +++ b/tests/build_tests/super_errors/expected/nested_ppwarning_signature_attribute.resi.expected @@ -0,0 +1,11 @@ + + Warning number 22 + /.../fixtures/nested_ppwarning_signature_attribute.resi:3:15-21 + + 1 │ module M: { + 2 │ let y: int + 3 │ @@ppwarning("hello") + 4 │ } + 5 │ + + hello \ No newline at end of file diff --git a/tests/build_tests/super_errors/expected/nested_ppwarning_structure_attribute.res.expected b/tests/build_tests/super_errors/expected/nested_ppwarning_structure_attribute.res.expected new file mode 100644 index 00000000000..67a8db2b4aa --- /dev/null +++ b/tests/build_tests/super_errors/expected/nested_ppwarning_structure_attribute.res.expected @@ -0,0 +1,11 @@ + + Warning number 22 + /.../fixtures/nested_ppwarning_structure_attribute.res:3:15-21 + + 1 │ module M = { + 2 │ let y = 1 + 3 │ @@ppwarning("hello") + 4 │ } + 5 │ + + hello \ No newline at end of file diff --git a/tests/build_tests/super_errors/expected/nonleading_malformed_warning_signature_attribute.resi.expected b/tests/build_tests/super_errors/expected/nonleading_malformed_warning_signature_attribute.resi.expected new file mode 100644 index 00000000000..a9b354f6d60 --- /dev/null +++ b/tests/build_tests/super_errors/expected/nonleading_malformed_warning_signature_attribute.resi.expected @@ -0,0 +1,10 @@ + + Warning number 47 + /.../fixtures/nonleading_malformed_warning_signature_attribute.resi:2:1-9 + + 1 │ let y: int + 2 │ @@warning(123) + 3 │ + + illegal payload for attribute 'warning'. +A single string literal is expected \ No newline at end of file diff --git a/tests/build_tests/super_errors/expected/nonleading_malformed_warning_structure_attribute.res.expected b/tests/build_tests/super_errors/expected/nonleading_malformed_warning_structure_attribute.res.expected new file mode 100644 index 00000000000..78ab2f89bc1 --- /dev/null +++ b/tests/build_tests/super_errors/expected/nonleading_malformed_warning_structure_attribute.res.expected @@ -0,0 +1,10 @@ + + Warning number 47 + /.../fixtures/nonleading_malformed_warning_structure_attribute.res:2:1-9 + + 1 │ let y = 1 + 2 │ @@warning(123) + 3 │ + + illegal payload for attribute 'warning'. +A single string literal is expected \ No newline at end of file diff --git a/tests/build_tests/super_errors/expected/nonleading_ppwarning_signature_attribute.resi.expected b/tests/build_tests/super_errors/expected/nonleading_ppwarning_signature_attribute.resi.expected new file mode 100644 index 00000000000..1a29e2be231 --- /dev/null +++ b/tests/build_tests/super_errors/expected/nonleading_ppwarning_signature_attribute.resi.expected @@ -0,0 +1,9 @@ + + Warning number 22 + /.../fixtures/nonleading_ppwarning_signature_attribute.resi:2:13-19 + + 1 │ let y: int + 2 │ @@ppwarning("hello") + 3 │ + + hello \ No newline at end of file diff --git a/tests/build_tests/super_errors/expected/nonleading_ppwarning_structure_attribute.res.expected b/tests/build_tests/super_errors/expected/nonleading_ppwarning_structure_attribute.res.expected new file mode 100644 index 00000000000..0c5b2df957f --- /dev/null +++ b/tests/build_tests/super_errors/expected/nonleading_ppwarning_structure_attribute.res.expected @@ -0,0 +1,9 @@ + + Warning number 22 + /.../fixtures/nonleading_ppwarning_structure_attribute.res:2:13-19 + + 1 │ let y = 1 + 2 │ @@ppwarning("hello") + 3 │ + + hello \ No newline at end of file diff --git a/tests/build_tests/super_errors/expected/ppwarning_signature_attribute.resi.expected b/tests/build_tests/super_errors/expected/ppwarning_signature_attribute.resi.expected new file mode 100644 index 00000000000..a7a9a73084f --- /dev/null +++ b/tests/build_tests/super_errors/expected/ppwarning_signature_attribute.resi.expected @@ -0,0 +1,9 @@ + + Warning number 22 + /.../fixtures/ppwarning_signature_attribute.resi:1:13-19 + + 1 │ @@ppwarning("hello") + 2 │ + 3 │ let x: int + + hello \ No newline at end of file diff --git a/tests/build_tests/super_errors/expected/ppwarning_structure_attribute.res.expected b/tests/build_tests/super_errors/expected/ppwarning_structure_attribute.res.expected new file mode 100644 index 00000000000..3ff8ada406b --- /dev/null +++ b/tests/build_tests/super_errors/expected/ppwarning_structure_attribute.res.expected @@ -0,0 +1,9 @@ + + Warning number 22 + /.../fixtures/ppwarning_structure_attribute.res:1:13-19 + + 1 │ @@ppwarning("hello") + 2 │ + 3 │ let x = 1 + + hello \ No newline at end of file diff --git a/tests/build_tests/super_errors/expected/warning102_expr_attribute.res.expected b/tests/build_tests/super_errors/expected/warning102_expr_attribute.res.expected new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/build_tests/super_errors/expected/warning102_nullish_equality.res.expected b/tests/build_tests/super_errors/expected/warning102_nullish_equality.res.expected new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/build_tests/super_errors/expected/warning102_polymorphic_equality.res.expected b/tests/build_tests/super_errors/expected/warning102_polymorphic_equality.res.expected new file mode 100644 index 00000000000..98c7b2fb391 --- /dev/null +++ b/tests/build_tests/super_errors/expected/warning102_polymorphic_equality.res.expected @@ -0,0 +1,8 @@ + + Warning number 102 + /.../fixtures/warning102_polymorphic_equality.res:1:19-24 + + 1 │ let f = (a, b) => a == b + 2 │ + + Polymorphic comparison introduced (maybe unsafe) \ No newline at end of file diff --git a/tests/build_tests/super_errors/expected/warning102_structure_attribute.res.expected b/tests/build_tests/super_errors/expected/warning102_structure_attribute.res.expected new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/build_tests/super_errors/expected/warning102_value_attribute.res.expected b/tests/build_tests/super_errors/expected/warning102_value_attribute.res.expected new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/build_tests/super_errors/fixtures/malformed_warning_attribute.res b/tests/build_tests/super_errors/fixtures/malformed_warning_attribute.res new file mode 100644 index 00000000000..3951cf99fc1 --- /dev/null +++ b/tests/build_tests/super_errors/fixtures/malformed_warning_attribute.res @@ -0,0 +1,3 @@ +@@warning(123) + +let x = 1 diff --git a/tests/build_tests/super_errors/fixtures/malformed_warning_attribute.resi b/tests/build_tests/super_errors/fixtures/malformed_warning_attribute.resi new file mode 100644 index 00000000000..cd7eec4e6c1 --- /dev/null +++ b/tests/build_tests/super_errors/fixtures/malformed_warning_attribute.resi @@ -0,0 +1,3 @@ +@@warning(123) + +let x: int diff --git a/tests/build_tests/super_errors/fixtures/nested_malformed_warning_signature_attribute.resi b/tests/build_tests/super_errors/fixtures/nested_malformed_warning_signature_attribute.resi new file mode 100644 index 00000000000..f5eae9c9198 --- /dev/null +++ b/tests/build_tests/super_errors/fixtures/nested_malformed_warning_signature_attribute.resi @@ -0,0 +1,4 @@ +module M: { + let y: int + @@warning(123) +} diff --git a/tests/build_tests/super_errors/fixtures/nested_malformed_warning_structure_attribute.res b/tests/build_tests/super_errors/fixtures/nested_malformed_warning_structure_attribute.res new file mode 100644 index 00000000000..a6fe5be712a --- /dev/null +++ b/tests/build_tests/super_errors/fixtures/nested_malformed_warning_structure_attribute.res @@ -0,0 +1,4 @@ +module M = { + let y = 1 + @@warning(123) +} diff --git a/tests/build_tests/super_errors/fixtures/nested_ppwarning_signature_attribute.resi b/tests/build_tests/super_errors/fixtures/nested_ppwarning_signature_attribute.resi new file mode 100644 index 00000000000..b2b9041016a --- /dev/null +++ b/tests/build_tests/super_errors/fixtures/nested_ppwarning_signature_attribute.resi @@ -0,0 +1,4 @@ +module M: { + let y: int + @@ppwarning("hello") +} diff --git a/tests/build_tests/super_errors/fixtures/nested_ppwarning_structure_attribute.res b/tests/build_tests/super_errors/fixtures/nested_ppwarning_structure_attribute.res new file mode 100644 index 00000000000..fb87c43da8c --- /dev/null +++ b/tests/build_tests/super_errors/fixtures/nested_ppwarning_structure_attribute.res @@ -0,0 +1,4 @@ +module M = { + let y = 1 + @@ppwarning("hello") +} diff --git a/tests/build_tests/super_errors/fixtures/nonleading_malformed_warning_signature_attribute.resi b/tests/build_tests/super_errors/fixtures/nonleading_malformed_warning_signature_attribute.resi new file mode 100644 index 00000000000..65cc613f38a --- /dev/null +++ b/tests/build_tests/super_errors/fixtures/nonleading_malformed_warning_signature_attribute.resi @@ -0,0 +1,2 @@ +let y: int +@@warning(123) diff --git a/tests/build_tests/super_errors/fixtures/nonleading_malformed_warning_structure_attribute.res b/tests/build_tests/super_errors/fixtures/nonleading_malformed_warning_structure_attribute.res new file mode 100644 index 00000000000..fa0d1033a8e --- /dev/null +++ b/tests/build_tests/super_errors/fixtures/nonleading_malformed_warning_structure_attribute.res @@ -0,0 +1,2 @@ +let y = 1 +@@warning(123) diff --git a/tests/build_tests/super_errors/fixtures/nonleading_ppwarning_signature_attribute.resi b/tests/build_tests/super_errors/fixtures/nonleading_ppwarning_signature_attribute.resi new file mode 100644 index 00000000000..b110d72c831 --- /dev/null +++ b/tests/build_tests/super_errors/fixtures/nonleading_ppwarning_signature_attribute.resi @@ -0,0 +1,2 @@ +let y: int +@@ppwarning("hello") diff --git a/tests/build_tests/super_errors/fixtures/nonleading_ppwarning_structure_attribute.res b/tests/build_tests/super_errors/fixtures/nonleading_ppwarning_structure_attribute.res new file mode 100644 index 00000000000..35c88da5634 --- /dev/null +++ b/tests/build_tests/super_errors/fixtures/nonleading_ppwarning_structure_attribute.res @@ -0,0 +1,2 @@ +let y = 1 +@@ppwarning("hello") diff --git a/tests/build_tests/super_errors/fixtures/ppwarning_signature_attribute.resi b/tests/build_tests/super_errors/fixtures/ppwarning_signature_attribute.resi new file mode 100644 index 00000000000..95597ae052d --- /dev/null +++ b/tests/build_tests/super_errors/fixtures/ppwarning_signature_attribute.resi @@ -0,0 +1,3 @@ +@@ppwarning("hello") + +let x: int diff --git a/tests/build_tests/super_errors/fixtures/ppwarning_structure_attribute.res b/tests/build_tests/super_errors/fixtures/ppwarning_structure_attribute.res new file mode 100644 index 00000000000..7d21223a7a9 --- /dev/null +++ b/tests/build_tests/super_errors/fixtures/ppwarning_structure_attribute.res @@ -0,0 +1,3 @@ +@@ppwarning("hello") + +let x = 1 diff --git a/tests/build_tests/super_errors/fixtures/warning102_expr_attribute.res b/tests/build_tests/super_errors/fixtures/warning102_expr_attribute.res new file mode 100644 index 00000000000..9bec0b9afbd --- /dev/null +++ b/tests/build_tests/super_errors/fixtures/warning102_expr_attribute.res @@ -0,0 +1,3 @@ +let x = (a, b) => { + @warning("-102") (a->Pair.second > b->Pair.second) +} diff --git a/tests/build_tests/super_errors/fixtures/warning102_nullish_equality.res b/tests/build_tests/super_errors/fixtures/warning102_nullish_equality.res new file mode 100644 index 00000000000..c14079e0403 --- /dev/null +++ b/tests/build_tests/super_errors/fixtures/warning102_nullish_equality.res @@ -0,0 +1,8 @@ +let undefinedEq = undefined == undefined +let undefinedNeq = undefined != undefined + +let nullEq = null == null +let nullNeq = null != null + +let nullableEq = Nullable.undefined == Nullable.make(3) +let nullableNeq = Nullable.undefined != Nullable.make(3) diff --git a/tests/build_tests/super_errors/fixtures/warning102_polymorphic_equality.res b/tests/build_tests/super_errors/fixtures/warning102_polymorphic_equality.res new file mode 100644 index 00000000000..16c9337f925 --- /dev/null +++ b/tests/build_tests/super_errors/fixtures/warning102_polymorphic_equality.res @@ -0,0 +1 @@ +let f = (a, b) => a == b diff --git a/tests/build_tests/super_errors/fixtures/warning102_structure_attribute.res b/tests/build_tests/super_errors/fixtures/warning102_structure_attribute.res new file mode 100644 index 00000000000..d0ddc537322 --- /dev/null +++ b/tests/build_tests/super_errors/fixtures/warning102_structure_attribute.res @@ -0,0 +1,3 @@ +@@warning("-102") + +let x = (a, b) => a->Pair.second > b->Pair.second diff --git a/tests/build_tests/super_errors/fixtures/warning102_value_attribute.res b/tests/build_tests/super_errors/fixtures/warning102_value_attribute.res new file mode 100644 index 00000000000..1fb1a49b850 --- /dev/null +++ b/tests/build_tests/super_errors/fixtures/warning102_value_attribute.res @@ -0,0 +1 @@ +let v = @warning("-102") compare diff --git a/tests/build_tests/super_errors/input.js b/tests/build_tests/super_errors/input.js index 3ea9e08c68d..822428371ca 100644 --- a/tests/build_tests/super_errors/input.js +++ b/tests/build_tests/super_errors/input.js @@ -11,7 +11,7 @@ const { bsc } = setup(import.meta.dirname); const expectedDir = path.join(import.meta.dirname, "expected"); const fixtures = readdirSync(path.join(import.meta.dirname, "fixtures")).filter( - fileName => path.extname(fileName) === ".res", + fileName => [".res", ".resi"].includes(path.extname(fileName)), ); const prefix = ["-w", "+A", "-bs-jsx", "4"];