Skip to content

Commit 235cd7a

Browse files
jamesjwufacebook-github-bot
authored andcommitted
Allow internal for the __dynamicallycallable attribute
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
1 parent f2cd60a commit 235cd7a

3 files changed

Lines changed: 36 additions & 17 deletions

File tree

hphp/hack/src/typing/nast_check/dynamically_callable_attr_check.ml

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,30 @@ let handler =
3535
let (pos, _) = m.m_name in
3636
let vis = m.m_visibility in
3737
let attr = m.m_user_attributes in
38-
match
39-
Naming_attributes.mem_pos SN.UserAttributes.uaDynamicallyCallable attr
40-
with
41-
| Some p ->
42-
(if not (Aast.equal_visibility vis Public) then
43-
let vis =
44-
match vis with
45-
| Public -> `public
46-
| Private -> `private_
47-
| Protected -> `protected
48-
| Internal -> `internal
49-
in
50-
Errors.add_naming_error
51-
@@ Naming_error.Illegal_use_of_dynamically_callable
52-
{ attr_pos = p; meth_pos = pos; vis });
38+
let check_reified_callable p =
5339
if has_reified_generics m.m_tparams then
5440
Errors.add_nast_check_error
55-
@@ Nast_check_error.Dynamically_callable_reified p;
56-
()
41+
@@ Nast_check_error.Dynamically_callable_reified p
42+
in
43+
match
44+
( Naming_attributes.mem_pos SN.UserAttributes.uaDynamicallyCallable attr,
45+
vis )
46+
with
47+
| (Some p, Public)
48+
| (Some p, Internal) ->
49+
check_reified_callable p
50+
| (Some p, _) ->
51+
let vis =
52+
match vis with
53+
| Public -> `public
54+
| Private -> `private_
55+
| Protected -> `protected
56+
| Internal -> `internal
57+
in
58+
Errors.add_naming_error
59+
@@ Naming_error.Illegal_use_of_dynamically_callable
60+
{ attr_pos = p; meth_pos = pos; vis };
61+
check_reified_callable p
5762
| _ -> ()
5863

5964
method! at_fun_ _ f =
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//// def.php
2+
<?hh
3+
<<file:__EnableUnstableFeatures("modules")>>
4+
new module foo {}
5+
//// use.php
6+
<?hh
7+
<<file:__EnableUnstableFeatures("modules")>>
8+
module foo;
9+
10+
public class Foo {
11+
<<__DynamicallyCallable>>
12+
internal function foo(): void {}
13+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
No errors

0 commit comments

Comments
 (0)