Skip to content

Commit f371c72

Browse files
cknittclaude
andauthored
Print private in type declarations of error messages (#8999)
Why: The outcome printer dropped `private` from abbreviations, variants and manifests, so a privacy mismatch read "type t = int is not included in type t = int", and a mismatch against `type t = private a` showed a public alias (#8996). `private` is printed after the `=` of an abbreviation or a variant, and after the manifest of a re-exported variant, as records and open types already did. Diagnostic modified (privacy mismatch): Example: // Foo.resi type t = int // Foo.res type t = private int Before (diagnostic): Type declarations do not match: type t = int is not included in type t = int After (diagnostic): Type declarations do not match: type t = private int is not included in type t = int Diagnostic modified (a re-exported private variant): Example: // Priv.resi type v = A | B type w = v = private A | B // Priv.res type v = A | B type w = A | B Before (diagnostic): is not included in type w = v = A | B After (diagnostic): is not included in type w = v = private A | B Fixes: #8996 Claude-Session: https://claude.ai/code/session_01CMkrYaktctdKc4M41WF36t Signed-off-by: Christoph Knittel <ck@cca.io> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent c9a267c commit f371c72

10 files changed

Lines changed: 64 additions & 6 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Print `private` for abbreviations and variants in type mismatch errors and other printed type declarations.

‎compiler/syntax/src/res_outcome_printer.ml‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,16 @@ let rec print_out_sig_item_doc ?(print_name_as_is = false)
694694
private_doc;
695695
print_record_declaration_doc ~inline:false record;
696696
]
697-
| typ -> Doc.concat [Doc.text " = "; print_out_type_doc typ]
697+
| Otyp_manifest (manifest, typ) ->
698+
Doc.concat
699+
[
700+
Doc.text " = ";
701+
print_out_type_doc manifest;
702+
Doc.text " = ";
703+
private_doc;
704+
print_out_type_doc typ;
705+
]
706+
| typ -> Doc.concat [Doc.text " = "; private_doc; print_out_type_doc typ]
698707
in
699708
let constraints =
700709
match out_type_decl.otype_cstrs with

‎tests/build_tests/super_errors/expected/object_private_row_grants_set.res.expected‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212
Signature mismatch:
1313
Modules do not match:
1414
{
15-
type t = {.."x": int}
15+
type t = private {.."x": int}
1616
}
1717
is not included in
1818
{
19-
type t = {..@set "x": int}
19+
type t = private {..@set "x": int}
2020
}
2121
Type declarations do not match:
22-
type t = {.."x": int}
22+
type t = private {.."x": int}
2323
is not included in
24-
type t = {..@set "x": int}
24+
type t = private {..@set "x": int}
2525
/.../fixtures/object_private_row_grants_set.res:6:3-36:
2626
Expected declaration
2727
/.../fixtures/object_private_row_grants_set.res:8:3-31:
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
===== Priv.res =====
2+
3+
We've found a bug for you!
4+
/.../fixtures/Cross_private_abbreviation_mismatch/Priv.res:3:1-10
5+
6+
1 │ type a
7+
2 │ type b
8+
3 │ type t = b
9+
4 │
10+
11+
The implementation /.../fixtures/Cross_private_abbreviation_mismatch/Priv.res
12+
does not match the interface /.../fixtures/Cross_private_abbreviation_mismatch/priv.cmi:
13+
Type declarations do not match:
14+
type t = b
15+
is not included in
16+
type t = private a
17+
/.../fixtures/Cross_private_abbreviation_mismatch/Priv.resi:2:1-18:
18+
Expected declaration
19+
/.../fixtures/Cross_private_abbreviation_mismatch/Priv.res:3:1-10:
20+
Actual declaration
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
===== Priv.res =====
2+
3+
We've found a bug for you!
4+
/.../fixtures/Cross_private_variant_manifest_mismatch/Priv.res:2:1-14
5+
6+
1 │ type v = A | B
7+
2 │ type w = A | B
8+
3 │
9+
10+
The implementation /.../fixtures/Cross_private_variant_manifest_mismatch/Priv.res
11+
does not match the interface /.../fixtures/Cross_private_variant_manifest_mismatch/priv.cmi:
12+
Type declarations do not match:
13+
type w = A | B
14+
is not included in
15+
type w = v = private A | B
16+
/.../fixtures/Cross_private_variant_manifest_mismatch/Priv.resi:2:1-26:
17+
Expected declaration
18+
/.../fixtures/Cross_private_variant_manifest_mismatch/Priv.res:2:1-14:
19+
Actual declaration

‎tests/build_tests/super_errors_multi/expected/Iface_privacy_mismatch.expected‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
The implementation /.../fixtures/Iface_privacy_mismatch/Foo.res
1010
does not match the interface /.../fixtures/Iface_privacy_mismatch/foo.cmi:
1111
Type declarations do not match:
12-
type t = int
12+
type t = private int
1313
is not included in
1414
type t = int
1515
/.../fixtures/Iface_privacy_mismatch/Foo.resi:1:1-12:
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
type a
2+
type b
3+
type t = b
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
type a
2+
type t = private a
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
type v = A | B
2+
type w = A | B
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
type v = A | B
2+
type w = v = private A | B

0 commit comments

Comments
 (0)