Skip to content

Commit dfcce22

Browse files
committed
improve formatting
1 parent a0e1a2d commit dfcce22

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

ocaml/testsuite/tests/typing-layouts/error_message_attr.ml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ Error: This expression has type float# but an expression was expected of type
5858
The layout of float# is float64, because
5959
it is the primitive float64 type float#.
6060
But the layout of float# must be a sublayout of value, because
61-
of the annotation on the wildcard _ at line 1, characters 20-31
62-
Custom message.
61+
of the annotation on the wildcard _ at line 1, characters 20-31.
62+
Custom message
6363
|}]
6464

6565
let f x =
@@ -74,8 +74,8 @@ Error: This expression has type ('a : value)
7474
The layout of float# is float64, because
7575
it is the primitive float64 type float#.
7676
But the layout of float# must be a sublayout of value, because
77-
of the annotation on the wildcard _ at line 2, characters 15-26
78-
Custom message.
77+
of the annotation on the wildcard _ at line 2, characters 15-26.
78+
Custom message
7979
|}]
8080

8181
(* Ltyp_var { name = Some name; layout } case *)
@@ -90,8 +90,8 @@ Line 3, characters 61-63:
9090
^^
9191
Error: This type ('a : value) should be an instance of type ('b : float64)
9292
The layout of 'a is value, because
93-
of the annotation on the type variable 'a
94-
Custom message.
93+
of the annotation on the type variable 'a.
94+
Custom message
9595
But the layout of 'a must overlap with float64, because
9696
of the definition of t at line 2, characters 2-28.
9797
|}]
@@ -112,8 +112,8 @@ Error: Bad layout annotation:
112112
The layout of t is float64, because
113113
of the definition of t at line 2, characters 2-18.
114114
But the layout of t must be a sublayout of value, because
115-
of the annotation on the type variable a
116-
Custom message.
115+
of the annotation on the type variable a.
116+
Custom message
117117
|}]
118118

119119
(* Second call to [layout_of_annotation] in the Not_found case
@@ -131,8 +131,8 @@ Error: This alias is bound to type t but is used as an instance of type
131131
The layout of t is float64, because
132132
of the definition of t at line 2, characters 2-18.
133133
But the layout of t must be a sublayout of value, because
134-
of the annotation on the type variable a
135-
Custom message.
134+
of the annotation on the type variable a.
135+
Custom message
136136
|}]
137137

138138
(* Third call to [layout_of_annotation] in the None case
@@ -149,8 +149,8 @@ Error: Bad layout annotation:
149149
The layout of t/2 is float64, because
150150
of the definition of t at line 2, characters 2-18.
151151
But the layout of t/2 must be a sublayout of value, because
152-
of the annotation on the wildcard _ at line 3, characters 26-31
153-
Custom message.
152+
of the annotation on the wildcard _ at line 3, characters 26-31.
153+
Custom message
154154
|}]
155155

156156
(* Currently it's not possible to attach attributes to Ltyp_poly *)

ocaml/typing/layouts.ml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -704,9 +704,9 @@ module Layout = struct
704704
fprintf ppf "the type variable %s" name
705705
| Type_wildcard loc ->
706706
fprintf ppf "the wildcard _ at %a" Location.print_loc_in_lowercase loc
707-
| With_error_message (message, context) ->
708-
format_annotation_context ppf context;
709-
fprintf ppf "@ @[%s@]" message
707+
| With_error_message (_message, context) ->
708+
(* message gets printed in [format_flattened_history] so we ignore it here *)
709+
format_annotation_context ppf context
710710

711711
let format_any_creation_reason ppf : any_creation_reason -> unit = function
712712
| Missing_cmi p ->
@@ -868,7 +868,13 @@ module Layout = struct
868868
end
869869
| _ -> assert false
870870
end;
871-
fprintf ppf ".@]"
871+
fprintf ppf ".";
872+
begin match t.history with
873+
| Creation (Annotated (With_error_message (message, _), _)) ->
874+
fprintf ppf "@ @[%s@]" message
875+
| _ -> ()
876+
end;
877+
fprintf ppf "@]"
872878

873879

874880
(* this isn't really formatted for user consumption *)
@@ -998,7 +1004,7 @@ module Layout = struct
9981004
let equate = equate_or_equal ~allow_mutation:true
9991005

10001006
(* Not all layout history reasons are created equal. Some are more helpful than others.
1001-
This function tried to encode that information.
1007+
This function encodes that information.
10021008
10031009
The reason with higher score should get preserved when combined with one of lower
10041010
score. *)

0 commit comments

Comments
 (0)