Skip to content
Permalink
Browse files

Fix implicit proto for objects with [[call]] properties

Summary:
When an object has a callable property, it is actually a function. As a
function, it's prototype is the function prototype with properties `bind`,
`call`, `apply`, etc.

The code to detect this only considered the original callable property syntax,
but should also consider the newer [[call]] syntax.

Reviewed By: gabelevi

Differential Revision: D14652059

fbshipit-source-id: b83185a8b8bd633d78394bfcbc56a1d5a35d460c
  • Loading branch information...
samwgoldman authored and facebook-github-bot committed Apr 22, 2019
1 parent cbd6438 commit 5d7e01d06b85388882b3214e383d26b73e6de111
Showing with 10 additions and 4 deletions.
  1. +5 −1 src/typing/type_annotation.ml
  2. +5 −3 tests/call_properties/call_properties.exp
@@ -934,7 +934,11 @@ let rec convert cx tparams_map = Ast.Type.(function
| loc, Object { Object.exact; properties; inexact } ->
let reason_desc = RObjectType in
let callable = List.exists (function
| Object.CallProperty (_, { Object.CallProperty.static; _ }) -> not static
| Object.CallProperty (_, { Object.CallProperty.static; _ })
| Object.InternalSlot (_, { Object.InternalSlot.
id = (_, { Ast.Identifier.name = "call"; _ });
static; _ })
-> not static
| _ -> false
) properties in
let mk_object ~exact (call_props, dict, props_map, proto) =
@@ -291,8 +291,10 @@ References:

Error --------------------------------------------------------------------------------------------- internal_slot.js:5:2

Cannot cast object literal to `O` because a call signature declaring the expected parameter / return type is missing in
object literal [1] but exists in `O` [2].
Cannot cast object literal to `O` because:
- object literal [1] is incompatible with function prototype [2].
- a call signature declaring the expected parameter / return type is missing in object literal [1] but exists in
`O` [2].

internal_slot.js:5:2
5| ({}: O); // err: no callable property
@@ -434,7 +436,7 @@ References:



Found 27 errors
Found 28 errors

Only showing the most relevant union/intersection branches.
To see all branches, re-run Flow with --show-all-branches

0 comments on commit 5d7e01d

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