Skip to content

Commit eaff193

Browse files
committed
fix #5169
# Conflicts: # scripts/ninja.js
1 parent 9601edb commit eaff193

File tree

7 files changed

+130
-2
lines changed

7 files changed

+130
-2
lines changed

jscomp/test/build.ninja

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ o test/gpr_4900_test.cmi test/gpr_4900_test.cmj : cc test/gpr_4900_test.ml | tes
325325
o test/gpr_4924_test.cmi test/gpr_4924_test.cmj : cc test/gpr_4924_test.ml | test/mt.cmj $stdlib
326326
o test/gpr_4931.cmi test/gpr_4931.cmj : cc test/gpr_4931.ml | $stdlib
327327
o test/gpr_5071_test.cmi test/gpr_5071_test.cmj : cc test/gpr_5071_test.res | test/react.cmj $stdlib
328+
o test/gpr_5169_test.cmi test/gpr_5169_test.cmj : cc test/gpr_5169_test.ml | $stdlib
328329
o test/gpr_627_test.cmi test/gpr_627_test.cmj : cc test/gpr_627_test.ml | test/mt.cmj $stdlib
329330
o test/gpr_658.cmi test/gpr_658.cmj : cc test/gpr_658.ml | $stdlib
330331
o test/gpr_858_test.cmi test/gpr_858_test.cmj : cc test/gpr_858_test.ml | $stdlib
@@ -479,6 +480,7 @@ o test/ocaml_typedtree_test.cmi : cc test/ocaml_typedtree_test.mli | $stdlib
479480
o test/of_string_test.cmi test/of_string_test.cmj : cc test/of_string_test.ml | test/mt.cmj $stdlib
480481
o test/offset.cmi test/offset.cmj : cc test/offset.ml | $stdlib
481482
o test/oo_js_test_date.cmi test/oo_js_test_date.cmj : cc test/oo_js_test_date.ml | test/mt.cmj $stdlib
483+
o test/option_encoding_test.cmi test/option_encoding_test.cmj : cc test/option_encoding_test.ml | $stdlib
482484
o test/option_repr_test.cmi test/option_repr_test.cmj : cc test/option_repr_test.ml | test/mt.cmj $stdlib
483485
o test/optional_ffi_test.cmi test/optional_ffi_test.cmj : cc test/optional_ffi_test.ml | test/mt.cmj $stdlib
484486
o test/optional_regression_test.cmi test/optional_regression_test.cmj : cc test/optional_regression_test.ml | test/mt.cmj $stdlib

jscomp/test/gpr_5169_test.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
'use strict';
2+
3+
4+
var NotOption = {};
5+
6+
var TotallyNotOption = {};
7+
8+
var NotOption2 = {};
9+
10+
var a;
11+
12+
var b = 1;
13+
14+
var c;
15+
16+
var d = 1;
17+
18+
var e;
19+
20+
var f = 1;
21+
22+
var g;
23+
24+
var h = 1;
25+
26+
var i = /* None */0;
27+
28+
var j = /* Some */{
29+
_0: 1
30+
};
31+
32+
var k = /* None */0;
33+
34+
var l = /* Some */{
35+
_0: 1
36+
};
37+
38+
exports.NotOption = NotOption;
39+
exports.a = a;
40+
exports.b = b;
41+
exports.c = c;
42+
exports.d = d;
43+
exports.TotallyNotOption = TotallyNotOption;
44+
exports.e = e;
45+
exports.f = f;
46+
exports.g = g;
47+
exports.h = h;
48+
exports.NotOption2 = NotOption2;
49+
exports.i = i;
50+
exports.j = j;
51+
exports.k = k;
52+
exports.l = l;
53+
/* No side effect */

jscomp/test/gpr_5169_test.ml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
module NotOption = struct
2+
3+
type 'a t = None | Some of 'a
4+
end
5+
6+
let a = NotOption.None (* undefined *)
7+
let b = NotOption.Some(1) (* 1 *)
8+
let c = let open NotOption in None
9+
let d = let open NotOption in Some(1)
10+
11+
12+
module TotallyNotOption = struct
13+
type 'a t = Some of ('a) | None
14+
end
15+
16+
let e = TotallyNotOption.None (* undefined *)
17+
let f = TotallyNotOption.Some(1) (* 1 *)
18+
let g = let open TotallyNotOption in None
19+
let h = let open TotallyNotOption in Some(1)
20+
21+
22+
module NotOption2 = struct
23+
type 'a t = None | Some of 'a | Bogus
24+
end
25+
26+
let i = NotOption2.None
27+
let j = NotOption2.Some(1)
28+
let k = let open NotOption2 in None
29+
let l = let open NotOption2 in Some(1)

jscomp/test/option_encoding_test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
3+
4+
var N = {};
5+
6+
var u = [
7+
undefined,
8+
3
9+
];
10+
11+
var h;
12+
13+
exports.N = N;
14+
exports.u = u;
15+
exports.h = h;
16+
/* No side effect */

jscomp/test/option_encoding_test.ml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[@@@config {
2+
flags = [|
3+
"-w";
4+
"@A";
5+
"-drawlambda";
6+
"-dtypedtree";
7+
"-bs-diagnose";
8+
"-dparsetree";
9+
(* "-dsource"; *)
10+
|]
11+
}]
12+
13+
14+
module N = struct
15+
type 'a t = 'a option =
16+
| None
17+
| Some of 'a
18+
end
19+
20+
21+
let u = N.(None, Some 3)
22+
23+
24+
let h = N.None

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72567,7 +72567,9 @@ and transl_exp0 e =
7256772567
| Longident.Lident "None"
7256872568
when Datarepr.constructor_has_optional_shape cstr
7256972569
-> Pt_shape_none
72570-
| _ -> Pt_constructor {name = cstr.cstr_name; const = cstr.cstr_consts; non_const = cstr.cstr_nonconsts}
72570+
| _ ->
72571+
if Datarepr.constructor_has_optional_shape cstr then Pt_shape_none
72572+
else Pt_constructor {name = cstr.cstr_name; const = cstr.cstr_consts; non_const = cstr.cstr_nonconsts}
7257172573
))
7257272574
| Cstr_unboxed ->
7257372575
(match ll with [v] -> v | _ -> assert false)

lib/4.06.1/whole_compiler.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356391,7 +356391,9 @@ and transl_exp0 e =
356391356391
| Longident.Lident "None"
356392356392
when Datarepr.constructor_has_optional_shape cstr
356393356393
-> Pt_shape_none
356394-
| _ -> Pt_constructor {name = cstr.cstr_name; const = cstr.cstr_consts; non_const = cstr.cstr_nonconsts}
356394+
| _ ->
356395+
if Datarepr.constructor_has_optional_shape cstr then Pt_shape_none
356396+
else Pt_constructor {name = cstr.cstr_name; const = cstr.cstr_consts; non_const = cstr.cstr_nonconsts}
356395356397
))
356396356398
| Cstr_unboxed ->
356397356399
(match ll with [v] -> v | _ -> assert false)

0 commit comments

Comments
 (0)