Skip to content

Commit 251699b

Browse files
authored
Merge pull request rescript-lang#1601 from bloomberg/fix_printer_bug
fix rescript-lang#1600
2 parents 14b7d3f + 704e1bd commit 251699b

File tree

8 files changed

+121
-11
lines changed

8 files changed

+121
-11
lines changed

jscomp/bin/all_ounit_tests.ml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4123,7 +4123,23 @@ external ff :
41234123
OUnit.assert_bool __LOC__
41244124
(not (Ext_string.is_empty should_err.stderr))
41254125

4126-
end
4126+
end;
4127+
4128+
(* __LOC__ >:: begin fun _ -> *)
4129+
(* let should_infer = perform_bsc [| "-i"; "-bs-eval"|] {| *)
4130+
(* let f = fun [@bs] x -> let (a,b) = x in a + b *)
4131+
(* |} in *)
4132+
(* let infer_type = bsc_eval (Printf.sprintf {| *)
4133+
4134+
(* let f : %s = fun [@bs] x -> let (a,b) = x in a + b *)
4135+
(* |} should_infer.stdout ) in *)
4136+
(* begin *)
4137+
(* Ounit_cmd_util.debug_output should_infer ; *)
4138+
(* Ounit_cmd_util.debug_output infer_type ; *)
4139+
(* OUnit.assert_bool __LOC__ *)
4140+
(* ((Ext_string.is_empty infer_type.stderr)) *)
4141+
(* end *)
4142+
(* end *)
41274143
]
41284144

41294145

jscomp/bin/whole_compiler.ml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41474,16 +41474,19 @@ and print_simple_out_type ppf =
4147441474
print_ident id
4147541475

4147641476
| Otyp_constr ((Oide_dot (Oide_ident "Js", ("fn" | "meth" as name )) as id) ,
41477-
([Otyp_variant(_,Ovar_fields [ _, _, tys], _,_); result] as tyl))
41477+
([Otyp_variant(_,Ovar_fields [ variant, _, tys], _,_); result] as tyl))
4147841478
->
4147941479
(* Otyp_arrow*)
4148041480
let make tys result =
4148141481
if tys = [] then
4148241482
Otyp_arrow ("", Otyp_constr (Oide_ident "unit", []),result)
4148341483
else
41484-
match tys with
41485-
| [ Otyp_tuple tys] ->
41486-
List.fold_right (fun x acc -> Otyp_arrow("",x,acc) ) tys result
41484+
match tys with
41485+
| [ Otyp_tuple tys as single] ->
41486+
if variant = "Arity_1" then
41487+
Otyp_arrow ("", single, result)
41488+
else
41489+
List.fold_right (fun x acc -> Otyp_arrow("",x,acc) ) tys result
4148741490
| [single] ->
4148841491
Otyp_arrow ("", single, result)
4148941492
| _ ->
@@ -41507,12 +41510,14 @@ and print_simple_out_type ppf =
4150741510
end
4150841511
end
4150941512
| Otyp_constr ((Oide_dot (Oide_ident "Js", "meth_callback" ) as id) ,
41510-
([Otyp_variant(_,Ovar_fields [ _, _, tys], _,_); result] as tyl))
41513+
([Otyp_variant(_,Ovar_fields [ variant, _, tys], _,_); result] as tyl))
4151141514
->
4151241515
let make tys result =
4151341516
match tys with
41514-
| [ Otyp_tuple tys] ->
41515-
List.fold_right (fun x acc -> Otyp_arrow("",x,acc) ) tys result
41517+
| [ Otyp_tuple tys as single ] ->
41518+
if variant = "Arity_1" then Otyp_arrow ("", single, result)
41519+
else
41520+
List.fold_right (fun x acc -> Otyp_arrow("",x,acc) ) tys result
4151641521
| [single] ->
4151741522
Otyp_arrow ("", single, result)
4151841523
| _ ->

jscomp/ounit_tests/ounit_cmd_tests.ml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,22 @@ external ff :
240240
OUnit.assert_bool __LOC__
241241
(not (Ext_string.is_empty should_err.stderr))
242242

243-
end
243+
end;
244+
245+
(* __LOC__ >:: begin fun _ -> *)
246+
(* let should_infer = perform_bsc [| "-i"; "-bs-eval"|] {| *)
247+
(* let f = fun [@bs] x -> let (a,b) = x in a + b *)
248+
(* |} in *)
249+
(* let infer_type = bsc_eval (Printf.sprintf {| *)
250+
251+
(* let f : %s = fun [@bs] x -> let (a,b) = x in a + b *)
252+
(* |} should_infer.stdout ) in *)
253+
(* begin *)
254+
(* Ounit_cmd_util.debug_output should_infer ; *)
255+
(* Ounit_cmd_util.debug_output infer_type ; *)
256+
(* OUnit.assert_bool __LOC__ *)
257+
(* ((Ext_string.is_empty infer_type.stderr)) *)
258+
(* end *)
259+
(* end *)
244260
]
245261

jscomp/test/.depend

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ gpr_1484.cmj :
223223
gpr_1501_test.cmj : ../stdlib/printexc.cmj mt.cmj
224224
gpr_1503_test.cmj : mt.cmj ../stdlib/int64.cmj
225225
gpr_1539_test.cmj :
226+
gpr_1600_test.cmj : ../runtime/js.cmj ../stdlib/array.cmj
226227
gpr_405_test.cmj : ../stdlib/hashtbl.cmj gpr_405_test.cmi
227228
gpr_441.cmj :
228229
gpr_459_test.cmj : mt.cmj

jscomp/test/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ OTHERS := literals a test_ari test_export2 test_internalOO test_obj_simple_ffi t
154154
gpr_1539_test\
155155
webpack_config\
156156
bs_qualified\
157-
mario_game
157+
mario_game\
158+
gpr_1600_test
158159

159160

160161
# bs_uncurry_test

jscomp/test/gpr_1600_test.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
'use strict';
2+
3+
4+
var obj = {
5+
hi: function (x) {
6+
console.log(x);
7+
return /* () */0;
8+
}
9+
};
10+
11+
var eventObj = {
12+
events: /* array */[],
13+
empty: function () {
14+
return /* () */0;
15+
},
16+
push: function (a) {
17+
var self = this ;
18+
self.events[0] = a;
19+
return /* () */0;
20+
},
21+
needRebuild: function () {
22+
var self = this ;
23+
return +(self.events.length !== 0);
24+
},
25+
currentEvents: function () {
26+
var self = this ;
27+
return self.events;
28+
}
29+
};
30+
31+
function f() {
32+
return eventObj;
33+
}
34+
35+
exports.obj = obj;
36+
exports.eventObj = eventObj;
37+
exports.f = f;
38+
/* obj Not a pure module */

jscomp/test/gpr_1600_test.ml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
3+
4+
let f : (int * int -> int [@bs]) = fun [@bs] x -> let a,b = x in a + b
5+
6+
7+
let obj : < hi : (int * int -> unit [@bs.meth]) > Js.t = object
8+
method hi (x : int * int) = Js.log x
9+
end [@bs]
10+
(** expect *)
11+
12+
class type _a = object
13+
method empty : unit -> unit
14+
method currentEvents : unit -> (string * string) array
15+
method push : string * string -> unit
16+
method needRebuild : unit -> bool
17+
end [@bs]
18+
19+
type a = _a Js.t
20+
21+
let eventObj : < currentEvents : (unit -> (string * string) array [@bs.meth]);
22+
empty : (unit -> unit [@bs.meth]);
23+
needRebuild : (unit -> bool [@bs.meth]);
24+
push : (string * string -> unit [@bs.meth]) >
25+
Js.t = object (self)
26+
val events : (string * string) array = [||]
27+
method empty () = ()
28+
method push a = Array.unsafe_set self##events 0 a
29+
method needRebuild () = Array.length self##events <> 0
30+
method currentEvents () = self##events
31+
end [@bs]
32+
33+
let f () = (eventObj : a)

ocaml

Submodule ocaml updated from 2ab8b9e to 0d4716d

0 commit comments

Comments
 (0)