Skip to content

Commit f29ecf7

Browse files
cknittclaude
andcommitted
Say what a declaration's values are when runtime representations differ
Why: "The actual declaration states values whose typeof is "object"" reads clumsily: a declaration doesn't state values. The reason now has the values as its subject, with "are" for classes and arrays and "have" for a typeof, as in the @typeof annotation it comes from. 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: Values of the actual declaration have typeof "object". Values of the expected declaration have 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") ↦ are instances of Dog @instanceof("Dog") of a subclass ↦ are instances of Dog, a subclass of Animal arrays ↦ are arrays @typeof("string") ↦ have typeof "string" nothing ↦ have no stated class or typeof 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 f29ecf7

7 files changed

Lines changed: 24 additions & 26 deletions

‎compiler/ml/ast_untagged_variants.ml‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -322,16 +322,17 @@ 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
327-
| Some (InstanceType (Class {name; ancestors = []})) -> "instances of " ^ name
325+
(* What a declaration's annotations state about its values, for error
326+
messages, as the rest of a sentence starting with "Values of ..." *)
327+
let describe_declared_values = function
328+
| Some (InstanceType (Class {name; ancestors = []})) ->
329+
"are instances of " ^ name
328330
| Some (InstanceType (Class {name; ancestors})) ->
329-
"instances of " ^ name ^ ", a subclass of "
331+
"are instances of " ^ name ^ ", a subclass of "
330332
^ String.concat " and " ancestors
331-
| 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 (InstanceType Array) -> "are arrays"
334+
| Some block_type -> "have typeof \"" ^ typeof_name block_type ^ "\""
335+
| None -> "have no stated class or typeof"
335336

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

‎compiler/ml/includecore.ml‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,9 @@ let report_type_mismatch0 first second decl ppf err =
242242
| Runtime_annotation (declared1, declared2) ->
243243
pr
244244
"@[<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
245+
Values of %s %s %s.@,\
246+
Values of %s %s %s@]"
247+
first decl declared1 second decl declared2
251248

252249
let report_type_mismatch first second decl ppf =
253250
List.iter (fun err ->
@@ -397,8 +394,8 @@ let compare_runtime_annotations env id decl1 decl2 =
397394
else
398395
[
399396
Runtime_annotation
400-
( Ast_untagged_variants.describe_declared_block_type declared1,
401-
Ast_untagged_variants.describe_declared_block_type declared2 );
397+
( Ast_untagged_variants.describe_declared_values declared1,
398+
Ast_untagged_variants.describe_declared_values declared2 );
402399
]
403400

404401
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+
Values of the actual declaration have typeof "object".
22+
Values of the expected declaration have 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+
Values of the actual declaration have no stated class or typeof.
20+
Values of the expected declaration have 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+
Values of the actual declaration are instances of Dog, a subclass of Animal.
21+
Values of the expected declaration are 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+
Values of the actual declaration are instances of Dog, a subclass of Animal.
21+
Values of the expected declaration are 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+
Values of the actual declaration are instances of Dog, a subclass of Animal.
21+
Values of the expected declaration are instances of Dog.

0 commit comments

Comments
 (0)