Skip to content

Commit

Permalink
[flow][enums] Fix bigint enum without explicit of bigint parsing
Browse files Browse the repository at this point in the history
Summary: Changelog: [fix] Fix bigint Flow Enum without explicit `of bigint` parsing. We were previously not correctly inferring that this was a bigint enum.

Reviewed By: SamChou19815

Differential Revision: D55260671

fbshipit-source-id: 7e48e74a667c42c5d0848021abefcde370c56bb7
  • Loading branch information
gkz authored and facebook-github-bot committed Mar 22, 2024
1 parent 06a478b commit 5b29a62
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/parser/enum_parser.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 () =
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 ()
Expand Down
6 changes: 6 additions & 0 deletions tests/enums/bigint.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 5b29a62

Please sign in to comment.