Skip to content

Improve layout history error message: review new messages #2091

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ocaml/testsuite/tests/typing-immediate/immediate.ml
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ Line 2, characters 2-41:
2 | type t = Foo of int | Bar [@@immediate]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: The layout of type t is value, because
it's a boxed variant.
it's a boxed variant type.
But the layout of type t must be a sublayout of immediate, because
of the annotation on the declaration of the type t.
|}];;
Expand All @@ -175,7 +175,7 @@ Line 2, characters 2-38:
2 | type t = { foo : int } [@@immediate]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: The layout of type t is value, because
it's a boxed record.
it's a boxed record type.
But the layout of type t must be a sublayout of immediate, because
of the annotation on the declaration of the type t/2.
|}];;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ module = "any_missing_cmi_lib.ml"
script = "rm -f any_missing_cmi_lib2.cmi"
***** expect
*)
(* CR layouts v2.9: all error messages below here are unreviewed *)


#directory "ocamlc.byte";;
#load "any_missing_cmi_lib.cmo";;
Expand All @@ -24,8 +22,8 @@ Line 1, characters 30-44:
Error: Function arguments and returns must be representable.
The layout of Any_missing_cmi_lib2.t is any, because
the .cmi file for Any_missing_cmi_lib2.t is missing.
But the layout of Any_missing_cmi_lib2.t must be a sublayout of '_representable_layout_1, because
it's used as a function argument.
But the layout of Any_missing_cmi_lib2.t must be representable, because
it's the type of a function argument.
No .cmi file found containing Any_missing_cmi_lib2.t.
Hint: Adding "any_missing_cmi_lib2" to your dependencies might help.
|}]
36 changes: 18 additions & 18 deletions ocaml/testsuite/tests/typing-layouts-err-msg/concrete.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Error: This expression has type t_any but an expression was expected of type
('a : '_representable_layout_1)
The layout of t_any is any, because
of the definition of t_any at line 1, characters 0-16.
But the layout of t_any must be a sublayout of '_representable_layout_1, because
But the layout of t_any must be representable, because
a value of this type is matched against a pattern.
|}]

Expand All @@ -36,8 +36,8 @@ Line 1, characters 9-19:
Error: Constructor argument types must have a representable layout.
The layout of t_any is any, because
of the definition of t_any at line 1, characters 0-16.
But the layout of t_any must be a sublayout of '_representable_layout_2, because
it's used as the type of a constructor field.
But the layout of t_any must be representable, because
it's the type of a constructor field.
|}]

(* Label_declaration *)
Expand All @@ -50,7 +50,7 @@ Line 1, characters 10-18:
Error: Record element types must have a representable layout.
The layout of t_any is any, because
of the definition of t_any at line 1, characters 0-16.
But the layout of t_any must be a sublayout of '_representable_layout_3, because
But the layout of t_any must be representable, because
it is the type of record field a.
|}]

Expand All @@ -63,10 +63,10 @@ Line 2, characters 9-14:
2 | and t2 = t_any t
^^^^^
Error: This type t_any should be an instance of type
('a : '_representable_layout_4)
('a : '_representable_layout_2)
The layout of t_any is any, because
of the definition of t_any at line 1, characters 0-16.
But the layout of t_any must be a sublayout of '_representable_layout_4, because
But the layout of t_any must be representable, because
it instantiates an unannotated type parameter of t.
|}]

Expand All @@ -85,10 +85,10 @@ Line 1, characters 4-12:
^^^^^^^^
Error: This pattern matches values of type t_any
but a pattern was expected which matches values of type
('a : '_representable_layout_5)
('a : '_representable_layout_3)
The layout of t_any is any, because
of the definition of t_any at line 1, characters 0-16.
But the layout of t_any must be a sublayout of '_representable_layout_5, because
But the layout of t_any must be representable, because
it's the type of a variable bound by a `let`.
|}]

Expand All @@ -101,11 +101,11 @@ Line 1, characters 6-16:
^^^^^^^^^^
Error: This pattern matches values of type t_any
but a pattern was expected which matches values of type
('a : '_representable_layout_6)
('a : '_representable_layout_4)
The layout of t_any is any, because
of the definition of t_any at line 1, characters 0-16.
But the layout of t_any must be a sublayout of '_representable_layout_6, because
it's used as a function argument.
But the layout of t_any must be representable, because
it's the type of a function argument.
|}]

(* Function_result *)
Expand All @@ -116,11 +116,11 @@ Line 1, characters 18-30:
1 | let f (): t_any = assert false
^^^^^^^^^^^^
Error: This expression has type t_any but an expression was expected of type
('a : '_representable_layout_7)
('a : '_representable_layout_5)
The layout of t_any is any, because
of the definition of t_any at line 1, characters 0-16.
But the layout of t_any must be a sublayout of '_representable_layout_7, because
it's used as a function result.
But the layout of t_any must be representable, because
it's the type of a function result.
|}]

(* Structure_item_expression *)
Expand All @@ -138,8 +138,8 @@ Line 1, characters 14-19:
Error: Function argument types must have a representable layout.
The layout of t_any is any, because
of the definition of t_any at line 1, characters 0-16.
But the layout of t_any must be a sublayout of '_representable_layout_8, because
it's used as a function argument.
But the layout of t_any must be representable, because
it's the type of a function argument.
|}]
(* Shadowed by Function_argument *)

Expand All @@ -152,8 +152,8 @@ Line 1, characters 26-31:
Error: Function return types must have a representable layout.
The layout of t_any is any, because
of the definition of t_any at line 1, characters 0-16.
But the layout of t_any must be a sublayout of '_representable_layout_9, because
it's used as a function result.
But the layout of t_any must be representable, because
it's the type of a function result.
|}]
(* Shadowed by Function_result *)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ Error: This expression has type t_any but an expression was expected of type
('a : '_representable_layout_1)
The layout of t_any is any, because
of the definition of t_any at line 6, characters 0-16.
But the layout of t_any must be a sublayout of '_representable_layout_1, because
it's used as the type of an expression in a structure.
But the layout of t_any must be representable, because
it's the type of an expression in a structure.

4 changes: 2 additions & 2 deletions ocaml/testsuite/tests/typing-layouts-err-msg/immediate.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Line 3, characters 21-22:
Error: This expression has type v = unit
but an expression was expected of type 'a t = ('a : void)
The layout of unit is immediate, because
it's an enumeration variant (all constructors are constant).
it's an enumeration variant type (all constructors are constant).
But the layout of unit must be a sublayout of void, because
of the definition of t at line 1, characters 0-22.
|}]
Expand Down Expand Up @@ -61,7 +61,7 @@ Line 2, characters 29-30:
Error: This expression has type [ `A | `B ]
but an expression was expected of type 'a t = ('a : void)
The layout of [ `A | `B ] is immediate, because
it's an enumeration variant (all constructors are constant).
it's an enumeration variant type (all constructors are constant).
But the layout of [ `A | `B ] must be a sublayout of void, because
of the definition of t at line 1, characters 0-22.
|}]
Expand Down
71 changes: 45 additions & 26 deletions ocaml/testsuite/tests/typing-layouts-err-msg/value.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
flags = "-extension layouts_alpha"
* expect
*)
(* CR layouts v2.9: all error messages below here are not reviewed for quality *)

(***********************)
(* Value layout errors *)
Expand Down Expand Up @@ -39,7 +38,7 @@ Error: Variables bound in a class must have layout value.
The layout of v is float64, because
it's the type of a variable bound by a `let`, defaulted to layout float64.
But the layout of v must be a sublayout of value, because
it's let-bound in a class expression.
it's the type of a let-bound variable in a class expression.
|}];;
(* CR layouts v2.9: The part about defaulting here is incorrect.
It's due to the logic in Pcl_let using sorts directly instead of
Expand All @@ -55,7 +54,7 @@ Error: Tuple element types must have layout value.
The layout of t_any is any, because
of the definition of t_any at line 1, characters 0-18.
But the layout of t_any must be a sublayout of value, because
it's a tuple element.
it's the type of a tuple element.
|}];;

(* Probe *)
Expand All @@ -81,7 +80,7 @@ Error: In this `with' constraint, the new definition of t
is not included in
type t : immediate
The layout of the first is value, because
it's used as an element in a first-class module.
it's a type declaration in a first-class module.
But the layout of the first must be a sublayout of immediate, because
of the definition of t at line 2, characters 2-20.
|}];;
Expand All @@ -92,11 +91,11 @@ let f: ('a : void) -> 'b = fun x -> x # baz
Line 1, characters 36-37:
1 | let f: ('a : void) -> 'b = fun x -> x # baz
^
Error: Methods must have layout value.
The layout of this expression is void, because
Error: The object type must have layout value.
The layout of the type of this expression is void, because
of the annotation on the type variable 'a.
But the layout of this expression must overlap with value, because
it's an object.
But the layout of the type of this expression must overlap with value, because
it's the type of an object.
|}];;

(* Instance_variable *)
Expand All @@ -114,7 +113,7 @@ Error: Variables bound in a class must have layout value.
The layout of baz is void, because
of the definition of t_void at line 6, characters 0-19.
But the layout of baz must be a sublayout of value, because
it's an instance variable.
it's the type of an instance variable.
|}];;

(* Object_field *)
Expand All @@ -128,7 +127,7 @@ Error: This expression has type ('a : value)
The layout of t_void is void, because
of the definition of t_void at line 6, characters 0-19.
But the layout of t_void must be a sublayout of value, because
it's an object field.
it's the type of an object field.
|}];;

(* Class_field *)
Expand All @@ -144,7 +143,7 @@ Error: Variables bound in a class must have layout value.
The layout of bar is void, because
of the definition of t_void at line 6, characters 0-19.
But the layout of bar must be a sublayout of value, because
it's an class field.
it's the type of a class field.
|}];;

(* Boxed_record *)
Expand All @@ -154,7 +153,7 @@ Line 1, characters 0-26:
1 | type r : void = {a:string}
^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: The layout of type r is value, because
it's a boxed record.
it's a boxed record type.
But the layout of type r must be a sublayout of void, because
of the annotation on the declaration of the type r.
|}];;
Expand All @@ -166,7 +165,7 @@ Line 1, characters 0-28:
1 | type v : void = A of t_value
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: The layout of type v is value, because
it's a boxed variant.
it's a boxed variant type.
But the layout of type v must be a sublayout of void, because
of the annotation on the declaration of the type v.
|}];;
Expand All @@ -178,7 +177,7 @@ Line 1, characters 0-21:
1 | type attr : void = ..
^^^^^^^^^^^^^^^^^^^^^
Error: The layout of type attr is value, because
it's an extensible variant.
it's an extensible variant type.
But the layout of type attr must be a sublayout of void, because
of the annotation on the declaration of the type attr.
|}]
Expand Down Expand Up @@ -239,7 +238,7 @@ Line 2, characters 36-37:
Error: This expression has type [ `A of int | `B ]
but an expression was expected of type 'a t = ('a : void)
The layout of [ `A of int | `B ] is value, because
it's a polymorphic variant.
it's a polymorphic variant type.
But the layout of [ `A of int | `B ] must be a sublayout of void, because
of the definition of t at line 1, characters 0-22.
|}]
Expand Down Expand Up @@ -300,7 +299,7 @@ Error: This expression has type ('a : value)
The layout of 'b is void, because
of the annotation on the type variable 'b.
But the layout of 'b must overlap with value, because
it's an unannotated universal variable.
it is or unifies with an unannotated universal variable.
|}];;

(* Polymorphic_variant_field *)
Expand All @@ -314,7 +313,7 @@ Error: This expression has type t_float64
The layout of t_float64 is float64, because
of the definition of t_float64 at line 5, characters 0-24.
But the layout of t_float64 must be a sublayout of value, because
it's a field of a polymorphic variant.
it's the type of the field of a polymorphic variant.
|}];;

(* Default_type_layout *)
Expand Down Expand Up @@ -348,7 +347,7 @@ Error: This expression has type t_float64
The layout of t_float64 is float64, because
of the definition of t_float64 at line 5, characters 0-24.
But the layout of t_float64 must be a sublayout of value, because
it's an array element.
it's the type of an array element.
|}];;

(* Lazy_expression *)
Expand All @@ -362,10 +361,30 @@ Error: This expression has type t_float64
The layout of t_float64 is float64, because
of the definition of t_float64 at line 5, characters 0-24.
But the layout of t_float64 must be a sublayout of value, because
it's a lazy expression.
it's the type of a lazy expression.
|}];;

(* Class_argument *)
(* Class_type_argument *)
module M = struct
type ('a : void) t

class virtual ['a] foo =
object
val virtual baz : 'a t
end
end
[%%expect{|
Line 6, characters 24-26:
6 | val virtual baz : 'a t
^^
Error: This type ('a : void) should be an instance of type ('a0 : value)
The layout of 'a is value, because
it's a type argument to a class constructor.
But the layout of 'a must overlap with void, because
of the definition of t at line 2, characters 2-20.
|}];;

(* Class_term_argument *)
class foo (x : t_float64) =
object end;;
[%%expect{|
Expand All @@ -377,7 +396,7 @@ Error: This pattern matches values of type t_float64
The layout of t_float64 is float64, because
of the definition of t_float64 at line 5, characters 0-24.
But the layout of t_float64 must be a sublayout of value, because
it's a term-level argument to a class constructor.
it's the type of a term-level argument to a class constructor.
|}];;

(* Structure_element *)
Expand All @@ -386,11 +405,11 @@ module type S = sig val x : t_void end
Line 1, characters 28-34:
1 | module type S = sig val x : t_void end
^^^^^^
Error: This type signature for x is not a value type.
The layout of x is void, because
Error: This type for x is not a value type.
The layout of type t_void is void, because
of the definition of t_void at line 6, characters 0-19.
But the layout of x must be a sublayout of value, because
it's stored in a module structure.
But the layout of type t_void must be a sublayout of value, because
it's the type of something stored in a module structure.
|}];;

(* Debug_printer_argument *)
Expand Down Expand Up @@ -424,7 +443,7 @@ Error: m1 must have a type of layout value because it is captured by an object.
The layout of t_float64 is float64, because
of the definition of t_float64 at line 5, characters 0-24.
But the layout of t_float64 must be a sublayout of value, because
it's captured in an object.
it's the type of a variable captured in an object.
|}];;

(* Unknown *)
Expand Down
Loading