Skip to content

Commit 4412f8e

Browse files
author
Hongbo Zhang
committed
improve error message
1 parent f4b7e5f commit 4412f8e

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

jscomp/syntax/ast_util.ml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -416,12 +416,10 @@ let ocaml_obj_as_js_object
416416
Cfk_concrete
417417
(Fresh, e))
418418
->
419-
begin match e with
420-
| {
421-
pexp_desc =
422-
Pexp_poly
423-
(({pexp_desc = Pexp_fun ("", None, pat, e)} as f),
424-
None)} ->
419+
begin match e.pexp_desc with
420+
| Pexp_poly
421+
(({pexp_desc = Pexp_fun ("", None, pat, e)} as f),
422+
None) ->
425423
let arity = Ast_pat.arity_of_fun pat e in
426424
let method_type, label_type =
427425
generate_callback_method_pair x.pcf_loc mapper label.txt arity in
@@ -433,9 +431,18 @@ let ocaml_obj_as_js_object
433431
let f = Ast_pat.is_unit_cont pat ~yes:e ~no:f in
434432
to_method_callback loc mapper self_pat f
435433
} :: exprs)
434+
| Pexp_poly( _, Some _)
435+
->
436+
Location.raise_errorf ~loc:x.pcf_loc
437+
"polymorphic type annotation not supported yet"
438+
439+
| Pexp_poly (_, None) ->
440+
Location.raise_errorf
441+
~loc:x.pcf_loc
442+
"Unsupported syntax, expect syntax like `method x () = x ` "
436443
| _ ->
437444
Location.raise_errorf ~loc:x.pcf_loc
438-
"polymorphic type annotation not supported"
445+
"Unsupported syntax in js object"
439446
end
440447
| Pcf_method (_, _, Cfk_concrete(Override, _) ) ->
441448
Location.raise_errorf ~loc:x.pcf_loc

jscomp/test/ppx_this_obj_test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,12 @@ var collection = /* array */[
9090
v4
9191
];
9292

93-
eq('File "ppx_this_obj_test.ml", line 55, characters 5-12', /* tuple */[
93+
eq('File "ppx_this_obj_test.ml", line 59, characters 5-12', /* tuple */[
9494
11,
9595
v.hi(3, 2)
9696
]);
9797

98-
eq('File "ppx_this_obj_test.ml", line 56, characters 5-12', /* tuple */[
98+
eq('File "ppx_this_obj_test.ml", line 60, characters 5-12', /* tuple */[
9999
11,
100100
v2.hi(3, 2)
101101
]);

jscomp/test/ppx_this_obj_test.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ let v4 =
4747
method x () = 1.
4848
end [@bs]
4949

50-
50+
(* let v5 = *)
51+
(* object *)
52+
(* method x = x *)
53+
(* end [@bs] *)
54+
5155
(** guarantee they have the same type *)
5256
let collection = [| v ; v2 ; v3 ; v4 |]
5357

0 commit comments

Comments
 (0)