Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 5d7e01d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/typing/type_annotation.ml
Expand Up @@ -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) =
Expand Down
8 changes: 5 additions & 3 deletions tests/call_properties/call_properties.exp
Expand Up @@ -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
Expand Down Expand Up @@ -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.