@@ -439,6 +439,19 @@ let specialize_primitive p env ty (* ~has_constant_constructor *) =
439439 | None -> table.objcomp
440440 with Not_found -> find_primitive p.prim_name)
441441
442+ let is_null_undefined_constant = function
443+ | Lprim ((Pnull | Pundefined ), [] , _ ) -> true
444+ | _ -> false
445+
446+ let warn_polymorphic_comparison loc prim args =
447+ match (prim, args) with
448+ | Pobjcomp (Ceq | Cneq ), [arg1; arg2]
449+ when is_null_undefined_constant arg1 || is_null_undefined_constant arg2 ->
450+ ()
451+ | (Pobjcomp _ | Pobjorder | Pobjmin | Pobjmax ), _ ->
452+ Location. prerr_warning loc Warnings. Bs_polymorphic_comparison
453+ | _ -> ()
454+
442455(* Eta-expand a primitive *)
443456
444457let transl_primitive loc p env ty =
@@ -447,6 +460,7 @@ let transl_primitive loc p env ty =
447460 try specialize_primitive p env ty (* ~has_constant_constructor:false *)
448461 with Not_found -> Pccall p
449462 in
463+ warn_polymorphic_comparison loc prim [] ;
450464 match prim with
451465 | Ploc kind -> (
452466 let lam = lam_of_loc kind loc in
@@ -653,8 +667,9 @@ let extract_directive_for_fn exp =
653667 else None )
654668
655669let rec transl_exp e =
656- List. iter (Translattribute. check_attribute e) e.exp_attributes;
657- transl_exp0 e
670+ Builtin_attributes. warning_scope ~ppwarning: false e.exp_attributes (fun () ->
671+ List. iter (Translattribute. check_attribute e) e.exp_attributes;
672+ transl_exp0 e)
658673
659674and transl_exp0 (e : Typedtree.expression ) : Lambda.lambda =
660675 match e.exp_desc with
@@ -734,6 +749,7 @@ and transl_exp0 (e : Typedtree.expression) : Lambda.lambda =
734749 let prim =
735750 transl_primitive_application e.exp_loc p e.exp_env prim_type args
736751 in
752+ warn_polymorphic_comparison e.exp_loc prim argl;
737753 match (prim, args) with
738754 | Praise k , [_] ->
739755 let targ = List. hd argl in
@@ -1082,7 +1098,10 @@ and transl_let rec_flag pat_expr_list body =
10821098 let rec transl = function
10831099 | [] -> body
10841100 | {vb_pat = pat ; vb_expr = expr ; vb_attributes = attr ; vb_loc} :: rem ->
1085- let lam = transl_exp expr in
1101+ let lam =
1102+ Builtin_attributes. warning_scope ~ppwarning: false attr (fun () ->
1103+ transl_exp expr)
1104+ in
10861105 let lam = Translattribute. add_inline_attribute lam vb_loc attr in
10871106 Matching. for_let pat.pat_loc lam pat (transl rem)
10881107 in
@@ -1098,7 +1117,10 @@ and transl_let rec_flag pat_expr_list body =
10981117 Only variables are allowed as left-hand side of `let rec'
10991118 *)
11001119 in
1101- let lam = transl_exp expr in
1120+ let lam =
1121+ Builtin_attributes. warning_scope ~ppwarning: false vb_attributes
1122+ (fun () -> transl_exp expr)
1123+ in
11021124 let lam = Translattribute. add_inline_attribute lam vb_loc vb_attributes in
11031125 (id, lam)
11041126 in
0 commit comments