Skip to content
Browse files

Remove [[call]] property from function statics

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

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 3c5a41026f8da473b3869e0ef6d84afa0b978816
Showing with 8 additions and 1 deletion.
  1. +7 −0 src/typing/
  2. +1 −1 src/typing/
@@ -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
@@ -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
let prototype =
let reason = replace_reason_const RPrototype reason in

0 comments on commit 3c5a410

Please sign in to comment.
You can’t perform that action at this time.