Skip to content

Commit

Permalink
Merge pull request #10361 from Octachron/semdiff_type_decl
Browse files Browse the repository at this point in the history
Diffing for mismatches in variant and record declarations
  • Loading branch information
gasche committed Jun 25, 2021
2 parents 650ba02 + fb81f86 commit e390e64
Show file tree
Hide file tree
Showing 18 changed files with 1,648 additions and 459 deletions.
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 @@ -695,6 +708,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 @@ -711,6 +725,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 @@ -724,7 +739,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
4 changes: 4 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ Working version
- #10328: Give more precise error when disambiguation could not possibly work.
(Leo White, review by Gabriel Scherer and Florian Angeletti)

- #10361: Improve error messages for mismatched record and variant
definitions.
(Florian Angeletti, review by Gabriel Radanne and Gabriel Scherer)

- #10407: Produce more detailed error messages that contain full error traces
when module inclusion fails.
(Antal Spector-Zabusky, review by Florian Angeletti)
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

0 comments on commit e390e64

Please sign in to comment.