Skip to content

Commit

Permalink
Allow internal for the __dynamicallycallable attribute
Browse files Browse the repository at this point in the history
Summary: Internal methods are actually "public" from a runtime perspective, so it makes sense to allow __DynamicallyCallable on them.

Reviewed By: oulgen

Differential Revision: D40868413

fbshipit-source-id: 0c67991594cfc27d3aba9af09f81f9a74cfe2918
  • Loading branch information
jamesjwu authored and facebook-github-bot committed Nov 1, 2022
1 parent f2cd60a commit 235cd7a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 17 deletions.
39 changes: 22 additions & 17 deletions hphp/hack/src/typing/nast_check/dynamically_callable_attr_check.ml
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,30 @@ let handler =
let (pos, _) = m.m_name in
let vis = m.m_visibility in
let attr = m.m_user_attributes in
match
Naming_attributes.mem_pos SN.UserAttributes.uaDynamicallyCallable attr
with
| Some p ->
(if not (Aast.equal_visibility vis Public) then
let vis =
match vis with
| Public -> `public
| Private -> `private_
| Protected -> `protected
| Internal -> `internal
in
Errors.add_naming_error
@@ Naming_error.Illegal_use_of_dynamically_callable
{ attr_pos = p; meth_pos = pos; vis });
let check_reified_callable p =
if has_reified_generics m.m_tparams then
Errors.add_nast_check_error
@@ Nast_check_error.Dynamically_callable_reified p;
()
@@ Nast_check_error.Dynamically_callable_reified p
in
match
( Naming_attributes.mem_pos SN.UserAttributes.uaDynamicallyCallable attr,
vis )
with
| (Some p, Public)
| (Some p, Internal) ->
check_reified_callable p
| (Some p, _) ->
let vis =
match vis with
| Public -> `public
| Private -> `private_
| Protected -> `protected
| Internal -> `internal
in
Errors.add_naming_error
@@ Naming_error.Illegal_use_of_dynamically_callable
{ attr_pos = p; meth_pos = pos; vis };
check_reified_callable p
| _ -> ()

method! at_fun_ _ f =
Expand Down
13 changes: 13 additions & 0 deletions hphp/hack/test/typecheck/modules/dynamically_callable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//// def.php
<?hh
<<file:__EnableUnstableFeatures("modules")>>
new module foo {}
//// use.php
<?hh
<<file:__EnableUnstableFeatures("modules")>>
module foo;

public class Foo {
<<__DynamicallyCallable>>
internal function foo(): void {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
No errors

0 comments on commit 235cd7a

Please sign in to comment.