Skip to content

Commit 0073b81

Browse files
authored
Merge pull request #630 from bloomberg/fix_gpr_627
bug fix #627
2 parents 737215f + d8ec153 commit 0073b81

File tree

8 files changed

+120
-11
lines changed

8 files changed

+120
-11
lines changed

jscomp/js_dump.ml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,8 @@ let ipp_ident cxt f id un_used =
261261
ident cxt f (Ext_ident.make_unused ())
262262
else
263263
ident cxt f id
264-
let rec formal_parameter_list cxt (f : P.t) l env =
264+
let rec formal_parameter_list cxt (f : P.t) method_ l env =
265+
let offset = if method_ then 1 else 0 in
265266
let rec aux i cxt l =
266267
match l with
267268
| [] -> cxt
@@ -275,9 +276,9 @@ let rec formal_parameter_list cxt (f : P.t) l env =
275276
| [] -> cxt
276277
| [i] ->
277278
(** necessary, since some js libraries like [mocha]...*)
278-
if Js_fun_env.get_unused env 0 then cxt else ident cxt f i
279+
if Js_fun_env.get_unused env offset then cxt else ident cxt f i
279280
| _ ->
280-
aux 0 cxt l
281+
aux offset cxt l
281282

282283

283284
(* IdentMap *)
@@ -371,7 +372,7 @@ let rec pp_function method_
371372
| Some x -> ignore (ident inner_cxt f x));
372373
if method_ then begin
373374
let cxt = P.paren_group f 1 (fun _ ->
374-
formal_parameter_list inner_cxt f (List.tl l) env )
375+
formal_parameter_list inner_cxt f method_ (List.tl l) env )
375376
in
376377
P.space f ;
377378
ignore @@ P.brace_vgroup f 1 (fun _ ->
@@ -399,7 +400,7 @@ let rec pp_function method_
399400
end
400401
else begin
401402
let cxt = P.paren_group f 1 (fun _ ->
402-
formal_parameter_list inner_cxt f l env )
403+
formal_parameter_list inner_cxt f method_ l env )
403404
in
404405
P.space f ;
405406
ignore @@ P.brace_vgroup f 1 (fun _ -> statement_list false cxt f b );

jscomp/test/.depend

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,8 @@ gpr_441.cmj :
262262
gpr_441.cmx :
263263
gpr_459_test.cmj : mt.cmi
264264
gpr_459_test.cmx : mt.cmx
265+
gpr_627_test.cmj : mt.cmi
266+
gpr_627_test.cmx : mt.cmx
265267
guide_for_ext.cmj :
266268
guide_for_ext.cmx :
267269
hamming_test.cmj : ../stdlib/printf.cmi mt.cmi ../stdlib/lazy.cmi \
@@ -1012,6 +1014,8 @@ gpr_441.cmo :
10121014
gpr_441.cmj :
10131015
gpr_459_test.cmo : mt.cmi
10141016
gpr_459_test.cmj : mt.cmj
1017+
gpr_627_test.cmo : mt.cmi
1018+
gpr_627_test.cmj : mt.cmj
10151019
guide_for_ext.cmo :
10161020
guide_for_ext.cmj :
10171021
hamming_test.cmo : ../stdlib/printf.cmi mt.cmi ../stdlib/lazy.cmi \

jscomp/test/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ OTHERS := a test_ari test_export2 test_internalOO test_obj_simple_ffi test_scope
5959
optional_ffi_test poly_variant_test \
6060
bs_rest_test infer_type_test fs_test module_as_function\
6161
test_case_set test_mutliple string_bound_get_test inline_string_test\
62-
ppx_this_obj_test unsafe_obj_external
62+
ppx_this_obj_test unsafe_obj_external gpr_627_test
6363

6464

6565
SOURCE_LIST := js_dyn $(OTHERS)

jscomp/test/gpr_627_test.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
'use strict';
2+
3+
var Mt = require("./mt");
4+
var Block = require("../../lib/js/block");
5+
6+
var suites = [/* [] */0];
7+
8+
var test_id = [0];
9+
10+
function eq(loc, param) {
11+
var y = param[1];
12+
var x = param[0];
13+
test_id[0] = test_id[0] + 1 | 0;
14+
suites[0] = /* :: */[
15+
/* tuple */[
16+
loc + (" id " + test_id[0]),
17+
function () {
18+
return /* Eq */Block.__(0, [
19+
x,
20+
y
21+
]);
22+
}
23+
],
24+
suites[0]
25+
];
26+
return /* () */0;
27+
}
28+
29+
var u = {
30+
say: function (x, y) {
31+
return x + y | 0;
32+
}
33+
};
34+
35+
var v = {
36+
hi: function (x, y) {
37+
var self = this ;
38+
var u = {
39+
x: x
40+
};
41+
return self.say(u.x) + y + x;
42+
},
43+
say: function (x) {
44+
var self = this ;
45+
return x * self.x();
46+
},
47+
x: function () {
48+
return 3;
49+
}
50+
};
51+
52+
var p_001 = u.say(1, 2);
53+
54+
var p = /* tuple */[
55+
3,
56+
p_001
57+
];
58+
59+
eq('File "gpr_627_test.ml", line 26, characters 5-12', p);
60+
61+
eq('File "gpr_627_test.ml", line 27, characters 5-12', /* tuple */[
62+
v.hi(1, 2),
63+
6
64+
]);
65+
66+
Mt.from_pair_suites("gpr_627_test.ml", suites[0]);
67+
68+
exports.suites = suites;
69+
exports.test_id = test_id;
70+
exports.eq = eq;
71+
exports.u = u;
72+
exports.v = v;
73+
/* u Not a pure module */

jscomp/test/gpr_627_test.ml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
let suites : Mt.pair_suites ref = ref []
2+
let test_id = ref 0
3+
let eq loc (x, y) =
4+
incr test_id ;
5+
suites :=
6+
(loc ^" id " ^ (string_of_int !test_id), (fun _ -> Mt.Eq(x,y))) :: !suites
7+
8+
9+
let u = object
10+
method say x y = x + y
11+
end [@bs]
12+
13+
let v =
14+
let x = 3. in
15+
object (self)
16+
method hi x y =
17+
let u = [%bs.obj{ x }] in
18+
self##say u##x +. y +.x
19+
method say = fun x -> x *. self## x ()
20+
method x () = x
21+
end [@bs]
22+
23+
24+
let () =
25+
let p = (3, u##say 1 2) in
26+
eq __LOC__ p ;
27+
eq __LOC__ (v##hi 1. 2., 6.)
28+
29+
30+
let () = Mt.from_pair_suites __FILE__ !suites
31+

jscomp/test/ppx_this_obj_test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ var v3 = {
5858
hi: function (x, y) {
5959
var self = this ;
6060
var u = {
61-
x: 3
61+
x: x
6262
};
6363
return self.say(u.x) + y + x;
6464
},
@@ -72,10 +72,10 @@ var v3 = {
7272
};
7373

7474
var v4 = {
75-
hi: function (_, y) {
75+
hi: function (x, y) {
7676
return x + y;
7777
},
78-
say: function () {
78+
say: function (x) {
7979
return x;
8080
},
8181
x: function () {

jscomp/test/ppx_this_obj_test.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ let v3 =
3434
let x = 3. in
3535
object (self)
3636
method hi x y =
37-
let u = [%bs.obj{ x = 3. }] in
37+
let u = [%bs.obj{ x }] in
3838
self##say u##x +. y +.x
3939
method say = fun x -> x *. self## x ()
4040
method x () = x

jscomp/test/test_bs_this.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function f(x) {
4646
});
4747
}
4848

49-
function u() {
49+
function u(x) {
5050
return x;
5151
}
5252

0 commit comments

Comments
 (0)