Skip to content

Commit

Permalink
sealed_whitelist
Browse files Browse the repository at this point in the history
Summary:
Migrate from:

https://www.internalfb.com/code/fbsource/[1e23f98b01d1]/fbcode/hphp/hack/src/decl/decl_folded_class.ml?lines=305-308

Differential Revision: D34730147

fbshipit-source-id: 3600dfc76a17170063414ead93d2b2c823caf00b
  • Loading branch information
Thomas Jiang authored and facebook-github-bot committed Mar 10, 2022
1 parent c559c6b commit 9733c3d
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 0 deletions.
4 changes: 4 additions & 0 deletions hphp/hack/src/rupro/lib/decl_defs/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ impl<R: Reason> fmt::Debug for FoldedClass<R> {
xhp_attr_deps,
req_ancestors,
req_ancestors_extends,
sealed_whitelist,
decl_errors,
} = self;

Expand Down Expand Up @@ -244,6 +245,9 @@ impl<R: Reason> fmt::Debug for FoldedClass<R> {
if !req_ancestors_extends.is_empty() {
s.field("req_ancestors_extends", req_ancestors_extends);
}
if let Some(sealed_whitelist) = sealed_whitelist {
s.field("sealed_whitelist", sealed_whitelist);
}
if !decl_errors.is_empty() {
s.field("decl_errors", decl_errors);
}
Expand Down
1 change: 1 addition & 0 deletions hphp/hack/src/rupro/lib/decl_defs/folded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ pub struct FoldedClass<R: Reason> {
pub xhp_attr_deps: TypeNameIndexSet,
pub req_ancestors: Box<[Requirement<R>]>,
pub req_ancestors_extends: TypeNameIndexSet,
pub sealed_whitelist: Option<TypeNameIndexSet>,
pub decl_errors: Box<[TypingError<R>]>,
}

Expand Down
10 changes: 10 additions & 0 deletions hphp/hack/src/rupro/lib/folded_decl_provider/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,13 @@ impl<R: Reason> DeclFolder<R> {
(req_ancestors, req_ancestors_extends)
}

fn get_sealed_whitelist(&self, sc: &ShallowClass<R>) -> Option<TypeNameIndexSet> {
sc.user_attributes
.iter()
.find(|ua| ua.name.id() == self.special_names.user_attributes.uaSealed)
.map(|ua| ua.classname_params.iter().copied().collect())
}

pub fn decl_class(
&self,
sc: &ShallowClass<R>,
Expand Down Expand Up @@ -807,6 +814,8 @@ impl<R: Reason> DeclFolder<R> {

let (req_ancestors, req_ancestors_extends) = self.get_class_requirements(sc, parents);

let sealed_whitelist = self.get_sealed_whitelist(sc);

Arc::new(FoldedClass {
name: sc.name.id(),
pos: sc.name.pos().clone(),
Expand Down Expand Up @@ -840,6 +849,7 @@ impl<R: Reason> DeclFolder<R> {
xhp_attr_deps,
req_ancestors: req_ancestors.into_boxed_slice(),
req_ancestors_extends,
sealed_whitelist,
decl_errors: errors.into_boxed_slice(),
})
}
Expand Down
4 changes: 4 additions & 0 deletions hphp/hack/test/rupro/folded_decls/sealed_whitelist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?hh

<<__Sealed(A::class)>>
class A {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FoldedClass {
name: "\\A",
kind: Cclass(
Concrete,
),
consts: {
"class": ClassConst {
is_synthesized: true,
kind: CCConcrete,
pos: NPos,
ty: HH\classname<this>,
origin: "\\A",
refs: [],
},
},
sealed_whitelist: {
"\\A",
},
}

0 comments on commit 9733c3d

Please sign in to comment.