Skip to content

Commit 057e2ac

Browse files
committed
refactor
1 parent 7b3b777 commit 057e2ac

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

src/Exception.re

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ module Values = {
77
Hashtbl.create(15);
88
let currentFileTable = ref(Hashtbl.create(1));
99

10-
let add = (~id, exceptions) => {
11-
let name = Ident.name(id);
10+
let add = (~name, exceptions) => {
1211
let path = [name |> Name.create, ...ModulePath.getCurrent().path];
1312
Hashtbl.replace(
1413
currentFileTable^,
@@ -233,19 +232,19 @@ module Event = {
233232
module Checks = {
234233
type check = {
235234
events: list(Event.t),
236-
id: Ident.t,
237235
loc: Location.t,
238236
moduleName: string,
237+
name: string,
239238
exceptions: Exceptions.t,
240239
};
241240
type t = list(check);
242241

243242
let checks: ref(t) = ref([]);
244243

245-
let add = (~events, ~exceptions, ~id, ~loc, ~moduleName) =>
246-
checks := [{events, exceptions, id, loc, moduleName}, ...checks^];
244+
let add = (~events, ~exceptions, ~loc, ~moduleName, ~name) =>
245+
checks := [{events, exceptions, loc, moduleName, name}, ...checks^];
247246

248-
let doCheck = ({events, exceptions, id, loc, moduleName}) => {
247+
let doCheck = ({events, exceptions, loc, moduleName, name}) => {
249248
let (raiseSet, exnTable) = events |> Event.combine(~moduleName);
250249
let missingAnnotations = Exceptions.diff(raiseSet, exceptions);
251250
let redundantAnnotations = Exceptions.diff(exceptions, raiseSet);
@@ -254,7 +253,7 @@ module Checks = {
254253
Format.fprintf(
255254
ppf,
256255
"@{<info>%s@} might raise%a and is not annotated with @raises%a",
257-
id |> Ident.name,
256+
name,
258257
Exceptions.pp(~exnTable=Some(exnTable)),
259258
raiseSet,
260259
Exceptions.pp(~exnTable=None),
@@ -281,7 +280,7 @@ module Checks = {
281280
Format.fprintf(
282281
ppf,
283282
"@{<info>%s@} %a and is annotated with redundant @raises%a",
284-
id |> Ident.name,
283+
name,
285284
raisesDescription,
286285
(),
287286
Exceptions.pp(~exnTable=None),
@@ -526,11 +525,7 @@ let traverseAst = {
526525
| _ => false
527526
};
528527
let isToplevel = currentId^ == "";
529-
switch (vb.vb_pat.pat_desc) {
530-
| Tpat_var(id, {loc: {loc_ghost}})
531-
when (isFunction || isToplevel) && !loc_ghost && !vb.vb_loc.loc_ghost =>
532-
let name = Ident.name(id);
533-
528+
let processBinding = name => {
534529
currentId := name;
535530
currentEvents := [];
536531

@@ -560,12 +555,12 @@ let traverseAst = {
560555
| None => Exceptions.empty
561556
| Some(payload) => payload |> getExceptions
562557
};
563-
exceptionsFromAnnotations |> Values.add(~id);
558+
exceptionsFromAnnotations |> Values.add(~name);
564559
let res = super.value_binding(self, vb);
565560

566561
let moduleName = Common.currentModule^;
567562

568-
let path = [id |> Ident.name |> Name.create];
563+
let path = [name |> Name.create];
569564
let exceptions =
570565
switch (
571566
path
@@ -580,16 +575,20 @@ let traverseAst = {
580575
Checks.add(
581576
~events=currentEvents^,
582577
~exceptions,
583-
~id,
584578
~loc=vb.vb_pat.pat_loc,
585579
~moduleName,
580+
~name,
586581
);
587582

588583
currentId := oldId;
589584
currentEvents := oldEvents;
590585

591586
res;
592-
587+
};
588+
switch (vb.vb_pat.pat_desc) {
589+
| Tpat_var(id, {loc: {loc_ghost}})
590+
when (isFunction || isToplevel) && !loc_ghost && !vb.vb_loc.loc_ghost =>
591+
processBinding(id |> Ident.name)
593592
| _ => super.value_binding(self, vb)
594593
};
595594
};

0 commit comments

Comments
 (0)