Skip to content

Commit bd23e6f

Browse files
committed
message about automatic migrations
1 parent b71abc1 commit bd23e6f

File tree

8 files changed

+34
-9
lines changed

8 files changed

+34
-9
lines changed

compiler/bsb/bsb_package_specs.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ let supported_format (x : string) loc : Ext_module_system.t =
5050
{loc with Lexing.pos_cnum = loc.Lexing.pos_cnum + String.length x}
5151
in
5252
let loc = {Warnings.loc_start = loc; loc_end; loc_ghost = false} in
53-
Location.deprecated loc
53+
Location.deprecated ~can_be_automigrated:false loc
5454
(Printf.sprintf "Option \"%s\" is deprecated. Use \"%s\" instead." x
5555
Literals.esmodule)
5656
in

compiler/ext/warnings.ml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type top_level_unit_help = FunctionCall | Other
3131
type t =
3232
| Comment_start (* 1 *)
3333
| Comment_not_end (* 2 *)
34-
| Deprecated of string * loc * loc (* 3 *)
34+
| Deprecated of string * loc * loc * bool (* 3 *)
3535
| Fragile_match of string (* 4 *)
3636
| Partial_application (* 5 *)
3737
| Method_override of string list (* 7 *)
@@ -299,14 +299,21 @@ let () = reset ()
299299
let message = function
300300
| Comment_start -> "this is the start of a comment."
301301
| Comment_not_end -> "this is not the end of a comment."
302-
| Deprecated (s, _, _) ->
302+
| Deprecated (s, _, _, can_be_automigrated) ->
303303
(* Reduce \r\n to \n:
304304
- Prevents any \r characters being printed on Unix when processing
305305
Windows sources
306306
- Prevents \r\r\n being generated on Windows, which affects the
307307
testsuite
308308
*)
309309
"deprecated: " ^ Misc.normalise_eol s
310+
^
311+
if can_be_automigrated then
312+
"\n\n\
313+
\ This can be automatically migrated by the ReScript migration tool. \
314+
Run `rescript-tools migrate-all` to run all automatic migrations \
315+
available in your project."
316+
else ""
310317
| Fragile_match "" -> "this pattern-matching is fragile."
311318
| Fragile_match s ->
312319
"this pattern-matching is fragile.\n\
@@ -533,7 +540,7 @@ let message = function
533540
you implement this before running the code."
534541

535542
let sub_locs = function
536-
| Deprecated (_, def, use) ->
543+
| Deprecated (_, def, use, _) ->
537544
[(def, "Definition"); (use, "Expected signature")]
538545
| _ -> []
539546

compiler/ext/warnings.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type top_level_unit_help = FunctionCall | Other
2424
type t =
2525
| Comment_start (* 1 *)
2626
| Comment_not_end (* 2 *)
27-
| Deprecated of string * loc * loc (* 3 *)
27+
| Deprecated of string * loc * loc * bool (* 3 *)
2828
| Fragile_match of string (* 4 *)
2929
| Partial_application (* 5 *)
3030
| Method_override of string list (* 7 *)

compiler/ml/builtin_attributes.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,11 @@ let check_deprecated ?deprecated_context loc attrs s =
132132
!Cmt_utils.record_deprecated_used
133133
?deprecated_context ?migration_template ?migration_in_pipe_chain_template
134134
loc txt;
135-
Location.deprecated loc (cat s txt)
135+
Location.deprecated
136+
~can_be_automigrated:
137+
(Option.is_some migration_template
138+
|| Option.is_some migration_in_pipe_chain_template)
139+
loc (cat s txt)
136140

137141
let check_deprecated_inclusion ~def ~use loc attrs1 attrs2 s =
138142
match (deprecated_of_attrs attrs1, deprecated_of_attrs attrs2) with

compiler/ml/location.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,8 @@ let raise_errorf ?(loc = none) ?(sub = []) ?(if_highlight = "") =
298298
pp_ksprintf ~before:print_phanton_error_prefix (fun msg ->
299299
raise (Error {loc; msg; sub; if_highlight}))
300300

301-
let deprecated ?(def = none) ?(use = none) loc msg =
302-
prerr_warning loc (Warnings.Deprecated (msg, def, use))
301+
let deprecated ?(can_be_automigrated = false) ?(def = none) ?(use = none) loc
302+
msg =
303+
prerr_warning loc (Warnings.Deprecated (msg, def, use, can_be_automigrated))
303304

304305
let map_loc f {txt; loc} = {txt = f txt; loc}

compiler/ml/location.mli

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ val default_error_reporter :
130130
val report_exception : formatter -> exn -> unit
131131
(** Reraise the exception if it is unknown. *)
132132

133-
val deprecated : ?def:t -> ?use:t -> t -> string -> unit
133+
val deprecated :
134+
?can_be_automigrated:bool -> ?def:t -> ?use:t -> t -> string -> unit
134135

135136
val map_loc : ('a -> 'b) -> 'a loc -> 'b loc
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
Warning number 3
3+
/.../fixtures/deprecated_with_automigration.res:1:9-21
4+
5+
1 │ let _ = Js.Array2.map([1, 2], v => v + 1)
6+
2 │
7+
8+
deprecated: Js.Array2.map
9+
Use `Array.map` instead.
10+
11+
This can be automatically migrated by the ReScript migration tool. Run `rescript-tools migrate-all` to run all automatic migrations available in your project.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
let _ = Js.Array2.map([1, 2], v => v + 1)

0 commit comments

Comments
 (0)