Skip to content

Commit

Permalink
Fix Ppxlib.really_recursive and type_is_recursive
Browse files Browse the repository at this point in the history
Those used to recurse into attributes, sometimes falsly returning
`Recursive`.

Signed-off-by: Nathan Rebours <nathan.p.rebours@gmail.com>
  • Loading branch information
NathanReb committed Nov 5, 2021
1 parent f0aeb0c commit 7f04dd6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ unreleased

- Improve error messages in ppx raised exceptions (#292, @panglesd)

- Fix a bug in `type_is_recursive` and `really_recursive` where they would
consider a type declaration recursive if the type appeared inside an attribute
payload (#299, @NathanReb)

0.23.0 (31/08/2021)
-------------------

Expand Down
3 changes: 3 additions & 0 deletions src/common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ class type_is_recursive rec_flag tds =
| Pcstr_tuple args -> List.iter args ~f:self#core_type
| Pcstr_record fields -> List.iter fields ~f:self#label_declaration

method! attributes _ = (* Don't recurse through attributes *)
()

method go () =
match rec_flag with
| Nonrecursive -> Nonrecursive
Expand Down
2 changes: 1 addition & 1 deletion test/type_is_recursive/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ val actually_recursive : rec_flag = Ppxlib__.Import.Recursive
let ignore_attributes = test_is_recursive [%stri type t = int [@attr: t]]

[%%expect{|
val ignore_attributes : rec_flag = Ppxlib__.Import.Recursive
val ignore_attributes : rec_flag = Ppxlib__.Import.Nonrecursive
|}]

(* Should be Recursive
Expand Down

0 comments on commit 7f04dd6

Please sign in to comment.