From 2f2d098ad288ab3198e11b301f574cf3bde02a5b Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Fri, 23 Oct 2026 07:17:20 +0000 Subject: [PATCH] List float and bigint in the error for an invalid @as payload Why: `@as` accepts float and bigint literals, but the error for any other payload listed only strings, integers, booleans, null and undefined. The untagged variants spec, which quotes the message, now matches it, and its rule 6 table gives the wording printed for arrays and tuples. Diagnostic modified (invalid @as payload): Example: type t = | @as(foo) A | B Before (diagnostic): A variant case annotation @as(...) must be a string, integer, boolean, null, or undefined. After (diagnostic): A variant case annotation @as(...) must be a string, integer, float, bigint, boolean, null, or undefined. Signed-off-by: Christoph Knittel Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Xk6AeCYpCK4SZRtHYKHGoe --- changes/as-payload-error-lists-float-bigint.polish.md | 1 + compiler/ml/UntaggedVariants.md | 6 +++--- compiler/ml/ast_untagged_variants.ml | 4 ++-- .../UntaggedInvalidVariantAsAnnotation.res.expected | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) create mode 100644 changes/as-payload-error-lists-float-bigint.polish.md diff --git a/changes/as-payload-error-lists-float-bigint.polish.md b/changes/as-payload-error-lists-float-bigint.polish.md new file mode 100644 index 00000000000..cec86be5764 --- /dev/null +++ b/changes/as-payload-error-lists-float-bigint.polish.md @@ -0,0 +1 @@ +- List floats and bigints in the error for an invalid `@as` payload, since `@as` accepts them. diff --git a/compiler/ml/UntaggedVariants.md b/compiler/ml/UntaggedVariants.md index cec70e49753..a3e21a83529 100644 --- a/compiler/ml/UntaggedVariants.md +++ b/compiler/ml/UntaggedVariants.md @@ -71,8 +71,8 @@ is the number `1`. - Implementation: `ast_untagged_variants.ml:runtime_tag_of_parsetree`, `process_constructor_tag`. - Tests: fixtures `UntaggedInvalidVariantAsAnnotation.res` - ("A variant case annotation @as(...) must be a string, integer, boolean, - null, or undefined."), `VariantAsIntegerOutOfRange.res`, + ("A variant case annotation @as(...) must be a string, integer, float, + bigint, boolean, null, or undefined."), `VariantAsIntegerOutOfRange.res`, `UntaggedDuplicatedBsAs.res`; `spec_test` rule 2; `tests/tests/src/unboxed_variant_fold_test.res` (`wide`). @@ -140,7 +140,7 @@ The type checker rejects an untagged variant, with | Condition | Reason | Fixture | | --- | --- | --- | | two object cases | At most one case can be an object type. | `UntaggedAtMostOneObject.res` | -| two cases of one instance class (arrays and tuples share `Array`) | At most one case can be a C type. | `UntaggedAtMostOneInstance.res`, `UntaggedTupleAndArray.res` | +| two cases of one instance class (arrays and tuples share `Array`) | At most one case can be a C type; for `Array`, an array or tuple type. | `UntaggedAtMostOneInstance.res`, `UntaggedTupleAndArray.res` | | two function cases | At most one case can be a function type. | `UntaggedAtMostOneFunction.res` | | two string cases | At most one case can be a string type. | `UntaggedAtMostOneString.res` | | two number cases (`int` and `float` count together) | At most one case can be a number type (int or float). | `UntaggedAtMostOneNumber.res` | diff --git a/compiler/ml/ast_untagged_variants.ml b/compiler/ml/ast_untagged_variants.ml index 37807fd4455..cfad02b58a8 100644 --- a/compiler/ml/ast_untagged_variants.ml +++ b/compiler/ml/ast_untagged_variants.ml @@ -27,8 +27,8 @@ let report_error ppf = function | InvalidVariantAsAnnotation -> fprintf ppf - "A variant case annotation @as(...) must be a string, integer, boolean, \ - null, or undefined." + "A variant case annotation @as(...) must be a string, integer, float, \ + bigint, boolean, null, or undefined." | VariantAsIntegerOutOfRange value -> fprintf ppf "The integer %s in this variant case's @as annotation is out of range." diff --git a/tests/build_tests/super_errors/expected/UntaggedInvalidVariantAsAnnotation.res.expected b/tests/build_tests/super_errors/expected/UntaggedInvalidVariantAsAnnotation.res.expected index 85663aa2912..6ce8455fc71 100644 --- a/tests/build_tests/super_errors/expected/UntaggedInvalidVariantAsAnnotation.res.expected +++ b/tests/build_tests/super_errors/expected/UntaggedInvalidVariantAsAnnotation.res.expected @@ -5,4 +5,4 @@ 1 │ type t = | @as(foo) A | B 2 │ - A variant case annotation @as(...) must be a string, integer, boolean, null, or undefined. \ No newline at end of file + A variant case annotation @as(...) must be a string, integer, float, bigint, boolean, null, or undefined. \ No newline at end of file