Skip to content

Commit

Permalink
ExtDecl: do not create singleton unions when dealing with case types
Browse files Browse the repository at this point in the history
Summary:
When dealing with case types that are singleton unions, ExtDecl would create an ExtDeclTypeDef with the `type_` field as `(|T)`. This creates problems down the line since this is not a parsable type. `(|T)` results from creating a singleton union `Tunion(T)` then applying the hackrs type printer.

That type printer currently prints singleton unions as `(|T)` instead of just `T`. The reason is explained in [this comment](https://www.internalfb.com/diff/D52491369?transaction_fbid=3812697109009854): the code was ported from the ocaml printer `Typing_print.Full`, which is also used for debugging.

We could fix the printer, and we do in the previous diff, but it might get broken again later as devs want to debug more stuff.

So in addition, we also avoid creating singleton unions altogether before printing.

Reviewed By: viratyosin

Differential Revision: D67335740

fbshipit-source-id: 8e7673e22e702177eb1ac0a0b724ec9d4215fbf1
  • Loading branch information
Catherine Gasnier authored and facebook-github-bot committed Dec 17, 2024
1 parent 16c1526 commit e197519
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions hphp/hack/src/hackc/ffi_bridge/ext_decl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,19 @@ pub fn get_file_typedefs(parsed_file: &ParsedFile<'_>, name: &str) -> Vec<ExtDec
(enum_typedef_visibility(*vis), extract_type_name(hint))
}
TypedefTypeAssignment::CaseType((variant, variants)) => {
let mut hints = variants.iter().map(|v| v.0).collect::<Vec<_>>();
hints.insert(0, variant.0);
let mut hints;
let ty_ = if variants.is_empty() {
variant.0.1
} else {
hints = variants.iter().map(|v| v.0).collect::<Vec<_>>();
hints.insert(0, variant.0);
Ty_::Tunion(&hints)
};
(
String::from("case_type"),
extract_type_name(&Ty(
&typing_reason::Reason::NoReason, // the position is ignored when printing the type
Ty_::Tunion(&hints),
ty_,
)),
)
}
Expand Down

0 comments on commit e197519

Please sign in to comment.