Skip to content

Commit 4cc15f7

Browse files
committed
Treat cases with non-unary payloads uniformly.
1 parent 5cbf079 commit 4cc15f7

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

jscomp/build_tests/super_errors/expected/UntaggedNonUnary2.res.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
2 │ type t = Tuple(int, string) | Float(float)
77
3 │
88

9-
This type cannot be unboxed because it has more than one constructor.
9+
This untagged variant definition is invalid: Constructor Tuple has more than one argument.

jscomp/ml/typedecl.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -304,27 +304,27 @@ let transl_declaration ~typeRecordAsObject env sdecl id =
304304
in
305305
let raw_status = get_unboxed_from_attributes sdecl in
306306

307-
let checkUntaggedVariant = match sdecl.ptype_kind with
307+
let checkUntaggedVariant() = match sdecl.ptype_kind with
308308
| Ptype_variant cds -> Ext_list.for_all cds (function
309309
| {pcd_args = Pcstr_tuple ([] | [_])} ->
310310
(* at most one payload allowed for untagged variants *)
311311
true
312+
| {pcd_args = Pcstr_tuple (_::_::_); pcd_name={txt=name}} ->
313+
Ast_untagged_variants.reportConstructorMoreThanOneArg ~loc:sdecl.ptype_loc ~name
312314
| {pcd_args = Pcstr_record _} -> true
313-
| _ -> false )
315+
)
314316
| _ -> false
315317
in
316318

317-
if raw_status.unboxed && not raw_status.default && not checkUntaggedVariant then begin
319+
if raw_status.unboxed && not raw_status.default && not (checkUntaggedVariant()) then begin
318320
match sdecl.ptype_kind with
319321
| Ptype_abstract ->
320322
raise(Error(sdecl.ptype_loc, Bad_unboxed_attribute
321323
"it is abstract"))
322324
| Ptype_variant [{pcd_args = Pcstr_tuple []}] ->
323325
raise(Error(sdecl.ptype_loc, Bad_unboxed_attribute
324326
"its constructor has no argument"))
325-
| Ptype_variant [{pcd_args = Pcstr_tuple [_]}] -> ()
326-
| Ptype_variant [{pcd_args = Pcstr_tuple (_::_::_); pcd_name = {txt=name}}] ->
327-
Ast_untagged_variants.reportConstructorMoreThanOneArg ~loc:sdecl.ptype_loc ~name
327+
| Ptype_variant [{pcd_args = Pcstr_tuple _}] -> ()
328328
| Ptype_variant [{pcd_args = Pcstr_record
329329
[{pld_mutable=Immutable; _}]}] -> ()
330330
| Ptype_variant [{pcd_args = Pcstr_record [{pld_mutable=Mutable; _}]}] ->

0 commit comments

Comments
 (0)