Repository navigation
Commit f1f3d46
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.
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.
Diagnostic modified (sides of a signature mismatch):
Before (diagnostic):
the second declaration is @notundefined,
but the first declaration can hold undefined.
After (diagnostic):
the expected declaration is @notundefined,
but the actual declaration can hold undefined.
Matching modified (lining up two declarations, Includecore.align):
Before (text):
entry i of the actual declaration against entry i of the expected one,
stopping at the first difference
After (text):
same names in the same order → each pair, no tables
a name in both → compared, at its own position in each layout
a name in one only → missing or extra
one name lacking on each side
after the same common entry → renamed (paired in order when the
gap holds as many on each side)
common names in another order → the expected order, once
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 "actual" and "expected"? The error already shows the two locations as "Actual declaration" and "Expected declaration"; the sentences now use the same words instead of "first" and "second". Type re-exports and extensions keep their own words ("the original definition", "this definition").
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 9d25b40 commit f1f3d46
35 files changed
Lines changed: 509 additions & 137 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 | |
|---|---|---|---|
| |||
556 | 556 | | |
557 | 557 | | |
558 | 558 | | |
559 | | - | |
| 559 | + | |
| 560 | + | |
560 | 561 | | |
561 | 562 | | |
562 | 563 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
| 30 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
| 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 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 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 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 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 | + | |
0 commit comments