Repository navigation
Commit 98ff97a
Match fields and constructors by name in signature mismatch errors
Why:
The inclusion check compared the fields of two records and the
constructors of two variants by position and reported only the first
difference. A field missing in the middle, two swapped fields or a
constructor added at the front all read as "Fields number N have
different names", and the other differences stayed hidden. Upstream
OCaml 4.13 lines the declarations up with an edit distance (#9130);
names are unique within a declaration, so lining them up by name is
enough here.
Includecore.align lines the two lists up by name. Declarations with the same
names in the same order, as nearly all are, are paired directly. Otherwise a
name in only one declaration is missing or extra, one name lacking on each
side after the same common entry is a renaming (paired in order when that gap
holds as many on each side), and common names in another order are reported
once, in the expected order. Each entry in both is compared on its own, at its
own position in each variant layout, so every difference is reported. The
differences of an inline record are grouped under its constructor.
The declarations are printed as before; the blocks below show the reasons
under them.
Diagnostic modified (field missing in the middle):
Example:
module M: {
type t = {name: string, age: int, email: string}
} = {
type t = {name: string, email: string}
}
Before (diagnostic):
Fields number 2 have different names, email and age.
After (diagnostic):
The field age is only present in the expected declaration.
Diagnostic modified (fields in another order):
Example:
module M: {
type t = {a: int, b: int, c: int, d: int}
} = {
type t = {c: int, a: int, b: int, e: int}
}
Before (diagnostic):
Fields number 1 have different names, c and a.
After (diagnostic):
The field d is only present in the expected declaration.
The field e is only present in the actual declaration.
The fields are in another order in the expected declaration:
a, b, c.
Diagnostic modified (several differing fields):
Example:
module M: {
type t = {id: int, mutable name: string, age: int, @as("e-mail") email?: string}
} = {
type t = {id: string, name: string, age: float, email: string}
}
Before (diagnostic):
The mutability of field name is different.
After (diagnostic):
The types for field id are not equal.
The mutability of field name is different.
The types for field age are not equal.
The optional attribute of field email is different.
The field email has the runtime name "email" in the actual declaration,
but "e-mail" in the expected declaration.
Diagnostic modified (constructor added and renamed):
Example:
module M: {
type t = Red | Green | Blue | Gray
} = {
type t = Black | Red | Green | Blue | Grey
}
Before (diagnostic):
Constructors number 1 have different names, Black and Red.
After (diagnostic):
The constructor Grey is named Gray in the expected declaration.
The constructor Black is only present in the actual declaration.
Diagnostic modified (inline record of a constructor):
Example:
module M: {
type t = Person({name: string, age: int}) | Anonymous
} = {
type t = Person({age: int, name: string, nick: string}) | Anonymous
}
Before (diagnostic):
Fields number 0 have different names, age and name.
After (diagnostic):
The records of constructor Person differ:
The field nick is only present in the actual declaration.
The fields are in another order in the expected declaration:
name, age.
Review: Does the check accept anything it rejected before, or the other way round? No. A declaration passes only when every name is in both, in the same order, with no difference per entry, which is what the positional walk required; only the messages change.
Review: Why is the type of an optional field not reported when only its optional attribute differs? The type of an optional field is an option of the declared type, so it differs whenever the attribute does; the attribute message already says so.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gLpf7RN1MiRcubPgRn
Signed-off-by: Christoph Knittel <ck@cca.io>1 parent 6176c4d commit 98ff97a
21 files changed
Lines changed: 456 additions & 113 deletions
File tree
- changes
- compiler/ml
- tests/build_tests
- super_errors_multi/expected
- super_errors
- expected
- fixtures
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
| 34 | + | |
| 35 | + | |
35 | 36 | | |
| 37 | + | |
36 | 38 | | |
37 | 39 | | |
38 | | - | |
| 40 | + | |
39 | 41 | | |
| 42 | + | |
| 43 | + | |
40 | 44 | | |
41 | 45 | | |
42 | 46 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
| 21 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
0 commit comments