Skip to content

Commit 8f911d5

Browse files
committed
Use value from as attribute if available
1 parent 44e9786 commit 8f911d5

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

compiler/core/lam_constant_convert.ml

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,26 @@ let rec convert_constant (const : Lambda.structured_constant) : Lam_constant.t =
4242
| Const_false -> Const_js_false
4343
| Const_true -> Const_js_true
4444
| Const_pointer (i, p) -> (
45-
match p with
46-
| Pt_module_alias -> Const_module_alias
47-
| Pt_shape_none -> Lam_constant.lam_none
48-
| Pt_assertfalse -> Const_int {i = Int32.of_int i; comment = Pt_assertfalse}
49-
| Pt_constructor {name; const; non_const; attrs} ->
50-
let tag_type = Ast_untagged_variants.process_tag_type attrs in
51-
Const_int
52-
{
53-
i = Int32.of_int i;
54-
comment =
55-
Pt_constructor {cstr_name = {name; tag_type}; const; non_const};
56-
}
57-
| Pt_variant {name} ->
58-
if Ext_string.is_valid_hash_number name then
59-
Const_int {i = Ext_string.hash_number_as_i32_exn name; comment = None}
60-
else Const_pointer name)
45+
match p with
46+
| Pt_module_alias -> Const_module_alias
47+
| Pt_shape_none -> Lam_constant.lam_none
48+
| Pt_assertfalse ->
49+
Const_int { i = Int32.of_int i; comment = Pt_assertfalse }
50+
| Pt_constructor { name; const; non_const; attrs } ->
51+
let tag_type = Ast_untagged_variants.process_tag_type attrs in
52+
let i = match tag_type with
53+
| Some(Ast_untagged_variants.Int(v)) -> v
54+
| _ -> i in
55+
Const_int
56+
{
57+
i = Int32.of_int i;
58+
comment = Pt_constructor { cstr_name={name; tag_type}; const; non_const };
59+
}
60+
| Pt_variant { name } ->
61+
if Ext_string.is_valid_hash_number name then
62+
Const_int
63+
{ i = Ext_string.hash_number_as_i32_exn name; comment = None }
64+
else Const_pointer name)
6165
| Const_float_array s -> assert false
6266
| Const_immstring s -> Const_string {s; unicode = false}
6367
| Const_block (t, xs) -> (

0 commit comments

Comments
 (0)