Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Remove [[call]] property from function statics
Summary:
A function is modeled as a FunT with statics, but since all functions are
objects it is also fair to consider the function as its statics. For this
reason, we add a [[call]] property to the statics with the type of the function
itself.

This recursion is mostly fine, but polymorphic functions behave badly. The FunT
is wrapped in a PolyT, but the [[call]] property is also wrapped in PolyT. This
causes the type instantiations for the function and it's [[call]] property to be
unrelated, when the two are essentially the same type.

The trick here is to ensure that FunT types are not decomposed into their
statics if they will be compared against another function or callable thing.

I observed this behavior investigating something else, but it was not the cause
of any specific bad behavior.

Reviewed By: panagosg7

Differential Revision: D14783679

fbshipit-source-id: 8ce44ac0df985776b85368d886a2ace625bd37f8
  • Loading branch information
samwgoldman authored and facebook-github-bot committed Apr 26, 2019
1 parent 443d32c commit 3c5a410
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/typing/flow_js.ml
Expand Up @@ -5683,6 +5683,13 @@ let rec __flow cx ((l: Type.t), (u: Type.use_t)) trace =
(* You can use a function as a callable object *)
(***********************************************)

| DefT (_, _, FunT _), UseT (use_op, DefT (_, _, (
ObjT {call_t = Some id; _} |
InstanceT (_, _, _, {inst_call_t = Some id; _})
))) ->
let t = Context.find_call cx id in
rec_flow cx trace (l, UseT (use_op, t))

(* FunT ~> ObjT *)

(* Previously, call properties were stored in the props map, and were
Expand Down
2 changes: 1 addition & 1 deletion src/typing/func_sig.ml
Expand Up @@ -98,7 +98,7 @@ let functiontype cx this_t {reason; kind; tparams; fparams; return_t; knot; _} =
let make_trust = Context.trust_constructor cx in
let static =
let proto = FunProtoT reason in
Obj_type.mk_with_proto cx reason ~call:knot proto
Obj_type.mk_with_proto cx reason proto
in
let prototype =
let reason = replace_reason_const RPrototype reason in
Expand Down

0 comments on commit 3c5a410

Please sign in to comment.