Skip to content

Commit 939a445

Browse files
committed
add a test case for p_is_int
1 parent 1279a00 commit 939a445

File tree

8 files changed

+147
-78
lines changed

8 files changed

+147
-78
lines changed

jscomp/test/exception_rebind_test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ var B = {
1313
F: E
1414
};
1515

16+
var A0 = Caml_exceptions.create("Exception_rebind_test.A0");
17+
1618
var H = Exception_def.A;
1719

1820
exports.A = A;
1921
exports.B = B;
2022
exports.H = H;
23+
exports.A0 = A0;
2124
/* Exception_def Not a pure module */

jscomp/test/exception_rebind_test.ml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,11 @@ module B = struct
99
end
1010

1111
exception H = Exception_def.A
12+
13+
14+
type u = exn
15+
16+
type exn += A0 of int
17+
#if 0 then
18+
type u += A1 of int (*Type definition u is not extensible*)
19+
#end

jscomp/test/poly_variant_test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,21 @@ function test(readline, x) {
120120
return /* () */0;
121121
}
122122

123+
function p_is_int_test(x) {
124+
if (typeof x === "number") {
125+
return 2;
126+
} else {
127+
return 3;
128+
}
129+
}
130+
131+
eq("File \"poly_variant_test.ml\", line 142, characters 5-12", 2, 2);
132+
133+
eq("File \"poly_variant_test.ml\", line 143, characters 5-12", 3, p_is_int_test(/* `b */[
134+
98,
135+
2
136+
]));
137+
123138
Mt.from_pair_suites("Poly_variant_test", suites.contents);
124139

125140
function on2(prim, prim$1) {
@@ -144,4 +159,5 @@ exports.test = test;
144159
exports.on2 = on2;
145160
exports.read = read;
146161
exports.readN = readN;
162+
exports.p_is_int_test = p_is_int_test;
147163
/* Not a pure module */

jscomp/test/poly_variant_test.ml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,16 @@ let register readline =
130130
let test readline x =
131131
on readline x
132132

133+
134+
let p_is_int_test x =
135+
match x with
136+
| `a -> 2
137+
| `b _ -> 3
138+
139+
let u = `b 2
140+
141+
let () =
142+
eq __LOC__ 2 (p_is_int_test `a);
143+
eq __LOC__ 3 (p_is_int_test u)
144+
133145
let () = Mt.from_pair_suites __MODULE__ !suites

jscomp/test/poly_variant_test.mli

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,6 @@ val on2 :
3737

3838
val read : string -> string
3939
val readN : string -> string
40+
41+
val p_is_int_test
42+
: [`a | `b of int] -> int

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -35636,13 +35636,13 @@ val ref_tag_info : tag_info
3563635636
type field_dbg_info =
3563735637
| Fld_na
3563835638
| Fld_record of {name : string; mutable_flag : Asttypes.mutable_flag}
35639-
| Fld_module of string
35640-
| Fld_record_inline of string
35641-
| Fld_record_extension of string
35639+
| Fld_module of {name : string}
35640+
| Fld_record_inline of {name : string}
35641+
| Fld_record_extension of {name : string}
3564235642
| Fld_tuple
3564335643
| Fld_poly_var_tag
3564435644
| Fld_poly_var_content
35645-
35645+
| Fld_extension_slot
3564635646
val fld_record :
3564735647
(Types.label_description ->
3564835648
field_dbg_info) ref
@@ -36098,13 +36098,13 @@ let ref_tag_info : tag_info = Blk_record [| "contents" |]
3609836098
type field_dbg_info =
3609936099
| Fld_na
3610036100
| Fld_record of {name : string; mutable_flag : Asttypes.mutable_flag}
36101-
| Fld_module of string
36102-
| Fld_record_inline of string
36103-
| Fld_record_extension of string
36101+
| Fld_module of {name : string }
36102+
| Fld_record_inline of { name : string}
36103+
| Fld_record_extension of {name : string}
3610436104
| Fld_tuple
3610536105
| Fld_poly_var_tag
3610636106
| Fld_poly_var_content
36107-
36107+
| Fld_extension_slot
3610836108
let fld_record = ref (fun (lbl : Types.label_description) ->
3610936109
Fld_record {name = lbl.lbl_name; mutable_flag = Mutable})
3611036110

@@ -36637,7 +36637,7 @@ let rec transl_normal_path = function
3663736637
then Lprim(Pgetglobal id, [], Location.none)
3663836638
else Lvar id
3663936639
| Pdot(p, s, pos) ->
36640-
Lprim(Pfield (pos, Fld_module s), [transl_normal_path p], Location.none)
36640+
Lprim(Pfield (pos, Fld_module {name = s}), [transl_normal_path p], Location.none)
3664136641
| Papply _ ->
3664236642
fatal_error "Lambda.transl_path"
3664336643

@@ -101029,6 +101029,16 @@ let block_shape ppf shape = match shape with
101029101029
t;
101030101030
Format.fprintf ppf ")"
101031101031

101032+
101033+
let str_of_field_info (fld_info : Lambda.field_dbg_info)=
101034+
match fld_info with
101035+
| (Fld_module {name } | Fld_record {name} | Fld_record_inline {name} | Fld_record_extension {name})
101036+
-> name
101037+
| Fld_na -> "na"
101038+
| Fld_tuple -> "[]"
101039+
| Fld_poly_var_tag->"`"
101040+
| Fld_poly_var_content -> "#"
101041+
| Fld_extension_slot -> "ext"
101032101042
let primitive ppf = function
101033101043
| Pidentity -> fprintf ppf "id"
101034101044
| Pbytes_to_string -> fprintf ppf "bytes_to_string"
@@ -101043,8 +101053,7 @@ let primitive ppf = function
101043101053
fprintf ppf "makeblock %i%a" tag block_shape shape
101044101054
| Pmakeblock(tag, _, Mutable, shape) ->
101045101055
fprintf ppf "makemutable %i%a" tag block_shape shape
101046-
| Pfield (n, (Fld_module s | Fld_record {name=s})) -> fprintf ppf "field:%s/%i" s n
101047-
| Pfield (n,_) -> fprintf ppf "field %i" n
101056+
| Pfield (n, fld) -> fprintf ppf "field:%s/%i" (str_of_field_info fld) n
101048101057
| Pfield_computed -> fprintf ppf "field_computed"
101049101058
| Psetfield(n, ptr, init, _) ->
101050101059
let instr =
@@ -104056,7 +104065,7 @@ let get_mod_field modname field =
104056104065
with Not_found ->
104057104066
fatal_error ("Primitive "^modname^"."^field^" not found.")
104058104067
in
104059-
Lprim(Pfield (p, Fld_module field),
104068+
Lprim(Pfield (p, Fld_module {name = field}),
104060104069
[Lprim(Pgetglobal mod_ident, [], Location.none)],
104061104070
Location.none)
104062104071
with Not_found -> fatal_error ("Module "^modname^" unavailable.")
@@ -104227,10 +104236,10 @@ let make_record_matching loc all_labels def = function
104227104236
| Record_regular ->
104228104237
Lprim (Pfield (lbl.lbl_pos, !Lambda.fld_record lbl), [arg], loc)
104229104238
| Record_inlined _ ->
104230-
Lprim (Pfield (lbl.lbl_pos, Fld_record_inline lbl.lbl_name), [arg], loc)
104239+
Lprim (Pfield (lbl.lbl_pos, Fld_record_inline {name = lbl.lbl_name}), [arg], loc)
104231104240
| Record_unboxed _ -> arg
104232104241
| Record_float -> Lprim (Pfloatfield (lbl.lbl_pos, !Lambda.fld_record lbl), [arg], loc)
104233-
| Record_extension -> Lprim (Pfield (lbl.lbl_pos + 1, Fld_record_extension lbl.lbl_name), [arg], loc)
104242+
| Record_extension -> Lprim (Pfield (lbl.lbl_pos + 1, Fld_record_extension {name = lbl.lbl_name}), [arg], loc)
104234104243
in
104235104244
let str =
104236104245
match lbl.lbl_mut with
@@ -104929,7 +104938,7 @@ let combine_constructor sw_names loc arg ex_pat cstr partial ctx def
104929104938
nonconsts
104930104939
default
104931104940
in
104932-
Llet(Alias, Pgenval,tag, Lprim(Pfield (0, Fld_na), [arg], loc), tests)
104941+
Llet(Alias, Pgenval,tag, Lprim(Pfield (0, Fld_extension_slot), [arg], loc), tests)
104933104942
in
104934104943
List.fold_right
104935104944
(fun (path, act) rem ->
@@ -105532,9 +105541,9 @@ let partial_function loc () =
105532105541
Filename.basename fname
105533105542
in
105534105543

105535-
Lprim(Praise Raise_regular, [Lprim(Pmakeblock(0, Lambda.Blk_extension, Immutable, None),
105544+
Lprim(Praise Raise_regular, [Lprim(Pmakeblock(0, Blk_extension, Immutable, None),
105536105545
[transl_normal_path Predef.path_match_failure;
105537-
Lconst(Const_block(0, Lambda.Blk_tuple,
105546+
Lconst(Const_block(0, Blk_tuple,
105538105547
[Const_base(Const_string (fname, None));
105539105548
Const_base(Const_int line);
105540105549
Const_base(Const_int char)]))], loc)], loc)
@@ -106923,9 +106932,9 @@ let assert_failed exp =
106923106932
in
106924106933

106925106934
Lprim(Praise Raise_regular, [event_after exp
106926-
(Lprim(Pmakeblock(0, Lambda.Blk_extension, Immutable, None),
106935+
(Lprim(Pmakeblock(0, Blk_extension, Immutable, None),
106927106936
[transl_normal_path Predef.path_assert_failure;
106928-
Lconst(Const_block(0, Lambda.Blk_tuple,
106937+
Lconst(Const_block(0, Blk_tuple,
106929106938
[Const_base(Const_string (fname, None));
106930106939
Const_base(Const_int line);
106931106940
Const_base(Const_int char)]))], exp.exp_loc))], exp.exp_loc)
@@ -107181,11 +107190,11 @@ and transl_exp0 e =
107181107190
Record_regular ->
107182107191
Lprim (Pfield (lbl.lbl_pos, !Lambda.fld_record lbl), [targ], e.exp_loc)
107183107192
| Record_inlined _ ->
107184-
Lprim (Pfield (lbl.lbl_pos, Fld_record_inline lbl.lbl_name), [targ], e.exp_loc)
107193+
Lprim (Pfield (lbl.lbl_pos, Fld_record_inline {name = lbl.lbl_name}), [targ], e.exp_loc)
107185107194
| Record_unboxed _ -> targ
107186107195
| Record_float -> Lprim (Pfloatfield (lbl.lbl_pos, !Lambda.fld_record lbl), [targ], e.exp_loc)
107187107196
| Record_extension ->
107188-
Lprim (Pfield (lbl.lbl_pos + 1, Fld_record_extension lbl.lbl_name), [targ], e.exp_loc)
107197+
Lprim (Pfield (lbl.lbl_pos + 1, Fld_record_extension {name = lbl.lbl_name}), [targ], e.exp_loc)
107189107198
end
107190107199
| Texp_setfield(arg, _, lbl, newval) ->
107191107200
let access =
@@ -107586,9 +107595,9 @@ and transl_record loc env fields repres opt_init_expr =
107586107595
let access =
107587107596
match repres with
107588107597
Record_regular -> Pfield (i, !Lambda.fld_record lbl)
107589-
| Record_inlined _ -> Pfield (i, Fld_record_inline lbl.lbl_name)
107598+
| Record_inlined _ -> Pfield (i, Fld_record_inline {name = lbl.lbl_name})
107590107599
| Record_unboxed _ -> assert false
107591-
| Record_extension -> Pfield (i + 1, Fld_record_extension lbl.lbl_name)
107600+
| Record_extension -> Pfield (i + 1, Fld_record_extension {name = lbl.lbl_name})
107592107601
| Record_float -> Pfloatfield (i, !Lambda.fld_record lbl) in
107593107602
Lprim(access, [Lvar init_id], loc), field_kind
107594107603
| Overridden (_lid, expr) ->
@@ -108814,9 +108823,9 @@ let rec apply_coercion loc strict restr arg =
108814108823
assert (List.length runtime_fields = List.length pos_cc_list);
108815108824
let names = Array.of_list runtime_fields in
108816108825
name_lambda strict arg (fun id ->
108817-
let get_field_i i pos = Lprim(Pfield (pos, Fld_module names.(i)),[Lvar id], loc) in
108826+
let get_field_i i pos = Lprim(Pfield (pos, Fld_module {name = names.(i)}),[Lvar id], loc) in
108818108827
let get_field_name name pos =
108819-
Lprim (Pfield (pos, Fld_module name), [Lvar id], loc) in
108828+
Lprim (Pfield (pos, Fld_module {name}), [Lvar id], loc) in
108820108829
let lam =
108821108830
Lprim(Pmakeblock(0, Lambda.Blk_module runtime_fields, Immutable, None),
108822108831
List.mapi (fun i x -> apply_coercion_field loc (get_field_i i) x) pos_cc_list,
@@ -109407,7 +109416,7 @@ and transl_structure loc fields cc rootpath final_env = function
109407109416
rebind_idents (pos + 1) (id :: newfields) ids
109408109417
in
109409109418
Llet(Alias, Pgenval, id,
109410-
Lprim(Pfield (pos, Fld_module (Ident.name id)) , [Lvar mid], incl.incl_loc), body),
109419+
Lprim(Pfield (pos, Fld_module {name = Ident.name id}) , [Lvar mid], incl.incl_loc), body),
109411109420
size
109412109421
in
109413109422
let body, size = rebind_idents 0 fields ids in

0 commit comments

Comments
 (0)