Skip to content

Commit 4af172a

Browse files
committed
Better error location reporting for unsupported elements in ppx
1 parent b09b84a commit 4af172a

3 files changed

Lines changed: 25 additions & 18 deletions

File tree

Changelog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ Changes marked with '*' indicates a changes that breaks backward compatibility
99
- [ ] Add namespaces to attributes
1010
- [ ] Unify xmlm and xml_light driver to share codebase
1111

12+
## Unreleased
13+
- [x] Improve PPX diagnostics for unsupported type-parameter shapes by raising location-aware errors.
14+
1215
## 5.2.3
1316
- [x] Compatibility against ppxlib 0.36.0
1417

ppx/ppx_protocol_conv.ml

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -580,17 +580,28 @@ let name_of_core_type ~prefix = function
580580
{ loc = ptyp_loc; txt = sprintf "__param_%s_%s" prefix var }
581581
| { ptyp_desc = Ptyp_any; ptyp_loc; _ } ->
582582
raise_errorf ~loc:ptyp_loc "Generalized algebraic datatypes not supported"
583-
| { ptyp_desc = Ptyp_arrow (_, _, _); _} -> failwith "Ptyp_arrow "
584-
| { ptyp_desc = Ptyp_tuple _; _} -> failwith "Ptyp_tuple "
585-
| { ptyp_desc = Ptyp_constr (_, _); _} -> failwith "Ptyp_constr "
586-
| { ptyp_desc = Ptyp_object (_, _); _} -> failwith "Ptyp_object "
587-
| { ptyp_desc = Ptyp_class (_, _); _} -> failwith "Ptyp_class "
588-
| { ptyp_desc = Ptyp_alias (_, _); _} -> failwith "Ptyp_alias "
589-
| { ptyp_desc = Ptyp_variant (_, _, _); _} -> failwith "Ptyp_variant "
590-
| { ptyp_desc = Ptyp_poly (_, _); _} -> failwith "Ptyp_poly "
591-
| { ptyp_desc = Ptyp_package _; _} -> failwith "Ptyp_package "
592-
| { ptyp_desc = Ptyp_extension _; _} -> failwith "Ptyp_extension "
593-
| { ptyp_desc = Ptyp_open _; _} -> failwith "Ptyp_open "
583+
| { ptyp_desc = Ptyp_arrow (_, _, _); ptyp_loc; _} ->
584+
raise_errorf ~loc:ptyp_loc "Function types are not supported as type parameters"
585+
| { ptyp_desc = Ptyp_tuple _; ptyp_loc; _} ->
586+
raise_errorf ~loc:ptyp_loc "Tuple types are not supported as type parameters"
587+
| { ptyp_desc = Ptyp_constr (_, _); ptyp_loc; _} ->
588+
raise_errorf ~loc:ptyp_loc "Constructed types are not supported as type parameters"
589+
| { ptyp_desc = Ptyp_object (_, _); ptyp_loc; _} ->
590+
raise_errorf ~loc:ptyp_loc "Object types are not supported as type parameters"
591+
| { ptyp_desc = Ptyp_class (_, _); ptyp_loc; _} ->
592+
raise_errorf ~loc:ptyp_loc "Class types are not supported as type parameters"
593+
| { ptyp_desc = Ptyp_alias (_, _); ptyp_loc; _} ->
594+
raise_errorf ~loc:ptyp_loc "Aliased types are not supported as type parameters"
595+
| { ptyp_desc = Ptyp_variant (_, _, _); ptyp_loc; _} ->
596+
raise_errorf ~loc:ptyp_loc "Polymorphic variants are not supported as type parameters"
597+
| { ptyp_desc = Ptyp_poly (_, _); ptyp_loc; _} ->
598+
raise_errorf ~loc:ptyp_loc "Polymorphic types are not supported as type parameters"
599+
| { ptyp_desc = Ptyp_package _; ptyp_loc; _} ->
600+
raise_errorf ~loc:ptyp_loc "First-class module package types are not supported as type parameters"
601+
| { ptyp_desc = Ptyp_extension _; ptyp_loc; _} ->
602+
raise_errorf ~loc:ptyp_loc "Extension types are not supported as type parameters"
603+
| { ptyp_desc = Ptyp_open _; ptyp_loc; _} ->
604+
raise_errorf ~loc:ptyp_loc "Open types are not supported as type parameters"
594605

595606

596607
let rec is_recursive_ct types = function

runtime/runtime.ml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,6 @@ module Helper = struct
157157
in
158158
count_map ~f l 0
159159

160-
let () =
161-
let l = [1;2;3;4;5] in
162-
let l' = list_map ~f:(fun x -> x + 2) l in
163-
let l'' = List.map ~f:(fun x -> x + 2) l in
164-
assert (l' = l'');
165-
166-
167160
(** Excpetion raised if the type could not be serialized *)
168161
exception Protocol_error of string
169162

0 commit comments

Comments
 (0)