Skip to content
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

Diffing for mismatches in variant and record declarations #10361

Merged
merged 10 commits into from
Jun 25, 2021
Merged
20 changes: 18 additions & 2 deletions .depend
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,23 @@ utils/consistbl.cmx : \
utils/consistbl.cmi : \
utils/misc.cmi
utils/diffing.cmo : \
utils/misc.cmi \
utils/diffing.cmi
utils/diffing.cmx : \
utils/misc.cmx \
utils/diffing.cmi
utils/diffing.cmi : \
utils/misc.cmi
utils/diffing_with_keys.cmo : \
utils/misc.cmi \
utils/diffing.cmi \
utils/diffing_with_keys.cmi
utils/diffing_with_keys.cmx : \
utils/misc.cmx \
utils/diffing.cmx \
utils/diffing_with_keys.cmi
utils/diffing_with_keys.cmi : \
utils/diffing.cmi
utils/diffing.cmi :
utils/domainstate.cmo : \
utils/domainstate.cmi
utils/domainstate.cmx : \
Expand Down Expand Up @@ -694,6 +707,7 @@ typing/includecore.cmo : \
typing/ident.cmi \
typing/errortrace.cmi \
typing/env.cmi \
utils/diffing_with_keys.cmi \
typing/ctype.cmi \
parsing/builtin_attributes.cmi \
typing/btype.cmi \
Expand All @@ -710,6 +724,7 @@ typing/includecore.cmx : \
typing/ident.cmx \
typing/errortrace.cmx \
typing/env.cmx \
utils/diffing_with_keys.cmx \
typing/ctype.cmx \
parsing/builtin_attributes.cmx \
typing/btype.cmx \
Expand All @@ -723,7 +738,8 @@ typing/includecore.cmi : \
parsing/location.cmi \
typing/ident.cmi \
typing/errortrace.cmi \
typing/env.cmi
typing/env.cmi \
utils/diffing_with_keys.cmi
typing/includemod.cmo : \
typing/types.cmi \
typing/typedtree.cmi \
Expand Down
5 changes: 5 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,11 @@ OCaml 4.13.0
- #10232: Warning for unused record fields.
(Leo White, review by Florian Angeletti)

- #?????: Improve error messages for mismatched record and variant
definitions.
(Florian Angeletti, review by ???)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs an update.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated the entry along with the pending record change.



### Internal/compiler-libs changes:

- #9243, simplify parser rules for array indexing operations
Expand Down
3 changes: 2 additions & 1 deletion compilerlibs/Makefile.compilerlibs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ UTILS = \
utils/domainstate.cmo \
utils/binutils.cmo \
utils/lazy_backtrack.cmo \
utils/diffing.cmo
utils/diffing.cmo \
utils/diffing_with_keys.cmo
UTILS_CMI =

PARSING = \
Expand Down
2 changes: 1 addition & 1 deletion dune
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
config build_path_prefix_map misc identifiable numbers arg_helper clflags
profile terminfo ccomp warnings consistbl strongly_connected_components
targetint load_path int_replace_polymorphic_compare binutils local_store
lazy_backtrack diffing
lazy_backtrack diffing diffing_with_keys

;; PARSING
location longident docstrings syntaxerr ast_helper camlinternalMenhirLib
Expand Down
7 changes: 4 additions & 3 deletions testsuite/tests/typing-misc/records.ml
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ Line 1, characters 0-28:
1 | type missing = d = { x:int }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: This variant or record definition does not match that of type d
The field y is only present in the original definition.
An extra field, y, is provided in the original definition.
|}]

type wrong_type = d = {x:float}
Expand All @@ -241,11 +241,12 @@ Line 1, characters 0-31:
1 | type wrong_type = d = {x:float}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: This variant or record definition does not match that of type d
Fields do not match:
1. Fields do not match:
x : int;
is not the same as:
x : float;
The type int is not equal to the type float
2. An extra field, y, is provided in the original definition.
|}]

type mono = {foo:int}
Expand All @@ -266,5 +267,5 @@ Line 1, characters 0-30:
1 | type perm = d = {y:int; x:int}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: This variant or record definition does not match that of type d
Fields number 1 have different names, x and y.
Fields x and y have been swapped.
|}]
7 changes: 4 additions & 3 deletions testsuite/tests/typing-misc/variant.ml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Line 3, characters 0-27:
3 | type missing = d = X of int
^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: This variant or record definition does not match that of type d
The constructor Y is only present in the original definition.
An extra constructor, Y, is provided in the original definition.
|}]

type wrong_type = d = X of float
Expand All @@ -98,11 +98,12 @@ Line 1, characters 0-32:
1 | type wrong_type = d = X of float
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: This variant or record definition does not match that of type d
Constructors do not match:
1. Constructors do not match:
X of int
is not the same as:
X of float
The type int is not equal to the type float
2. An extra constructor, Y, is provided in the original definition.
|}]

type mono = Foo of float
Expand All @@ -123,7 +124,7 @@ Line 1, characters 0-35:
1 | type perm = d = Y of int | X of int
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: This variant or record definition does not match that of type d
Constructors number 1 have different names, X and Y.
Constructors X and Y have been swapped.
|}]

module M : sig
Expand Down
7 changes: 6 additions & 1 deletion testsuite/tests/typing-modules/module_type_substitution.ml
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,16 @@ Error: In this `with' constraint, the new definition of t
type t = X of x | Y of y
is not included in
type t = X of int | Y of float
Constructors do not match:
1. Constructors do not match:
X of x
is not the same as:
X of int
The type x is not equal to the type int
2. Constructors do not match:
Y of y
is not the same as:
Y of float
The type y is not equal to the type float
|}]

(** First class module types require an identity *)
Expand Down