Skip to content

Commit

Permalink
Ignore package error in function pointers to static functions
Browse files Browse the repository at this point in the history
Summary: SymbolRefs does not follow function pointers to static functions. To match it, we ignore package errors on those as well.

Reviewed By: DavidSnider

Differential Revision: D62771086

fbshipit-source-id: 6866756a6672aef6eb97551bf8908947d7de1420
  • Loading branch information
Francesco Zappa Nardelli authored and facebook-github-bot committed Sep 16, 2024
1 parent b519a89 commit 38d7856
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
8 changes: 7 additions & 1 deletion hphp/hack/src/typing/typing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3372,7 +3372,9 @@ end = struct
let (env, ty) = Env.fresh_type_error env pos in
make_result env p (Aast.Method_caller (pos_cname, meth_name)) ty))
| FunctionPointer (FP_class_const (cid, meth), targs) ->
let (env, _, ce, cty) = Class_id.class_expr env [] cid in
let (env, _, ce, cty) =
Class_id.class_expr ~is_function_pointer:true env [] cid
in
let (env, (fpty, tal)) =
Class_get_expr.class_get
~is_method:true
Expand Down Expand Up @@ -9329,6 +9331,7 @@ and Class_id : sig
?inside_nameof:bool ->
?is_const:bool ->
?is_attribute:bool ->
?is_function_pointer:bool ->
env ->
Nast.targ list ->
Nast.class_id ->
Expand Down Expand Up @@ -9400,6 +9403,7 @@ end = struct
?(inside_nameof = false)
?(is_const = false)
?(is_attribute = false)
?(is_function_pointer = false)
(env : env)
(tal : Nast.targ list)
((_, p, cid_) : Nast.class_id) :
Expand Down Expand Up @@ -9516,6 +9520,7 @@ end = struct
Env.package_v2 env
&& (inside_nameof
|| is_attribute
|| is_function_pointer
|| Env.package_v2_bypass_package_check_for_class_const env
&& is_const)
in
Expand All @@ -9530,6 +9535,7 @@ end = struct
(Cls.internal class_)
(Cls.get_module class_)
(Cls.get_package_override class_)));

(* Don't add Exact superfluously to class type if it's final *)
let exact =
if Cls.final class_ then
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//// foo.php
<?hh
// package pkg1 (does not include pkg2)
function main(): void {
C::foo<>;
}

//// bar.php
<?hh
// package pkg2
<<file: __PackageOverride('pkg2')>>
class C {
public static function foo(): void {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
No errors

0 comments on commit 38d7856

Please sign in to comment.