Skip to content

Commit

Permalink
add Enum::get_members helper
Browse files Browse the repository at this point in the history
Summary: Before this logic was in the narrowing code, I think it makes more sense to move it into the Enum strict so that it can be reused.

Reviewed By: rchen152

Differential Revision: D68280404

fbshipit-source-id: 589e01c92a92f24d8aea9c87bea4f8d42eeca0fd
  • Loading branch information
yangdanny97 authored and facebook-github-bot committed Jan 16, 2025
1 parent 17176b3 commit ba214e8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
11 changes: 6 additions & 5 deletions pyre2/pyre2/bin/alt/answers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1039,14 +1039,15 @@ impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> {
fn subtract_enum_member(&self, cls: &ClassType, name: &Name) -> Type {
let e = self.get_enum(cls).unwrap();
self.unions(
&cls.class_object()
.fields()
.iter()
&e.get_members()
.into_iter()
.filter_map(|f| {
if *f == *name {
if let Lit::Enum(box (_, ref member_name)) = f
&& *member_name == *name
{
None
} else {
e.get_member(f).map(Type::Literal)
Some(Type::Literal(f))
}
})
.collect::<Vec<_>>(),
Expand Down
9 changes: 9 additions & 0 deletions pyre2/pyre2/bin/alt/classes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@ impl Enum {
pub fn class_type(&self) -> &ClassType {
&self.0
}

pub fn get_members(&self) -> SmallSet<Lit> {
self.0
.class_object()
.fields()
.iter()
.filter_map(|f| self.get_member(f))
.collect()
}
}

fn is_unbound_function(ty: &Type) -> bool {
Expand Down

0 comments on commit ba214e8

Please sign in to comment.