Skip to content

Commit 346b857

Browse files
geralt-encorefacebook-github-bot
authored andcommitted
Handle protected internal in HackC IR and assembly
Summary: The issue was revealed by D76516094 that moves protected internal experimental feature to preview status. This diff makes sure that protected internal is being correctly translated for both HackC IR and assembly. Reviewed By: francesco-zappa-nardelli Differential Revision: D77148070 fbshipit-source-id: 4a703343da7277251c79b5dd0e9041a81afb4d29
1 parent 33c7592 commit 346b857

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

hphp/hack/src/hackc/assemble/assemble.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,8 @@ fn assemble_property(token_iter: &mut Lexer<'_>) -> Result<hhbc::Property> {
573573
fn determine_visibility(attr: &hhvm_types_ffi::ffi::Attr) -> Result<hhbc::Visibility> {
574574
let v = if attr.is_internal() && attr.is_public() {
575575
hhbc::Visibility::Internal
576+
} else if attr.is_internal() && attr.is_protected() {
577+
hhbc::Visibility::ProtectedInternal
576578
} else if attr.is_public() {
577579
hhbc::Visibility::Public
578580
} else if attr.is_private() {

hphp/hack/src/hackc/ir/assemble/parse.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// This source code is licensed under the MIT license found in the
44
// LICENSE file in the "hack" directory of this source tree.
55

6+
use std::result::Result::Ok;
7+
68
use anyhow::Result;
79
use ir_core::AsTypeStructExceptionKind;
810
use ir_core::Attr;
@@ -822,13 +824,24 @@ fn parse_var(tokenizer: &mut Tokenizer<'_>) -> Result<StringId> {
822824
}
823825

824826
pub(crate) fn parse_visibility(tokenizer: &mut Tokenizer<'_>) -> Result<Visibility> {
825-
parse_enum(tokenizer, "Visibility", |id| {
827+
let vis1 = parse_enum(tokenizer, "Visibility", str_to_visibility_fn())?;
828+
let vis2 = parse_opt_enum(tokenizer, str_to_visibility_fn())?;
829+
let vis = match (vis1, vis2) {
830+
(Visibility::Protected, Some(Visibility::Internal)) => Visibility::ProtectedInternal,
831+
(Visibility::Internal, Some(Visibility::Protected)) => Visibility::ProtectedInternal,
832+
_ => vis1,
833+
};
834+
Ok(vis)
835+
}
836+
837+
fn str_to_visibility_fn() -> impl FnOnce(&str) -> Option<Visibility> {
838+
|id| {
826839
Some(match id {
827840
"private" => Visibility::Private,
828841
"public" => Visibility::Public,
829842
"protected" => Visibility::Protected,
830843
"internal" => Visibility::Internal,
831844
_ => return None,
832845
})
833-
})
846+
}
834847
}

0 commit comments

Comments
 (0)