forked from ocaml-ppx/ppxlib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ocaml-ppx#299 from NathanReb/fix-type-is-rec
Fix `type_is_recursive` and `really_recursive`
- Loading branch information
Showing
5 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
(rule | ||
(alias runtest) | ||
(enabled_if | ||
(>= %{ocaml_version} "4.10.0")) | ||
(deps | ||
(:test test.ml) | ||
(package ppxlib)) | ||
(action | ||
(chdir | ||
%{project_root} | ||
(progn | ||
(run expect-test %{test}) | ||
(diff? %{test} %{test}.corrected))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
open Ppxlib | ||
|
||
let test_is_recursive stri = | ||
match stri.pstr_desc with | ||
| Pstr_type (rf, tds) -> really_recursive rf tds | ||
| _ -> assert false | ||
|
||
[%%expect{| | ||
val test_is_recursive : structure_item -> rec_flag = <fun> | ||
|}] | ||
|
||
let loc = Location.none | ||
|
||
[%%expect{| | ||
val loc : location = | ||
{Ppxlib.Location.loc_start = | ||
{Lexing.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; pos_cnum = -1}; | ||
loc_end = | ||
{Lexing.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; pos_cnum = -1}; | ||
loc_ghost = true} | ||
|}] | ||
|
||
(* Should be Nonrecursive *) | ||
let base_type = test_is_recursive [%stri type t = int] | ||
|
||
[%%expect{| | ||
val base_type : rec_flag = Ppxlib__.Import.Nonrecursive | ||
|}] | ||
|
||
(* Should be Nonrecursive *) | ||
let looks_recursive_but_is_not = test_is_recursive [%stri type nonrec t = t] | ||
|
||
[%%expect{| | ||
val looks_recursive_but_is_not : rec_flag = Ppxlib__.Import.Nonrecursive | ||
|}] | ||
|
||
(* Should be Nonrecursive *) | ||
let variant_non_rec = test_is_recursive [%stri type t = A of int | B of string] | ||
|
||
[%%expect{| | ||
val variant_non_rec : rec_flag = Ppxlib__.Import.Nonrecursive | ||
|}] | ||
|
||
(* Should be Nonrecursive *) | ||
let record_non_rec = test_is_recursive [%stri type t = {a: int; b: string}] | ||
|
||
[%%expect{| | ||
val record_non_rec : rec_flag = Ppxlib__.Import.Nonrecursive | ||
|}] | ||
|
||
(* Should be Recursive *) | ||
let actually_recursive = test_is_recursive [%stri type t = A of int | T of t] | ||
|
||
[%%expect{| | ||
val actually_recursive : rec_flag = Ppxlib__.Import.Recursive | ||
|}] | ||
|
||
(* Should be Nonrecursive *) | ||
let ignore_attributes = test_is_recursive [%stri type t = int [@attr: t]] | ||
|
||
[%%expect{| | ||
val ignore_attributes : rec_flag = Ppxlib__.Import.Nonrecursive | ||
|}] | ||
|
||
(* Should be Recursive | ||
This is subject to debate. @ceastlund's intuition is that we should | ||
traverse extensions so we'll stick to this for now. | ||
It's less of a problem as it is likely that when [really_recursive] is called | ||
those will have been expanded anyway. *) | ||
let extension_points = test_is_recursive [%stri type t = [%ext: t]] | ||
|
||
[%%expect{| | ||
val extension_points : rec_flag = Ppxlib__.Import.Recursive | ||
|}] |