Skip to content

Commit

Permalink
Print type declaration, and thus inferred layout, in more cases
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Roberts <[email protected]>
  • Loading branch information
ncik-roberts committed Dec 1, 2023
1 parent e3d77bd commit e759551
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
12 changes: 7 additions & 5 deletions src/analysis/type_utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,15 @@ let print_type_with_decl ~verbosity env ppf typ =
Env.with_cmis @@ fun () ->
Env.find_type path env
in
let is_abstract = Btype.type_kind_is_abstract decl in
(* Print expression only if it is parameterized or abstract *)
let print_expr = is_abstract || params <> [] in
(* Print expression in addition to the type declaration
only if it is parameterized. *)
let print_expr = params <> [] in
if print_expr then
Printtyp.type_scheme env ppf typ;
(* If not abstract, also print the declaration *)
if not is_abstract then
(* Jane Street only: print the declaration even if it's
abstract, because this gives us a place to print
the inferred layout annotation.
*)
begin
(* Separator if expression was printed *)
if print_expr then
Expand Down
10 changes: 5 additions & 5 deletions tests/test-dirs/type-enclosing/jane-street.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ to print everything on one line.
let f0 (x : t0) = x
^
With verbosity 0: "t0"
With verbosity 1: "int"
With verbosity 1: "type t0 = int"

let f1 (x : t1) = x
^
With verbosity 0: "t1"
With verbosity 1: "int"
With verbosity 1: "type t1 = int"

let f2 (x : t2) = x
^
Expand Down Expand Up @@ -191,17 +191,17 @@ to print everything on one line.
let poly1 (type a) (x : a) = x
^
With verbosity 0: "a"
With verbosity 1: "a"
With verbosity 1: "type a"

let poly2 (type a : value) (x : a) = x
^
With verbosity 0: "a"
With verbosity 1: "a"
With verbosity 1: "type a"

let poly3 (type a : float64) (x : a) = x
^
With verbosity 0: "a"
With verbosity 1: "a"
With verbosity 1: "type a"

let poly4 (type (a : immediate) (b : value)) (f : a -> b -> _) = f
^
Expand Down
4 changes: 2 additions & 2 deletions tests/test-dirs/type-enclosing/variants.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"line": 4,
"col": 5
},
"type": "[ `A | `B | `C ]",
"type": "type more = [ `A | `B | `C ]",
"tail": "no"
}
]
Expand Down Expand Up @@ -195,7 +195,7 @@ FIXME: Not satisfying, expected core not more
"line": 9,
"col": 7
},
"type": "[ `A | `B | `C ]",
"type": "type more = [ `A | `B | `C ]",
"tail": "no"
},
{
Expand Down

0 comments on commit e759551

Please sign in to comment.