Skip to content

Commit

Permalink
Fix exact object indexer issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Ville Saukkonen committed Dec 16, 2018
1 parent 49ab125 commit 4e0c018
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/typing/flow_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6741,7 +6741,7 @@ and flow_obj_to_obj cx trace ~use_op (lreason, l_obj) (ureason, u_obj) =
(Field (None, lv, lpolarity), Field (None, uv, upolarity))
| _ -> ());

if rflags.exact && rflags.sealed = Sealed && not (is_literal_object_reason ureason)
if udict = None && rflags.exact && rflags.sealed = Sealed && not (is_literal_object_reason ureason)
then (
iter_real_props cx lflds (fun ~is_sentinel s _ ->
if not (Context.has_prop cx uflds s)
Expand Down
51 changes: 50 additions & 1 deletion tests/exact/exact.exp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,55 @@ References:
^^^^^^^^^^ [1]


Error --------------------------------------------------------------------------------------------- exact_indexer.js:4:2

Cannot cast object literal to object type because number [1] is incompatible with string [2] in property `a`.

exact_indexer.js:4:2
4| ({ a: 123 }: {| ['a']: string |}); // error
^^^^^^^^^^

References:
exact_indexer.js:4:7
4| ({ a: 123 }: {| ['a']: string |}); // error
^^^ [1]
exact_indexer.js:4:24
4| ({ a: 123 }: {| ['a']: string |}); // error
^^^^^^ [2]


Error --------------------------------------------------------------------------------------------- exact_indexer.js:5:2

Cannot cast object literal to object type because string `a` [1] is incompatible with string literal `b` [2] in the
indexer property's key.

exact_indexer.js:5:2
5| ({ a: 123 }: {| ['b']: number |}); // error
^^^^^^^^^^ [1]

References:
exact_indexer.js:5:18
5| ({ a: 123 }: {| ['b']: number |}); // error
^^^ [2]


Error --------------------------------------------------------------------------------------------- exact_indexer.js:7:2

Cannot cast object literal to object type because number [1] is incompatible with string [2] in property `a`.

exact_indexer.js:7:2
7| ({ a: 123 }: {| [string]: string |}); // error
^^^^^^^^^^

References:
exact_indexer.js:7:7
7| ({ a: 123 }: {| [string]: string |}); // error
^^^ [1]
exact_indexer.js:7:27
7| ({ a: 123 }: {| [string]: string |}); // error
^^^^^^ [2]


Error -------------------------------------------------------------------------------------------------- objmap.js:11:32

Cannot assign object literal to `doesError` because number [1] is incompatible with number literal `2` [2] in property
Expand Down Expand Up @@ -333,4 +382,4 @@ References:



Found 20 errors
Found 23 errors
7 changes: 7 additions & 0 deletions tests/exact/exact_indexer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// @flow

({ a: 123 }: {| ['a']: number |}); // OK
({ a: 123 }: {| ['a']: string |}); // error
({ a: 123 }: {| ['b']: number |}); // error
({ a: 123 }: {| [string]: number |}); // OK
({ a: 123 }: {| [string]: string |}); // error

0 comments on commit 4e0c018

Please sign in to comment.