Skip to content

Commit 400784b

Browse files
cknittclaude
andcommitted
Label the two sides when runtime representations differ
Why: "The actual declaration states values whose typeof is "object"" reads clumsily: a declaration doesn't state values. The two lines now use the labels of the declaration blocks above them, followed by what each side states. Diagnostic modified (runtime representation reason): Before (diagnostic): Their runtime representations differ: The actual declaration states values whose typeof is "object". The expected declaration states values whose typeof is "string". After (diagnostic): Their runtime representations differ: Actual declaration: typeof "object" Expected declaration: typeof "string" Mapping modified (what a declaration states, Ast_untagged_variants.describe_declared_values): Before (representation): @instanceof("Dog") ↦ instances of Dog @instanceof("Dog") of a subclass ↦ instances of Dog, a subclass of Animal arrays ↦ arrays @typeof("string") ↦ values whose typeof is "string" nothing ↦ no runtime class or typeof After (representation): @instanceof("Dog") ↦ instances of Dog @instanceof("Dog") of a subclass ↦ instances of Dog, a subclass of Animal arrays ↦ arrays @typeof("string") ↦ typeof "string" nothing ↦ no stated class or typeof Review: Where do the labels come from? From the side names the caller passes, without their article: "the actual" and "declaration" make "Actual declaration"; the type definition errors of Typedecl get "Original definition" and "This definition". Review: Why no period? The lines are labels with a value, like the declaration labels, not sentences. 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 7a1245e commit 400784b

7 files changed

Lines changed: 35 additions & 27 deletions

‎compiler/ml/ast_untagged_variants.ml‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -322,16 +322,16 @@ let runtime_annotation_to_string = function
322322
| Type_of block_type ->
323323
Printf.sprintf "@%s(\"%s\")" type_of (typeof_name block_type)
324324

325-
(* What a declaration's annotations state, for error messages *)
326-
let describe_declared_block_type = function
325+
(* What a declaration's annotations state about its values, for error
326+
messages *)
327+
let describe_declared_values = function
327328
| Some (InstanceType (Class {name; ancestors = []})) -> "instances of " ^ name
328329
| Some (InstanceType (Class {name; ancestors})) ->
329330
"instances of " ^ name ^ ", a subclass of "
330331
^ String.concat " and " ancestors
331332
| Some (InstanceType Array) -> "arrays"
332-
| Some block_type ->
333-
"values whose typeof is \"" ^ typeof_name block_type ^ "\""
334-
| None -> "no runtime class or typeof"
333+
| Some block_type -> "typeof \"" ^ typeof_name block_type ^ "\""
334+
| None -> "no stated class or typeof"
335335

336336
(* The [@notUndefined], [@instanceOf] or [@typeOf] annotation in [attrs],
337337
validated. Only [Typedecl] passes [~loc]; later readers see attributes it

‎compiler/ml/includecore.ml‎

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,16 @@ type type_mismatch =
191191
| Runtime_annotation of string * string
192192
| Not_undefined
193193

194+
(* A side of a comparison as a label: "the actual" and "declaration" make
195+
"Actual declaration" *)
196+
let label side decl =
197+
let side =
198+
match String.split_on_char ' ' side with
199+
| "the" :: rest -> String.concat " " rest
200+
| _ -> side
201+
in
202+
String.capitalize_ascii (side ^ " " ^ decl)
203+
194204
let report_type_mismatch0 first second decl ppf err =
195205
let pr fmt = Format.fprintf ppf fmt in
196206
match err with
@@ -240,19 +250,17 @@ let report_type_mismatch0 first second decl ppf err =
240250
(String.capitalize_ascii second)
241251
decl first decl
242252
| Runtime_annotation (declared1, declared2) ->
243-
pr
244-
"@[<v 2>Their runtime representations differ:@,\
245-
%s %s states %s.@,\
246-
%s %s states %s@]"
247-
(String.capitalize_ascii first)
248-
decl declared1
249-
(String.capitalize_ascii second)
250-
decl declared2
253+
pr "@[<v 2>Their runtime representations differ:@,%s: %s@,%s: %s@]"
254+
(label first decl) declared1 (label second decl) declared2
251255

252256
let report_type_mismatch first second decl ppf =
253257
List.iter (fun err ->
254-
if err = Manifest then ()
255-
else
258+
match err with
259+
| Manifest -> ()
260+
(* Its lines are labels, not sentences *)
261+
| Runtime_annotation _ ->
262+
Format.fprintf ppf "@ %a" (report_type_mismatch0 first second decl) err
263+
| _ ->
256264
Format.fprintf ppf "@ %a." (report_type_mismatch0 first second decl) err)
257265

258266
let rec compare_constructor_arguments env cstr params1 params2 arg1 arg2 =
@@ -397,8 +405,8 @@ let compare_runtime_annotations env id decl1 decl2 =
397405
else
398406
[
399407
Runtime_annotation
400-
( Ast_untagged_variants.describe_declared_block_type declared1,
401-
Ast_untagged_variants.describe_declared_block_type declared2 );
408+
( Ast_untagged_variants.describe_declared_values declared1,
409+
Ast_untagged_variants.describe_declared_values declared2 );
402410
]
403411

404412
let type_declarations ?(equality = false) ~loc env name decl1 id decl2 =

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@
1818
type t
1919

2020
Their runtime representations differ:
21-
The actual declaration states values whose typeof is "object".
22-
The expected declaration states values whose typeof is "string".
21+
Actual declaration: typeof "object"
22+
Expected declaration: typeof "string"

‎tests/build_tests/super_errors_multi/expected/Cross_runtime_annotation_claimed_by_interface.expected‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616
type t
1717

1818
Their runtime representations differ:
19-
The actual declaration states no runtime class or typeof.
20-
The expected declaration states values whose typeof is "string".
19+
Actual declaration: no stated class or typeof
20+
Expected declaration: typeof "string"

‎tests/build_tests/super_errors_multi/expected/Cross_runtime_annotation_functor_argument.expected‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
type dog
1818

1919
Their runtime representations differ:
20-
The actual declaration states instances of Dog, a subclass of Animal.
21-
The expected declaration states instances of Dog.
20+
Actual declaration: instances of Dog, a subclass of Animal
21+
Expected declaration: instances of Dog

‎tests/build_tests/super_errors_multi/expected/Cross_runtime_annotation_hidden_base.expected‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
type dog = private animal
1818

1919
Their runtime representations differ:
20-
The actual declaration states instances of Dog, a subclass of Animal.
21-
The expected declaration states instances of Dog.
20+
Actual declaration: instances of Dog, a subclass of Animal
21+
Expected declaration: instances of Dog

‎tests/build_tests/super_errors_multi/expected/Cross_runtime_annotation_hidden_superclass.expected‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
type dog
1818

1919
Their runtime representations differ:
20-
The actual declaration states instances of Dog, a subclass of Animal.
21-
The expected declaration states instances of Dog.
20+
Actual declaration: instances of Dog, a subclass of Animal
21+
Expected declaration: instances of Dog

0 commit comments

Comments
 (0)