Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve option shape detection in Datarepr #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions typing/datarepr.ml
Original file line number Diff line number Diff line change
Expand Up @@ -158,23 +158,33 @@ let constructor_descrs ~current_unit ty_path decl cstrs rep =
(cd_id, cstr) :: descr_rem in
let result = describe_constructors 0 0 cstrs in
match result with
| [ (none_id, ({cstr_args = []} as none_descr) ) ;
(some_id, ({ cstr_args = [_]} as some_descr))
]
when Ident.name none_id = "None" && Ident.name some_id = "Some" ->
[
(none_id, {none_descr with
cstr_attributes =
optional_shape :: none_descr.cstr_attributes});
(some_id, {some_descr with
cstr_attributes =
optional_shape :: some_descr.cstr_attributes
})
]

| (
[ (a_id, ({cstr_args = []} as a_descr) ) ;
(b_id, ({ cstr_args = [_]} as b_descr))
] |
[ (a_id, ({cstr_args = [_]} as a_descr) ) ;
(b_id, ({ cstr_args = []} as b_descr))
[ (some_id, ({cstr_args = [_]} as some_descr) ) ;
(none_id, ({ cstr_args = []} as none_descr))
]
) when (Ident.name a_id = "Some" && Ident.name b_id = "None") ||
(Ident.name a_id = "None" && Ident.name b_id = "Some")
) when (Ident.name some_id = "Some" && Ident.name none_id = "None")
->
[
(a_id, {a_descr with
(some_id, {some_descr with
cstr_attributes =
optional_shape :: a_descr.cstr_attributes});
(b_id, {b_descr with
optional_shape :: some_descr.cstr_attributes});
(none_id, {none_descr with
cstr_attributes =
optional_shape :: b_descr.cstr_attributes
optional_shape :: none_descr.cstr_attributes
})
]
| _ -> result
Expand Down