Skip to content

Commit c8e2639

Browse files
authored
Replace "raise" in tests with "throw"; treat "throw" like "raise" in analysis (#7521)
* Replace "raise" in tests with "throw" * Treat "throw" like "raise" in analysis * Remove raise_notrace * Update syntax roundtrip tests * CHANGELOG
1 parent 7d3a0d0 commit c8e2639

File tree

108 files changed

+249
-249
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+249
-249
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#### :bug: Bug fix
2323

2424
- `rescript-tools doc` no longer includes shadowed bindings in its output. https://github.com/rescript-lang/rescript/pull/7497
25+
- Treat `throw` like `raise` in analysis. https://github.com/rescript-lang/rescript/pull/7521
2526

2627
#### :nail_care: Polish
2728

analysis/examples/larger-project/src/arg_helper.res

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,27 +76,27 @@ module Make = (
7676
| exception Not_found =>
7777
switch S.Value.of_string(value) {
7878
| value => set_user_default(value, acc)
79-
| exception exn => raise(Parse_failure(exn))
79+
| exception exn => throw(Parse_failure(exn))
8080
}
8181
| equals =>
8282
let key_value_pair = value
8383
let length = String.length(key_value_pair)
8484
assert (equals >= 0 && equals < length)
8585
if equals == 0 {
86-
raise(Parse_failure(Failure("Missing key in argument specification")))
86+
throw(Parse_failure(Failure("Missing key in argument specification")))
8787
}
8888
let key = {
8989
let key = String.sub(key_value_pair, 0, equals)
9090
try S.Key.of_string(key) catch {
91-
| exn => raise(Parse_failure(exn))
91+
| exn => throw(Parse_failure(exn))
9292
}
9393
}
9494

9595
let value = {
9696
let value = String.sub(key_value_pair, equals + 1, length - equals - 1)
9797

9898
try S.Value.of_string(value) catch {
99-
| exn => raise(Parse_failure(exn))
99+
| exn => throw(Parse_failure(exn))
100100
}
101101
}
102102

analysis/examples/larger-project/src/ast_helper.res

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ let with_default_loc = (l, f) => {
4747
} catch {
4848
| exn =>
4949
default_loc := old
50-
raise(exn)
50+
throw(exn)
5151
}
5252
}
5353

@@ -94,7 +94,7 @@ module Typ = {
9494
@raises(Error)
9595
let check_variable = (vl, loc, v) =>
9696
if List.mem(v, vl) {
97-
raise({
97+
throw({
9898
open Syntaxerr
9999
Error(Variable_in_scope(loc, v))
100100
})
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
@raise(DecodeError)
1+
@throw(DecodeError)
22
let testBsJson = x => Json_decode.string(x)
33

4-
@raise(DecodeError)
4+
@throw(DecodeError)
55
let testBsJson2 = x => Json.Decode.string(x)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
@raises(Not_found)
2-
let foo = () => raise(Not_found)
2+
let foo = () => throw(Not_found)

analysis/examples/larger-project/src/exception/Yojson.res

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ module Basic = {
44
type t
55

66
@raises(Json_error)
7-
let from_string: string => t = _ => raise(Json_error("Basic.from_string"))
7+
let from_string: string => t = _ => throw(Json_error("Basic.from_string"))
88

99
module Util = {
1010
exception Type_error(string, t)
1111

1212
@raises(Type_error)
13-
let member: (string, t) => t = (_s, j) => raise(Type_error("Basic.Util.member", j))
13+
let member: (string, t) => t = (_s, j) => throw(Type_error("Basic.Util.member", j))
1414

1515
let to_int: t => int = _ => 34
1616

analysis/examples/larger-project/src/location.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,5 +257,5 @@ let () = register_error_of_exn(x =>
257257
@raises(Error)
258258
let raise_errorf = (~loc=none, ~sub=list{}, ~if_highlight="") =>
259259
pp_ksprintf(~before=print_phanton_error_prefix, msg =>
260-
raise(Error({loc: loc, msg: msg, sub: sub, if_highlight: if_highlight}))
260+
throw(Error({loc: loc, msg: msg, sub: sub, if_highlight: if_highlight}))
261261
)

analysis/examples/larger-project/src/misc.res

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ exception Fatal_error
2323
let fatal_error = msg => {
2424
print_string(">> Fatal error: ")
2525
prerr_endline(msg)
26-
raise(Fatal_error)
26+
throw(Fatal_error)
2727
}
2828

2929
@raises(Fatal_error)
@@ -36,7 +36,7 @@ let try_finally = (work, cleanup) => {
3636
let result = try work() catch {
3737
| e =>
3838
cleanup()
39-
raise(e)
39+
throw(e)
4040
}
4141
cleanup()
4242
result
@@ -56,7 +56,7 @@ let protect_refs = {
5656
x
5757
| exception e =>
5858
set_refs(backup)
59-
raise(e)
59+
throw(e)
6060
}
6161
}
6262
}
@@ -149,7 +149,7 @@ module Stdlib = {
149149
let rec aux = (acc, l1, l2) =>
150150
switch (l1, l2) {
151151
| (list{}, _) => (List.rev(acc), l2)
152-
| (list{_, ..._}, list{}) => raise(Invalid_argument("map2_prefix"))
152+
| (list{_, ..._}, list{}) => throw(Invalid_argument("map2_prefix"))
153153
| (list{h1, ...t1}, list{h2, ...t2}) =>
154154
let h = f(h1, h2)
155155
aux(list{h, ...acc}, t1, t2)
@@ -179,7 +179,7 @@ module Stdlib = {
179179
(List.rev(acc), l)
180180
} else {
181181
switch l {
182-
| list{} => raise(Invalid_argument("split_at"))
182+
| list{} => throw(Invalid_argument("split_at"))
183183
| list{t, ...q} => aux(n - 1, list{t, ...acc}, q)
184184
}
185185
}
@@ -254,13 +254,13 @@ let find_in_path = (path, name) =>
254254
if Sys.file_exists(name) {
255255
name
256256
} else {
257-
raise(Not_found)
257+
throw(Not_found)
258258
}
259259
} else {
260260
@raises(Not_found)
261261
let rec try_dir = x =>
262262
switch x {
263-
| list{} => raise(Not_found)
263+
| list{} => throw(Not_found)
264264
| list{dir, ...rem} =>
265265
let fullname = Filename.concat(dir, name)
266266
if Sys.file_exists(fullname) {
@@ -290,7 +290,7 @@ let find_in_path_rel = (path, name) => {
290290
@raises(Not_found)
291291
let rec try_dir = x =>
292292
switch x {
293-
| list{} => raise(Not_found)
293+
| list{} => throw(Not_found)
294294
| list{dir, ...rem} =>
295295
let fullname = simplify(Filename.concat(dir, name))
296296
if Sys.file_exists(fullname) {
@@ -309,7 +309,7 @@ let find_in_path_uncap = (path, name) => {
309309
@raises(Not_found)
310310
let rec try_dir = x =>
311311
switch x {
312-
| list{} => raise(Not_found)
312+
| list{} => throw(Not_found)
313313
| list{dir, ...rem} =>
314314
let fullname = Filename.concat(dir, name)
315315
and ufullname = Filename.concat(dir, uname)
@@ -381,7 +381,7 @@ let copy_file_chunk = (ic, oc, len) => {
381381
} else {
382382
let r = input(ic, buff, 0, min(n, 0x1000))
383383
if r == 0 {
384-
raise(End_of_file)
384+
throw(End_of_file)
385385
} else {
386386
output(oc, buff, 0, r)
387387
copy(n - r)
@@ -435,12 +435,12 @@ let output_to_file_via_temporary = (~mode=list{Open_text}, filename, fn) => {
435435
} catch {
436436
| exn =>
437437
remove_file(temp_filename)
438-
raise(exn)
438+
throw(exn)
439439
}
440440
| exception exn =>
441441
close_out(oc)
442442
remove_file(temp_filename)
443-
raise(exn)
443+
throw(exn)
444444
}
445445
}
446446

@@ -514,7 +514,7 @@ let search_substring = (pat, str, start) => {
514514
if j >= String.length(pat) {
515515
i
516516
} else if i + j >= String.length(str) {
517-
raise(Not_found)
517+
throw(Not_found)
518518
} else if String.get(str, i + j) == String.get(pat, j) {
519519
search(i, j + 1)
520520
} else {
@@ -831,7 +831,7 @@ module Color = {
831831
| "error" => cur_styles.contents.error
832832
| "warning" => cur_styles.contents.warning
833833
| "loc" => cur_styles.contents.loc
834-
| _ => raise(Not_found)
834+
| _ => throw(Not_found)
835835
}
836836

837837
let color_enabled = ref(true)
@@ -957,15 +957,15 @@ exception HookExnWrapper({error: exn, hook_name: string, hook_info: hook_info})
957957
exception HookExn(exn)
958958

959959
@raises(HookExn)
960-
let raise_direct_hook_exn = e => raise(HookExn(e))
960+
let raise_direct_hook_exn = e => throw(HookExn(e))
961961

962962
@raises([HookExnWrapper, genericException])
963963
let fold_hooks = (list, hook_info, ast) =>
964964
List.fold_left(
965965
(ast, (hook_name, f)) =>
966966
try f(hook_info, ast) catch {
967-
| HookExn(e) => raise(e)
968-
| error => raise(HookExnWrapper({error: error, hook_name: hook_name, hook_info: hook_info}))
967+
| HookExn(e) => throw(e)
968+
| error => throw(HookExnWrapper({error: error, hook_name: hook_name, hook_info: hook_info}))
969969
},
970970
/* when explicit reraise with backtrace will be available,
971971
it should be used here */

analysis/examples/larger-project/src/res_token.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ let keywordTable = x =>
249249
| "type" => Typ
250250
| "when" => When
251251
| "while" => While
252-
| _ => raise(Not_found)
252+
| _ => throw(Not_found)
253253
}
254254

255255
let isKeyword = x =>

analysis/examples/larger-project/src/syntaxerr.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,5 @@ let location_of_error = x =>
8686
| Expecting(l, _) => l
8787
}
8888

89-
let ill_formed_ast = (loc, s) => raise(Error(Ill_formed_ast(loc, s)))
89+
let ill_formed_ast = (loc, s) => throw(Error(Ill_formed_ast(loc, s)))
9090

analysis/examples/larger-project/src/warnings.res

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ let mk_lazy = f => {
237237
} catch {
238238
| exn =>
239239
restore(prev)
240-
raise(exn)
240+
throw(exn)
241241
}
242242
}
243243
}
@@ -249,7 +249,7 @@ let parse_opt = (error, active, flags, s) => {
249249
active[i] = true
250250
error[i] = true
251251
}
252-
let error = () => raise(Arg.Bad("Ill-formed list of warnings"))
252+
let error = () => throw(Arg.Bad("Ill-formed list of warnings"))
253253
let rec get_num = (n, i) =>
254254
if i >= String.length(s) {
255255
(i, n)
@@ -601,7 +601,7 @@ let reset_fatal = () => nerrors := 0
601601
let check_fatal = () =>
602602
if nerrors.contents > 0 {
603603
nerrors := 0
604-
raise(Errors)
604+
throw(Errors)
605605
}
606606

607607
let descriptions = list{

analysis/reanalyze/src/Exception.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ let traverseAst () =
249249
case.c_guard |> iterExprOpt self;
250250
case.c_rhs |> iterExpr self)
251251
in
252-
let isRaise s = s = "Pervasives.raise" || s = "Pervasives.raise_notrace" in
252+
let isRaise s = s = "Pervasives.raise" || s = "Pervasives.throw" in
253253
let raiseArgs args =
254254
match args with
255255
| [(_, Some {Typedtree.exp_desc = Texp_construct ({txt}, _, _)})] ->

0 commit comments

Comments
 (0)