Skip to content

Commit e819c19

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" Diagnostic modified (@notundefined reason): Before (diagnostic): Their runtime representations differ: The expected declaration is @notundefined, but the actual declaration can hold undefined. After (diagnostic): Their runtime representations differ: Actual declaration: can hold undefined Expected declaration: @notundefined 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 e819c19

10 files changed

Lines changed: 44 additions & 37 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: 23 additions & 16 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
@@ -235,24 +245,21 @@ let report_type_mismatch0 first second decl ppf err =
235245
| Not_undefined ->
236246
pr
237247
"@[<v 2>Their runtime representations differ:@,\
238-
%s %s is @notUndefined,@,\
239-
but %s %s can hold undefined@]"
240-
(String.capitalize_ascii second)
241-
decl first decl
248+
%s: can hold undefined@,\
249+
%s: @notUndefined@]"
250+
(label first decl) (label second decl)
242251
| 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
252+
pr "@[<v 2>Their runtime representations differ:@,%s: %s@,%s: %s@]"
253+
(label first decl) declared1 (label second decl) declared2
251254

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

258265
let rec compare_constructor_arguments env cstr params1 params2 arg1 arg2 =
@@ -397,8 +404,8 @@ let compare_runtime_annotations env id decl1 decl2 =
397404
else
398405
[
399406
Runtime_annotation
400-
( Ast_untagged_variants.describe_declared_block_type declared1,
401-
Ast_untagged_variants.describe_declared_block_type declared2 );
407+
( Ast_untagged_variants.describe_declared_values declared1,
408+
Ast_untagged_variants.describe_declared_values declared2 );
402409
]
403410

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

‎tests/build_tests/super_errors/expected/not_undefined_functor_argument.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 expected declaration is @notUndefined,
22-
but the actual declaration can hold undefined.
21+
Actual declaration: can hold undefined
22+
Expected declaration: @notUndefined

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

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

2121
Their runtime representations differ:
22-
The expected declaration is @notUndefined,
23-
but the actual declaration can hold undefined.
22+
Actual declaration: can hold undefined
23+
Expected declaration: @notUndefined

‎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_not_undefined_option_implementation.expected‎

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

1919
Their runtime representations differ:
20-
The expected declaration is @notUndefined,
21-
but the actual declaration can hold undefined.
20+
Actual declaration: can hold undefined
21+
Expected declaration: @notUndefined

‎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)