Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
zth committed Oct 2, 2024
1 parent 81b11ec commit 02c12f1
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions jscomp/ml/typecore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ module NameChoice(Name : sig
val get_type: t -> type_expr
val get_descrs: Env.type_descriptions -> t list

val unsafe_do_not_use_add_with_name: t -> string -> t
val unsafe_do_not_use__add_with_name: t -> string -> t
val unbound_name_error: Env.t -> Longident.t loc -> 'a

end) = struct
Expand All @@ -807,21 +807,9 @@ end) = struct
if Path.same tpath Predef.path_dict then (
(* [dict] Handle directing any label lookup to the magic dict field. *)
match lid.txt with
Longident.Lident s_ -> begin
let s =
if List.exists (fun nd -> get_name nd = s_) descrs
|| not (List.exists (fun nd -> get_name nd = Dict_type_helpers.dict_magic_field_name) descrs)
then s_
else Dict_type_helpers.dict_magic_field_name in
try
let x = List.find (fun nd -> get_name nd = s) descrs in
if s = Dict_type_helpers.dict_magic_field_name
then unsafe_do_not_use_add_with_name x s_
else x
with Not_found ->
let names = List.map get_name descrs in
raise (Error (lid.loc, env,
Wrong_name ("", newvar (), type_kind, tpath, s, names)))
Longident.Lident s -> begin
let x = List.find (fun nd -> get_name nd = Dict_type_helpers.dict_magic_field_name) descrs in
unsafe_do_not_use__add_with_name x s
end
| _ -> raise Not_found)
else match lid.txt with
Expand Down Expand Up @@ -908,7 +896,7 @@ module Label = NameChoice (struct
let type_kind = "record"
let get_name lbl = lbl.lbl_name

let unsafe_do_not_use_add_with_name lbl name =
let unsafe_do_not_use__add_with_name lbl name =
(* [dict] This is used in dicts and shouldn't be used anywhere else.
It adds a new field to an existing record type, to "fool" the pattern
matching into thinking the label exists. *)
Expand Down Expand Up @@ -1078,7 +1066,7 @@ module Constructor = NameChoice (struct
let get_name cstr = cstr.cstr_name
let get_type cstr = cstr.cstr_res

let unsafe_do_not_use_add_with_name _cstr _name = assert false
let unsafe_do_not_use__add_with_name _cstr _name = assert false
let get_descrs = fst
let unbound_name_error = Typetexp.unbound_constructor_error
end)
Expand Down

0 comments on commit 02c12f1

Please sign in to comment.