diff --git a/src/parser/enum_parser.ml b/src/parser/enum_parser.ml index eb32d0cd59f..5d5ac00e522 100644 --- a/src/parser/enum_parser.ml +++ b/src/parser/enum_parser.ml @@ -404,6 +404,7 @@ end = struct | None -> let bools_len = List.length members.boolean_members in let nums_len = List.length members.number_members in + let bigints_len = List.length members.bigint_members in let strs_len = List.length members.string_members in let defaulted_len = List.length members.defaulted_members in let empty () = @@ -416,9 +417,9 @@ end = struct } in begin - match (bools_len, nums_len, strs_len, defaulted_len) with - | (0, 0, 0, 0) -> empty () - | (0, 0, _, _) -> + match (bools_len, nums_len, bigints_len, strs_len, defaulted_len) with + | (0, 0, 0, 0, 0) -> empty () + | (0, 0, 0, _, _) -> string_body ~env ~enum_name @@ -427,7 +428,7 @@ end = struct members.string_members members.defaulted_members comments - | (_, 0, 0, _) when bools_len >= defaulted_len -> + | (_, 0, 0, 0, _) when bools_len >= defaulted_len -> List.iter (fun (loc, { DefaultedMember.id = (_, { Identifier.name = member_name; _ }) }) -> error_at @@ -441,7 +442,7 @@ end = struct has_unknown_members; comments; } - | (0, _, 0, _) when nums_len >= defaulted_len -> + | (0, _, 0, 0, _) when nums_len >= defaulted_len -> List.iter (fun (loc, { DefaultedMember.id = (_, { Identifier.name = member_name; _ }) }) -> error_at @@ -455,6 +456,20 @@ end = struct has_unknown_members; comments; } + | (0, 0, _, 0, _) when bigints_len >= defaulted_len -> + List.iter + (fun (loc, { DefaultedMember.id = (_, { Identifier.name = member_name; _ }) }) -> + error_at + env + (loc, Parse_error.EnumNumberMemberNotInitialized { enum_name; member_name })) + members.defaulted_members; + BigIntBody + { + BigIntBody.members = members.bigint_members; + explicit_type = false; + has_unknown_members; + comments; + } | _ -> error_at env (name_loc, Parse_error.EnumInconsistentMemberValues { enum_name }); empty () diff --git a/tests/enums/bigint.js b/tests/enums/bigint.js index 8b96b3681ef..34b30f275a4 100644 --- a/tests/enums/bigint.js +++ b/tests/enums/bigint.js @@ -2,7 +2,13 @@ enum E1 of bigint { A = 1n } +E1.A as E1; // OK +E1.A as bigint; // OK + enum E2 { A = 1n, B = 2n, } + +E2.A as E2; // OK +E2.A as bigint; // OK