···676676 (x3 : int as 'used1) (x4 : 'used1) (x5 : 'used2) = (x1, x2, x3, x4, x5)
677677678678[%%expect{|
679679-Line 1, characters 12-27:
679679+Line 1, characters 19-27:
6806801 | let f (x1 : int as 'unused1) (x2 : int as 'unused2)
681681- ^^^^^^^^^^^^^^^
681681+ ^^^^^^^^
682682Warning 34 [unused-type-declaration]: unused type "'unused1".
683683684684-Line 1, characters 35-50:
684684+Line 1, characters 42-50:
6856851 | let f (x1 : int as 'unused1) (x2 : int as 'unused2)
686686- ^^^^^^^^^^^^^^^
686686+ ^^^^^^^^
687687Warning 34 [unused-type-declaration]: unused type "'unused2".
688688689689val f : int -> int -> int -> int -> 'used2 -> int * int * int * int * 'used2 =
+22-17
typing/typetexp.ml
···57575858 val is_in_scope : string -> bool
59596060- val add : check:bool -> Location.t -> string -> type_expr -> unit
6060+ val add : ?unused:bool ref -> string -> type_expr -> unit
6161 (* add a global type variable to the environment *)
62626363 val with_local_scope : (unit -> 'a) -> 'a
···104104 row_context:type_expr option ref list -> string -> type_expr
105105 (* look up a local type variable; throws Not_found if it isn't in scope *)
106106107107- val remember_used : check:bool -> string -> type_expr -> Location.t -> unit
107107+ val remember_used :
108108+ ?check:Location.t -> string -> type_expr -> Location.t -> unit
108109 (* remember that a given name is bound to a given type *)
109110110111 val globalize_used_variables : policy -> Env.t -> unit -> unit
···165166 let is_in_scope name =
166167 TyVarMap.mem name !type_variables
167168168168- let add ~check loc name v =
169169+ let add ?(unused = ref false) name v =
169170 assert (not_generic v);
170170- let unused = ref check in
171171- if check then
172172- !Env.add_delayed_check_forward begin fun () ->
173173- let warn = Warnings.Unused_type_declaration ("'" ^ name) in
174174- if !unused && Warnings.is_active warn
175175- then Location.prerr_warning loc warn
176176- end;
177171 type_variables := TyVarMap.add name (v, unused) !type_variables
178172179173 let narrow () =
···283277 inserted into [used_variables] are non-generic, but some
284278 might get generalized. *)
285279286286- let remember_used ~check name v loc =
280280+ let remember_used ?check name v loc =
287281 assert (not_generic v);
288288- used_variables := TyVarMap.add name (v, loc, ref check) !used_variables
282282+ let unused = match check with
283283+ | None -> ref false
284284+ | Some check_loc ->
285285+ let unused = ref true in
286286+ !Env.add_delayed_check_forward begin fun () ->
287287+ let warn = Warnings.Unused_type_declaration ("'" ^ name) in
288288+ if !unused && Warnings.is_active warn
289289+ then Location.prerr_warning check_loc warn
290290+ end;
291291+ unused
292292+ in
293293+ used_variables := TyVarMap.add name (v, loc, unused) !used_variables
289294290295291296 type flavor = Unification | Universal
···320325 let globalize_used_variables { flavor; extensibility } env =
321326 let r = ref [] in
322327 TyVarMap.iter
323323- (fun name (ty, loc, c) ->
328328+ (fun name (ty, loc, unused) ->
324329 if flavor = Unification || is_in_scope name then
325330 let v = new_global_var () in
326331 let snap = Btype.snapshot () in
···338343 get_in_scope_names ())));
339344 let v2 = new_global_var () in
340345 r := (loc, v, v2) :: !r;
341341- add ~check:!c loc name v2)
346346+ add ~unused name v2)
342347 !used_variables;
343348 used_variables := TyVarMap.empty;
344349 fun () ->
···397402 if TyVarEnv.is_in_scope name then
398403 raise Already_bound;
399404 let v = new_global_var ~name () in
400400- TyVarEnv.add ~check:false loc name v;
405405+ TyVarEnv.add name v;
401406 v
402407 in
403408 { ctyp_desc = Ttyp_var name; ctyp_type = ty; ctyp_env = env;
···439444 TyVarEnv.lookup_local ~row_context:row_context name
440445 with Not_found ->
441446 let v = TyVarEnv.new_var ~name policy in
442442- TyVarEnv.remember_used ~check:false name v styp.ptyp_loc;
447447+ TyVarEnv.remember_used name v styp.ptyp_loc;
443448 v
444449 end
445450 in
···544549 with_local_level_generalize_structure_if_principal begin fun () ->
545550 let t = newvar () in
546551 (* Use the whole location, which is used by [Type_mismatch]. *)
547547- TyVarEnv.remember_used ~check:true alias.txt t styp.ptyp_loc;
552552+ TyVarEnv.remember_used ~check:alias.loc alias.txt t styp.ptyp_loc;
548553 let ty = transl_type env ~policy ~row_context st in
549554 begin try unify_var env t ty.ctyp_type with Unify err ->
550555 let err = Errortrace.swap_unification_error err in