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 0000000000..cec86be576 --- /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 cec70e4975..a3e21a8352 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 37807fd445..cfad02b58a 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 85663aa291..6ce8455fc7 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