Skip to content

Commit e15b650

Browse files
authored
Merge pull request #4610 from BuckleScript/remove_assert
[refactoring] remove internal usage of %assert, given ocaml exception already produce good stacktrace
2 parents c31b572 + c282587 commit e15b650

Some content is hidden

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

45 files changed

+279
-354
lines changed

jscomp/main/builtin_cmj_datasets.ml

Lines changed: 4 additions & 4 deletions
Large diffs are not rendered by default.

jscomp/others/belt_Array.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ external getUndefined: 'a array -> int -> 'a Js.undefined = "%array_unsafe_get"
2222
let get arr i =
2323
if i >= 0 && i < length arr then Some (getUnsafe arr i) else None
2424
let getExn arr i =
25-
[%assert i >= 0 && i < length arr] ;
25+
assert (i >= 0 && i < length arr) ;
2626
getUnsafe arr i
2727
let set arr i v =
2828
if i >= 0 && i < length arr then (setUnsafe arr i v; true) else false
2929

3030
let setExn arr i v =
31-
[%assert i >= 0 && i < length arr];
31+
assert (i >= 0 && i < length arr);
3232
setUnsafe arr i v
3333

3434

jscomp/others/belt_List.ml

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ let head x =
9292

9393
let headExn x =
9494
match x with
95-
| [] -> [%assert "headExn"]
95+
| [] -> raise Not_found
9696
| x::_ -> x
9797

9898
let tail x =
@@ -102,7 +102,7 @@ let tail x =
102102

103103
let tailExn x =
104104
match x with
105-
| [] -> [%assert "tailExn"]
105+
| [] -> raise Not_found
106106
| _::t -> t
107107

108108
let add xs x = x :: xs
@@ -116,14 +116,14 @@ let rec nthAux x n =
116116
let rec nthAuxAssert x n =
117117
match x with
118118
| h::t -> if n = 0 then h else nthAuxAssert t (n - 1)
119-
| _ -> [%assert "getExn"]
119+
| _ -> raise Not_found
120120

121121
let get x n =
122122
if n < 0 then None
123123
else nthAux x n
124124

125125
let getExn x n =
126-
if n < 0 then [%assert "getExn"]
126+
if n < 0 then raise Not_found
127127
else nthAuxAssert x n
128128

129129
let rec partitionAux p cell precX precY =
@@ -447,22 +447,7 @@ let shuffle xs =
447447
2. raise JS exception, how to pattern match
448448
*)
449449

450-
(* let fromJson j f = *)
451-
(* match J.decodeArray j with *)
452-
(* | Some arr -> *)
453-
(* let len = Belt_Array.length arr in *)
454-
(* if len = 0 then [] *)
455-
(* else *)
456-
(* let head = (mutableCell (f (A.getUnsafe arr 0) [@bs]) []) in *)
457-
(* let cell = ref head in *)
458-
(* for i = 1 to len - 1 do *)
459-
(* let next = mutableCell (f (A.getUnsafe arr i) [@bs]) [] in *)
460-
(* unsafeMutateTail.unsafeMutateTail !cell next ; *)
461-
(* cell .contents<- next *)
462-
(* done ; *)
463-
(* head *)
464-
(* | None -> *)
465-
(* [%assert "Not array when decoding list"] *)
450+
466451

467452
let rec reverseConcat l1 l2 =
468453
match l1 with

jscomp/others/belt_MutableQueue.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ let peekUndefined q =
7171

7272
let peekExn q =
7373
match q.first with
74-
| None -> [%assert "Belt.Queue.Empty"]
74+
| None -> raise Not_found
7575
| Some v -> v.content
7676

7777
let pop q =
@@ -92,7 +92,7 @@ let pop q =
9292

9393
let popExn q = (* TO fix *)
9494
match q.first with
95-
| None -> [%assert "Empty"]
95+
| None -> raise Not_found
9696
| Some x ->
9797
let next = x.next in
9898
if next = None then

jscomp/others/belt_Option.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ let forEach opt f = forEachU opt (fun[@bs] x -> f x)
3030

3131
let getExn = function
3232
| Some x -> x
33-
| None -> [%assert "getExn"]
33+
| None -> raise Not_found
3434

3535
external getUnsafe : 'a option -> 'a = "%identity"
3636

jscomp/others/belt_Result.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ type ('a,'b) t = Ok of 'a | Error of 'b
2626

2727
let getExn = function
2828
| Ok x -> x
29-
| Error _ -> [%assert "getExn"]
29+
| Error _ -> raise Not_found
3030

3131
let mapWithDefaultU opt default f = match opt with
3232
| Ok x -> (f x [@bs])

jscomp/others/belt_internalAVLset.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ let rec checkInvariantInternal (v : _ t) =
287287
| Some n ->
288288
let {left = l; right = r} = n in
289289
let diff = height l - height r in
290-
[%assert diff <=2 && diff >= -2];
290+
assert (diff <=2 && diff >= -2);
291291
checkInvariantInternal l;
292292
checkInvariantInternal r
293293

@@ -529,7 +529,7 @@ let rec getUndefined (n : _ t) x ~cmp =
529529

530530
let rec getExn (n : _ t) x ~cmp =
531531
match n with
532-
None -> [%assert "getExn0"]
532+
None -> raise Not_found
533533
| Some t (* Node(l, v, r, _) *) ->
534534
let v = t.value in
535535
let c = (Belt_Id.getCmpInternal cmp) x v [@bs] in

jscomp/others/belt_internalAVLtree.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ let rec checkInvariantInternal (v : _ t) =
370370
| Some n ->
371371
let l,r = n.left , n.right in
372372
let diff = treeHeight l - treeHeight r in
373-
[%assert diff <=2 && diff >= -2 ];
373+
assert (diff <=2 && diff >= -2 );
374374
checkInvariantInternal l;
375375
checkInvariantInternal r
376376

@@ -604,7 +604,7 @@ let rec getUndefined n x ~cmp =
604604
let rec getExn n x ~cmp =
605605
match n with
606606
None ->
607-
[%assert "getExn0"]
607+
raise Not_found
608608
| Some n (* Node(l, v, d, r, _)*) ->
609609
let v = n.key in
610610
let c = (Belt_Id.getCmpInternal cmp) x v [@bs] in

jscomp/others/belt_internalMapInt.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ let rec getUndefined n (x : key) =
4646

4747
let rec getExn n (x : key) =
4848
match n with
49-
| None -> [%assert "getExn"]
49+
| None -> raise Not_found
5050
| Some n ->
5151
let v = n.N.key in
5252
if x = v then n.N.value

jscomp/others/belt_internalMapString.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ let rec getUndefined n (x : key) =
4646

4747
let rec getExn n (x : key) =
4848
match n with
49-
| None -> [%assert "getExn"]
49+
| None -> raise Not_found
5050
| Some n ->
5151
let v = n.N.key in
5252
if x = v then n.N.value

0 commit comments

Comments
 (0)