diff --git a/lib/node.js b/lib/node.js index ba89b2e577e..aedcc25fcfe 100644 --- a/lib/node.js +++ b/lib/node.js @@ -1085,7 +1085,7 @@ declare module "fs" { ): void; declare function readdir( path: string, - options: { encoding?: string, withFileTypes?: true, ... }, + options: { encoding?: string, withFileTypes: true, ... }, callback: (err: ?ErrnoError, files: Array) => void ): void; declare function readdir( @@ -1098,7 +1098,7 @@ declare module "fs" { ): Array; declare function readdirSync( path: string, - options?: string | { encoding?: string, withFileTypes?: true, ... } + options?: string | { encoding?: string, withFileTypes: true, ... } ): Array; declare function close(fd: number, callback: (err: ?ErrnoError) => void): void; declare function closeSync(fd: number): void; diff --git a/src/typing/subtyping_kit.ml b/src/typing/subtyping_kit.ml index 6959052a3df..c4ee7e8dc19 100644 --- a/src/typing/subtyping_kit.ml +++ b/src/typing/subtyping_kit.ml @@ -254,13 +254,12 @@ module Make (Flow : INPUT) : OUTPUT = struct in match (Context.get_prop cx lflds s, ldict) with | (Some lp, _) -> - if lit then ( - (* prop from unaliased LB: check <:, then make exact *) - (match (Property.read_t lp, Property.read_t up) with + if lit then + (* prop from unaliased LB: check <: *) + match (Property.read_t lp, Property.read_t up) with | (Some lt, Some ut) -> rec_flow cx trace (lt, UseT (use_op, ut)) - | _ -> ()); - speculative_object_write cx lflds s up - ) else + | _ -> () + else (* prop from aliased LB *) rec_flow_p cx ~trace ~use_op lreason ureason propref (lp, up) | (None, Some { key; value; dict_polarity; _ }) when not (is_dictionary_exempt s) -> @@ -287,12 +286,7 @@ module Make (Flow : INPUT) : OUTPUT = struct | _ -> (* property doesn't exist in inflowing type *) (match up with - | Field (_, OptionalT _, _) when lit -> - (* if property is marked optional or otherwise has a maybe type, - and if inflowing type is a literal (i.e., it is not an - annotation), then we add it to the inflowing type as - an optional property *) - speculative_object_write cx lflds s up + | Field (_, OptionalT _, _) when lit -> () | Field (_, OptionalT _, Polarity.Positive) when Obj_type.is_exact_or_sealed ureason lflags.obj_kind -> rec_flow diff --git a/tests/new_merge/new_merge.exp b/tests/new_merge/new_merge.exp index e972042a044..250a8dc8b5a 100644 --- a/tests/new_merge/new_merge.exp +++ b/tests/new_merge/new_merge.exp @@ -406,20 +406,20 @@ References: Error ----------------------------------------------------------------------------------------------------- main.js:85:2 -Cannot cast `y19` to object type because undefined [1] is incompatible with number [2] in property `a`. -[incompatible-cast] +Cannot cast `y19` to object type because property `a` is missing in object literal [1] but exists in object type [2]. +[prop-missing] main.js:85:2 85| (y19: { a: number }); // error undefined ~> number ^^^ References: - main.js:84:13 - 84| (y19: { a?: number }); // okay - ^^^^^^ [1] - main.js:85:12 + spread.js:10:18 + 10| export const y = { ...t }; + ^^^^^^^^ [1] + main.js:85:7 85| (y19: { a: number }); // error undefined ~> number - ^^^^^^ [2] + ^^^^^^^^^^^^^ [2] Error ----------------------------------------------------------------------------------------------------- main.js:89:2 diff --git a/tests/object_widening/object_widening.exp b/tests/object_widening/object_widening.exp index ce4196d729a..30d99a6191c 100644 --- a/tests/object_widening/object_widening.exp +++ b/tests/object_widening/object_widening.exp @@ -201,16 +201,17 @@ References: Error -------------------------------------------------------------------------------------------- type_widening.js:54:2 -Cannot cast `b.foo` to number because undefined [1] is incompatible with number [2]. [incompatible-cast] +Cannot cast `b.foo` to number because possibly missing property `foo` in object literal [1] is incompatible with +number [2]. [incompatible-cast] type_widening.js:54:2 54| (b.foo: number); // Error, foo does not appear in all branches ^^^^^ References: - type_widening.js:17:24 - 17| type AllOpt = { +foo?: number, +bar?: number, +baz?: number, +qux?: number, ... }; - ^^^^^^ [1] + type_widening.js:48:23 + 48| const b = spreadExact(y); + ^ [1] type_widening.js:54:9 54| (b.foo: number); // Error, foo does not appear in all branches ^^^^^^ [2] @@ -218,16 +219,17 @@ References: Error -------------------------------------------------------------------------------------------- type_widening.js:55:2 -Cannot cast `b.bar` to number because undefined [1] is incompatible with number [2]. [incompatible-cast] +Cannot cast `b.bar` to number because possibly missing property `bar` in object literal [1] is incompatible with +number [2]. [incompatible-cast] type_widening.js:55:2 55| (b.bar: number); // Error, bar does not appear in all branches ^^^^^ References: - type_widening.js:17:39 - 17| type AllOpt = { +foo?: number, +bar?: number, +baz?: number, +qux?: number, ... }; - ^^^^^^ [1] + type_widening.js:48:23 + 48| const b = spreadExact(y); + ^ [1] type_widening.js:55:9 55| (b.bar: number); // Error, bar does not appear in all branches ^^^^^^ [2] @@ -235,16 +237,32 @@ References: Error -------------------------------------------------------------------------------------------- type_widening.js:56:2 -Cannot cast `b.baz` to number because undefined [1] is incompatible with number [2]. [incompatible-cast] +Cannot cast `b.baz` to number because possibly missing property `baz` in object literal [1] is incompatible with +number [2]. [incompatible-cast] type_widening.js:56:2 56| (b.baz: number); // Error, baz does not appear in all branches ^^^^^ References: - type_widening.js:17:54 - 17| type AllOpt = { +foo?: number, +bar?: number, +baz?: number, +qux?: number, ... }; - ^^^^^^ [1] + type_widening.js:48:23 + 48| const b = spreadExact(y); + ^ [1] + type_widening.js:56:9 + 56| (b.baz: number); // Error, baz does not appear in all branches + ^^^^^^ [2] + + +Error -------------------------------------------------------------------------------------------- type_widening.js:56:2 + +Cannot cast `b.baz` to number because `void` (due to access of non-existent property `baz`) [1] is incompatible with +number [2]. [incompatible-cast] + + type_widening.js:56:2 + 56| (b.baz: number); // Error, baz does not appear in all branches + ^^^^^ [1] + +References: type_widening.js:56:9 56| (b.baz: number); // Error, baz does not appear in all branches ^^^^^^ [2] @@ -252,16 +270,32 @@ References: Error -------------------------------------------------------------------------------------------- type_widening.js:57:2 -Cannot cast `b.qux` to number because undefined [1] is incompatible with number [2]. [incompatible-cast] +Cannot cast `b.qux` to number because possibly missing property `qux` in object literal [1] is incompatible with +number [2]. [incompatible-cast] type_widening.js:57:2 57| (b.qux: number); // Error, qux does not appear in all branches ^^^^^ References: - type_widening.js:17:69 - 17| type AllOpt = { +foo?: number, +bar?: number, +baz?: number, +qux?: number, ... }; - ^^^^^^ [1] + type_widening.js:48:23 + 48| const b = spreadExact(y); + ^ [1] + type_widening.js:57:9 + 57| (b.qux: number); // Error, qux does not appear in all branches + ^^^^^^ [2] + + +Error -------------------------------------------------------------------------------------------- type_widening.js:57:2 + +Cannot cast `b.qux` to number because `void` (due to access of non-existent property `qux`) [1] is incompatible with +number [2]. [incompatible-cast] + + type_widening.js:57:2 + 57| (b.qux: number); // Error, qux does not appear in all branches + ^^^^^ [1] + +References: type_widening.js:57:9 57| (b.qux: number); // Error, qux does not appear in all branches ^^^^^^ [2] @@ -806,4 +840,4 @@ References: -Found 49 errors +Found 51 errors diff --git a/tests/object_widening/object_widening.exp.resolved_env b/tests/object_widening/object_widening.exp.resolved_env deleted file mode 100644 index 30d99a6191c..00000000000 --- a/tests/object_widening/object_widening.exp.resolved_env +++ /dev/null @@ -1,843 +0,0 @@ -Error ------------------------------------------------------------------------------------------ annot_in_union.js:16:31 - -Cannot assign object literal to `x` because possibly missing property `thisFieldIsMissing` in object literal [1] is -incompatible with boolean literal `true` [2] in property `thisFieldIsMissing`. [incompatible-type] - - annot_in_union.js:16:31 - v - 16| const x: LiterallyAnyObject = { - 17| ...prevPagers.object, // Error - 18| }; - ^ [1] - -References: - annot_in_union.js:5:23 - 5| thisFieldIsMissing: true, - ^^^^ [2] - - -Error -------------------------------------------------------------------------------------------- exact_indexer.js:4:11 - -Cannot spread object literal because Flow cannot determine a type for object literal [1]. object type [2] is inexact, so -it may contain `foo` with a type that conflicts with `foo`'s definition in object literal [3]. Try making object -type [2] exact. [cannot-spread-inexact] - - exact_indexer.js:4:11 - 4| const z = {...{foo: 3}, ...x.x}; - ^^^^^^^^^^^^^^^^^^^^^ [1] - -References: - exact_indexer.js:2:21 - 2| declare var x: {x?: {| [string]: number |}}; - ^^^^^^^^^^^^^^^^^^^^^^ [2] - exact_indexer.js:4:15 - 4| const z = {...{foo: 3}, ...x.x}; - ^^^^^^^^ [3] - - -Error --------------------------------------------------------------------------------------------- intersection.js:5:24 - -Cannot assign object literal to `i` because property `bar` is missing in object literal [1] but exists in -`OtherProps` [2]. [prop-missing] - - intersection.js:5:24 - 5| const i: Intersected = {...null}; // error, missing foo and bar - ^^^^^^^^^ [1] - -References: - intersection.js:4:28 - 4| type Intersected = Props & OtherProps; - ^^^^^^^^^^ [2] - - -Error --------------------------------------------------------------------------------------------- intersection.js:5:24 - -Cannot assign object literal to `i` because property `foo` is missing in object literal [1] but exists in `Props` [2]. -[prop-missing] - - intersection.js:5:24 - 5| const i: Intersected = {...null}; // error, missing foo and bar - ^^^^^^^^^ [1] - -References: - intersection.js:4:20 - 4| type Intersected = Props & OtherProps; - ^^^^^ [2] - - -Error -------------------------------------------------------------------------------------------- type_widening.js:27:2 - -Cannot cast `a.foo` to number because undefined [1] is incompatible with number [2]. [incompatible-cast] - - type_widening.js:27:2 - 27| (a.foo: number); // Error, foo does not appear in all branches - ^^^^^ - -References: - type_widening.js:8:13 - 8| x = {foo: 3}; - ^ [1] - type_widening.js:27:9 - 27| (a.foo: number); // Error, foo does not appear in all branches - ^^^^^^ [2] - - -Error -------------------------------------------------------------------------------------------- type_widening.js:27:2 - -Cannot cast `a.foo` to number because possibly missing property `foo` in object literal [1] is incompatible with -number [2]. [incompatible-cast] - - type_widening.js:27:2 - 27| (a.foo: number); // Error, foo does not appear in all branches - ^^^^^ - -References: - type_widening.js:19:23 - 19| const a = spreadExact(x); - ^ [1] - type_widening.js:27:9 - 27| (a.foo: number); // Error, foo does not appear in all branches - ^^^^^^ [2] - - -Error -------------------------------------------------------------------------------------------- type_widening.js:28:2 - -Cannot cast `a.bar` to number because possibly missing property `bar` in object literal [1] is incompatible with -number [2]. [incompatible-cast] - - type_widening.js:28:2 - 28| (a.bar: number); // Error, bar does not appear in all branches - ^^^^^ - -References: - type_widening.js:19:23 - 19| const a = spreadExact(x); - ^ [1] - type_widening.js:28:9 - 28| (a.bar: number); // Error, bar does not appear in all branches - ^^^^^^ [2] - - -Error -------------------------------------------------------------------------------------------- type_widening.js:28:2 - -Cannot cast `a.bar` to number because `void` (due to access of non-existent property `bar`) [1] is incompatible with -number [2]. [incompatible-cast] - - type_widening.js:28:2 - 28| (a.bar: number); // Error, bar does not appear in all branches - ^^^^^ [1] - -References: - type_widening.js:28:9 - 28| (a.bar: number); // Error, bar does not appear in all branches - ^^^^^^ [2] - - -Error -------------------------------------------------------------------------------------------- type_widening.js:29:2 - -Cannot cast `a.baz` to number because possibly missing property `baz` in object literal [1] is incompatible with -number [2]. [incompatible-cast] - - type_widening.js:29:2 - 29| (a.baz: number); // Error, baz does not appear in all branches - ^^^^^ - -References: - type_widening.js:19:23 - 19| const a = spreadExact(x); - ^ [1] - type_widening.js:29:9 - 29| (a.baz: number); // Error, baz does not appear in all branches - ^^^^^^ [2] - - -Error -------------------------------------------------------------------------------------------- type_widening.js:29:2 - -Cannot cast `a.baz` to number because `void` (due to access of non-existent property `baz`) [1] is incompatible with -number [2]. [incompatible-cast] - - type_widening.js:29:2 - 29| (a.baz: number); // Error, baz does not appear in all branches - ^^^^^ [1] - -References: - type_widening.js:29:9 - 29| (a.baz: number); // Error, baz does not appear in all branches - ^^^^^^ [2] - - -Error -------------------------------------------------------------------------------------------- type_widening.js:30:2 - -Cannot cast `a.qux` to number because possibly missing property `qux` in object literal [1] is incompatible with -number [2]. [incompatible-cast] - - type_widening.js:30:2 - 30| (a.qux: number); // Error, qux does not appear in all branches - ^^^^^ - -References: - type_widening.js:19:23 - 19| const a = spreadExact(x); - ^ [1] - type_widening.js:30:9 - 30| (a.qux: number); // Error, qux does not appear in all branches - ^^^^^^ [2] - - -Error -------------------------------------------------------------------------------------------- type_widening.js:30:2 - -Cannot cast `a.qux` to number because `void` (due to access of non-existent property `qux`) [1] is incompatible with -number [2]. [incompatible-cast] - - type_widening.js:30:2 - 30| (a.qux: number); // Error, qux does not appear in all branches - ^^^^^ [1] - -References: - type_widening.js:30:9 - 30| (a.qux: number); // Error, qux does not appear in all branches - ^^^^^^ [2] - - -Error -------------------------------------------------------------------------------------------- type_widening.js:54:2 - -Cannot cast `b.foo` to number because possibly missing property `foo` in object literal [1] is incompatible with -number [2]. [incompatible-cast] - - type_widening.js:54:2 - 54| (b.foo: number); // Error, foo does not appear in all branches - ^^^^^ - -References: - type_widening.js:48:23 - 48| const b = spreadExact(y); - ^ [1] - type_widening.js:54:9 - 54| (b.foo: number); // Error, foo does not appear in all branches - ^^^^^^ [2] - - -Error -------------------------------------------------------------------------------------------- type_widening.js:55:2 - -Cannot cast `b.bar` to number because possibly missing property `bar` in object literal [1] is incompatible with -number [2]. [incompatible-cast] - - type_widening.js:55:2 - 55| (b.bar: number); // Error, bar does not appear in all branches - ^^^^^ - -References: - type_widening.js:48:23 - 48| const b = spreadExact(y); - ^ [1] - type_widening.js:55:9 - 55| (b.bar: number); // Error, bar does not appear in all branches - ^^^^^^ [2] - - -Error -------------------------------------------------------------------------------------------- type_widening.js:56:2 - -Cannot cast `b.baz` to number because possibly missing property `baz` in object literal [1] is incompatible with -number [2]. [incompatible-cast] - - type_widening.js:56:2 - 56| (b.baz: number); // Error, baz does not appear in all branches - ^^^^^ - -References: - type_widening.js:48:23 - 48| const b = spreadExact(y); - ^ [1] - type_widening.js:56:9 - 56| (b.baz: number); // Error, baz does not appear in all branches - ^^^^^^ [2] - - -Error -------------------------------------------------------------------------------------------- type_widening.js:56:2 - -Cannot cast `b.baz` to number because `void` (due to access of non-existent property `baz`) [1] is incompatible with -number [2]. [incompatible-cast] - - type_widening.js:56:2 - 56| (b.baz: number); // Error, baz does not appear in all branches - ^^^^^ [1] - -References: - type_widening.js:56:9 - 56| (b.baz: number); // Error, baz does not appear in all branches - ^^^^^^ [2] - - -Error -------------------------------------------------------------------------------------------- type_widening.js:57:2 - -Cannot cast `b.qux` to number because possibly missing property `qux` in object literal [1] is incompatible with -number [2]. [incompatible-cast] - - type_widening.js:57:2 - 57| (b.qux: number); // Error, qux does not appear in all branches - ^^^^^ - -References: - type_widening.js:48:23 - 48| const b = spreadExact(y); - ^ [1] - type_widening.js:57:9 - 57| (b.qux: number); // Error, qux does not appear in all branches - ^^^^^^ [2] - - -Error -------------------------------------------------------------------------------------------- type_widening.js:57:2 - -Cannot cast `b.qux` to number because `void` (due to access of non-existent property `qux`) [1] is incompatible with -number [2]. [incompatible-cast] - - type_widening.js:57:2 - 57| (b.qux: number); // Error, qux does not appear in all branches - ^^^^^ [1] - -References: - type_widening.js:57:9 - 57| (b.qux: number); // Error, qux does not appear in all branches - ^^^^^^ [2] - - -Error -------------------------------------------------------------------------------------------- type_widening.js:81:2 - -Cannot cast `c.foo` to number because possibly missing property `foo` in object literal [1] is incompatible with -number [2]. [incompatible-cast] - - type_widening.js:81:2 - 81| (c.foo: number); // Error, foo does not appear in all branches - ^^^^^ - -References: - type_widening.js:75:18 - 75| const c = spread(z); - ^ [1] - type_widening.js:81:9 - 81| (c.foo: number); // Error, foo does not appear in all branches - ^^^^^^ [2] - - -Error -------------------------------------------------------------------------------------------- type_widening.js:82:2 - -Cannot cast `c.bar` to number because possibly missing property `bar` in object literal [1] is incompatible with -number [2]. [incompatible-cast] - - type_widening.js:82:2 - 82| (c.bar: number); // Error, bar does not appear in all branches - ^^^^^ - -References: - type_widening.js:75:18 - 75| const c = spread(z); - ^ [1] - type_widening.js:82:9 - 82| (c.bar: number); // Error, bar does not appear in all branches - ^^^^^^ [2] - - -Error -------------------------------------------------------------------------------------------- type_widening.js:82:4 - -Cannot get `c.bar` because property `bar` is missing in object type [1]. [prop-missing] - - type_widening.js:82:4 - 82| (c.bar: number); // Error, bar does not appear in all branches - ^^^ - -References: - type_widening.js:3:27 - 3| function spread(x: T): { ...T, ...{||} } { return (null: any)} - ^^^^^^^^^^^^^^^^^ [1] - - -Error -------------------------------------------------------------------------------------------- type_widening.js:83:2 - -Cannot cast `c.baz` to number because possibly missing property `baz` in object literal [1] is incompatible with -number [2]. [incompatible-cast] - - type_widening.js:83:2 - 83| (c.baz: number); // Error, baz does not appear in all branches - ^^^^^ - -References: - type_widening.js:75:18 - 75| const c = spread(z); - ^ [1] - type_widening.js:83:9 - 83| (c.baz: number); // Error, baz does not appear in all branches - ^^^^^^ [2] - - -Error -------------------------------------------------------------------------------------------- type_widening.js:83:4 - -Cannot get `c.baz` because property `baz` (did you mean `bar`?) is missing in object type [1]. [prop-missing] - - type_widening.js:83:4 - 83| (c.baz: number); // Error, baz does not appear in all branches - ^^^ - -References: - type_widening.js:3:27 - 3| function spread(x: T): { ...T, ...{||} } { return (null: any)} - ^^^^^^^^^^^^^^^^^ [1] - - -Error -------------------------------------------------------------------------------------------- type_widening.js:83:4 - -Cannot get `c.baz` because property `baz` is missing in object type [1]. [prop-missing] - - type_widening.js:83:4 - 83| (c.baz: number); // Error, baz does not appear in all branches - ^^^ - -References: - type_widening.js:3:27 - 3| function spread(x: T): { ...T, ...{||} } { return (null: any)} - ^^^^^^^^^^^^^^^^^ [1] - - -Error -------------------------------------------------------------------------------------------- type_widening.js:84:2 - -Cannot cast `c.qux` to number because possibly missing property `qux` in object literal [1] is incompatible with -number [2]. [incompatible-cast] - - type_widening.js:84:2 - 84| (c.qux: number); // Error, qux does not appear in all branches - ^^^^^ - -References: - type_widening.js:75:18 - 75| const c = spread(z); - ^ [1] - type_widening.js:84:9 - 84| (c.qux: number); // Error, qux does not appear in all branches - ^^^^^^ [2] - - -Error -------------------------------------------------------------------------------------------- type_widening.js:84:4 - -Cannot get `c.qux` because property `qux` is missing in object type [1]. [prop-missing] - - type_widening.js:84:4 - 84| (c.qux: number); // Error, qux does not appear in all branches - ^^^ - -References: - type_widening.js:3:27 - 3| function spread(x: T): { ...T, ...{||} } { return (null: any)} - ^^^^^^^^^^^^^^^^^ [1] - - -Error ------------------------------------------------------------------------------------------- type_widening.js:115:2 - -Cannot cast `optional_spread.foo` to number because undefined [1] is incompatible with number [2]. [incompatible-cast] - - type_widening.js:115:2 - 115| (optional_spread.foo: number); // Error, foo does not appear in all branches, might be undefined - ^^^^^^^^^^^^^^^^^^^ - -References: - type_widening.js:101:32 - 101| optional = ({foo: 3}: {foo?: number}); - ^^^^^^ [1] - type_widening.js:115:23 - 115| (optional_spread.foo: number); // Error, foo does not appear in all branches, might be undefined - ^^^^^^ [2] - - -Error ------------------------------------------------------------------------------------------- type_widening.js:116:2 - -Cannot cast `optional_spread.bar` to number because undefined [1] is incompatible with number [2]. [incompatible-cast] - - type_widening.js:116:2 - 116| (optional_spread.bar: number); // Error, bar does not appear in all branches, might be undefined - ^^^^^^^^^^^^^^^^^^^ - -References: - type_widening.js:103:32 - 103| optional = ({bar: 3}: {bar?: number}); - ^^^^^^ [1] - type_widening.js:116:23 - 116| (optional_spread.bar: number); // Error, bar does not appear in all branches, might be undefined - ^^^^^^ [2] - - -Error ------------------------------------------------------------------------------------------ type_widening.js:116:18 - -Cannot get `optional_spread.bar` because property `bar` is missing in object type [1]. [prop-missing] - - type_widening.js:116:18 - 116| (optional_spread.bar: number); // Error, bar does not appear in all branches, might be undefined - ^^^ - -References: - type_widening.js:3:27 - 3| function spread(x: T): { ...T, ...{||} } { return (null: any)} - ^^^^^^^^^^^^^^^^^ [1] - - -Error ------------------------------------------------------------------------------------------- type_widening.js:117:2 - -Cannot cast `optional_spread.baz` to number because undefined [1] is incompatible with number [2]. [incompatible-cast] - - type_widening.js:117:2 - 117| (optional_spread.baz: number); // Error, baz does not appear in all branches, might be undefined - ^^^^^^^^^^^^^^^^^^^ - -References: - type_widening.js:105:32 - 105| optional = ({baz: 3}: {baz?: number}); - ^^^^^^ [1] - type_widening.js:117:23 - 117| (optional_spread.baz: number); // Error, baz does not appear in all branches, might be undefined - ^^^^^^ [2] - - -Error ------------------------------------------------------------------------------------------ type_widening.js:117:18 - -Cannot get `optional_spread.baz` because property `baz` (did you mean `bar`?) is missing in object type [1]. -[prop-missing] - - type_widening.js:117:18 - 117| (optional_spread.baz: number); // Error, baz does not appear in all branches, might be undefined - ^^^ - -References: - type_widening.js:3:27 - 3| function spread(x: T): { ...T, ...{||} } { return (null: any)} - ^^^^^^^^^^^^^^^^^ [1] - - -Error ------------------------------------------------------------------------------------------ type_widening.js:117:18 - -Cannot get `optional_spread.baz` because property `baz` is missing in object type [1]. [prop-missing] - - type_widening.js:117:18 - 117| (optional_spread.baz: number); // Error, baz does not appear in all branches, might be undefined - ^^^ - -References: - type_widening.js:3:27 - 3| function spread(x: T): { ...T, ...{||} } { return (null: any)} - ^^^^^^^^^^^^^^^^^ [1] - - -Error ------------------------------------------------------------------------------------------- type_widening.js:118:2 - -Cannot cast `optional_spread.qux` to number because undefined [1] is incompatible with number [2]. [incompatible-cast] - - type_widening.js:118:2 - 118| (optional_spread.qux: number); // Error, qux does not appear in all branches, might be undefined - ^^^^^^^^^^^^^^^^^^^ - -References: - type_widening.js:107:32 - 107| optional = ({qux: 3}: {qux?: number}); - ^^^^^^ [1] - type_widening.js:118:23 - 118| (optional_spread.qux: number); // Error, qux does not appear in all branches, might be undefined - ^^^^^^ [2] - - -Error ------------------------------------------------------------------------------------------ type_widening.js:118:18 - -Cannot get `optional_spread.qux` because property `qux` is missing in object type [1]. [prop-missing] - - type_widening.js:118:18 - 118| (optional_spread.qux: number); // Error, qux does not appear in all branches, might be undefined - ^^^ - -References: - type_widening.js:3:27 - 3| function spread(x: T): { ...T, ...{||} } { return (null: any)} - ^^^^^^^^^^^^^^^^^ [1] - - -Error ------------------------------------------------------------------------------------------- type_widening.js:170:2 - -Cannot cast `indexer_spread2.foo` to string because number [1] is incompatible with string [2]. [incompatible-cast] - - type_widening.js:170:2 - 170| (indexer_spread2.foo: string); // Error, number ~> string - ^^^^^^^^^^^^^^^^^^^ - -References: - type_widening.js:156:36 - 156| indexer2 = ({foo: 3}: {[string]: number}); - ^^^^^^ [1] - type_widening.js:170:23 - 170| (indexer_spread2.foo: string); // Error, number ~> string - ^^^^^^ [2] - - -Error ------------------------------------------------------------------------------------------- type_widening.js:171:2 - -Cannot cast `indexer_spread2.bar` to string because undefined [1] is incompatible with string [2]. [incompatible-cast] - - type_widening.js:171:2 - 171| (indexer_spread2.bar: string); // Error, possibly number or undefined - ^^^^^^^^^^^^^^^^^^^ - -References: - type_widening.js:3:27 - 3| function spread(x: T): { ...T, ...{||} } { return (null: any)} - ^^^^^^^^^^^^^^^^^ [1] - type_widening.js:171:23 - 171| (indexer_spread2.bar: string); // Error, possibly number or undefined - ^^^^^^ [2] - - -Error ------------------------------------------------------------------------------------------- type_widening.js:171:2 - -Cannot cast `indexer_spread2.bar` to string because number [1] is incompatible with string [2]. [incompatible-cast] - - type_widening.js:171:2 - 171| (indexer_spread2.bar: string); // Error, possibly number or undefined - ^^^^^^^^^^^^^^^^^^^ - -References: - type_widening.js:156:36 - 156| indexer2 = ({foo: 3}: {[string]: number}); - ^^^^^^ [1] - type_widening.js:171:23 - 171| (indexer_spread2.bar: string); // Error, possibly number or undefined - ^^^^^^ [2] - - -Error ------------------------------------------------------------------------------------------- type_widening.js:171:2 - -Cannot cast `indexer_spread2.bar` to string because number [1] is incompatible with string [2]. [incompatible-cast] - - type_widening.js:171:2 - 171| (indexer_spread2.bar: string); // Error, possibly number or undefined - ^^^^^^^^^^^^^^^^^^^ - -References: - type_widening.js:160:37 - 160| indexer2 = ({baz: ''}: {[string]: number, baz: string}); - ^^^^^^ [1] - type_widening.js:171:23 - 171| (indexer_spread2.bar: string); // Error, possibly number or undefined - ^^^^^^ [2] - - -Error ------------------------------------------------------------------------------------------- type_widening.js:171:2 - -Cannot cast `indexer_spread2.bar` to string because number [1] is incompatible with string [2]. [incompatible-cast] - - type_widening.js:171:2 - 171| (indexer_spread2.bar: string); // Error, possibly number or undefined - ^^^^^^^^^^^^^^^^^^^ - -References: - type_widening.js:162:37 - 162| indexer2 = ({qux: ''}: {[string]: number, qux: string}); - ^^^^^^ [1] - type_widening.js:171:23 - 171| (indexer_spread2.bar: string); // Error, possibly number or undefined - ^^^^^^ [2] - - -Error ------------------------------------------------------------------------------------------- type_widening.js:172:2 - -Cannot cast `indexer_spread2.baz` to string because undefined [1] is incompatible with string [2]. [incompatible-cast] - - type_widening.js:172:2 - 172| (indexer_spread2.baz: string); // Error, possibly number or undefined - ^^^^^^^^^^^^^^^^^^^ - -References: - type_widening.js:3:27 - 3| function spread(x: T): { ...T, ...{||} } { return (null: any)} - ^^^^^^^^^^^^^^^^^ [1] - type_widening.js:172:23 - 172| (indexer_spread2.baz: string); // Error, possibly number or undefined - ^^^^^^ [2] - - -Error ------------------------------------------------------------------------------------------- type_widening.js:172:2 - -Cannot cast `indexer_spread2.baz` to string because number [1] is incompatible with string [2]. [incompatible-cast] - - type_widening.js:172:2 - 172| (indexer_spread2.baz: string); // Error, possibly number or undefined - ^^^^^^^^^^^^^^^^^^^ - -References: - type_widening.js:156:36 - 156| indexer2 = ({foo: 3}: {[string]: number}); - ^^^^^^ [1] - type_widening.js:172:23 - 172| (indexer_spread2.baz: string); // Error, possibly number or undefined - ^^^^^^ [2] - - -Error ------------------------------------------------------------------------------------------- type_widening.js:172:2 - -Cannot cast `indexer_spread2.baz` to string because number [1] is incompatible with string [2]. [incompatible-cast] - - type_widening.js:172:2 - 172| (indexer_spread2.baz: string); // Error, possibly number or undefined - ^^^^^^^^^^^^^^^^^^^ - -References: - type_widening.js:162:37 - 162| indexer2 = ({qux: ''}: {[string]: number, qux: string}); - ^^^^^^ [1] - type_widening.js:172:23 - 172| (indexer_spread2.baz: string); // Error, possibly number or undefined - ^^^^^^ [2] - - -Error ------------------------------------------------------------------------------------------- type_widening.js:173:2 - -Cannot cast `indexer_spread2.qux` to string because undefined [1] is incompatible with string [2]. [incompatible-cast] - - type_widening.js:173:2 - 173| (indexer_spread2.qux: string); // Error, Possibly number or undefined - ^^^^^^^^^^^^^^^^^^^ - -References: - type_widening.js:3:27 - 3| function spread(x: T): { ...T, ...{||} } { return (null: any)} - ^^^^^^^^^^^^^^^^^ [1] - type_widening.js:173:23 - 173| (indexer_spread2.qux: string); // Error, Possibly number or undefined - ^^^^^^ [2] - - -Error ------------------------------------------------------------------------------------------- type_widening.js:173:2 - -Cannot cast `indexer_spread2.qux` to string because number [1] is incompatible with string [2]. [incompatible-cast] - - type_widening.js:173:2 - 173| (indexer_spread2.qux: string); // Error, Possibly number or undefined - ^^^^^^^^^^^^^^^^^^^ - -References: - type_widening.js:156:36 - 156| indexer2 = ({foo: 3}: {[string]: number}); - ^^^^^^ [1] - type_widening.js:173:23 - 173| (indexer_spread2.qux: string); // Error, Possibly number or undefined - ^^^^^^ [2] - - -Error ------------------------------------------------------------------------------------------ type_widening.js:183:35 - -Cannot call `spread` with `indexer_err` bound to `x` because string [1] is incompatible with number [2]. -[incompatible-call] - - type_widening.js:183:35 - 183| const indexer_err_spread = spread(indexer_err); // Error, string and number don't unify - ^^^^^^^^^^^ - -References: - type_widening.js:178:46 - 178| indexer_err = ({foo: 'string'}: {[string]: string}) - ^^^^^^ [1] - type_widening.js:180:39 - 180| indexer_err = ({foo: 3}: {[string]: number}) - ^^^^^^ [2] - - -Error ------------------------------------------------------------------------------------------- type_widening.js:194:2 - -Cannot cast `indexer_on_second_spread.foo` to number because undefined [1] is incompatible with number [2]. -[incompatible-cast] - - type_widening.js:194:2 - 194| (indexer_on_second_spread.foo: number); // Error, may be void or string - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -References: - type_widening.js:3:27 - 3| function spread(x: T): { ...T, ...{||} } { return (null: any)} - ^^^^^^^^^^^^^^^^^ [1] - type_widening.js:194:32 - 194| (indexer_on_second_spread.foo: number); // Error, may be void or string - ^^^^^^ [2] - - -Error ------------------------------------------------------------------------------------------- type_widening.js:194:2 - -Cannot cast `indexer_on_second_spread.foo` to number because string [1] is incompatible with number [2]. -[incompatible-cast] - - type_widening.js:194:2 - 194| (indexer_on_second_spread.foo: number); // Error, may be void or string - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -References: - type_widening.js:188:29 - 188| indexer_on_second = {foo: 'string'}; - ^^^^^^^^ [1] - type_widening.js:194:32 - 194| (indexer_on_second_spread.foo: number); // Error, may be void or string - ^^^^^^ [2] - - -Error ------------------------------------------------------------------------------------------ type_widening.js:195:27 - -Cannot get `indexer_on_second_spread.bar` because property `bar` is missing in object type [1]. [prop-missing] - - type_widening.js:195:27 - 195| (indexer_on_second_spread.bar: number); // Error, no indexer if it's only in one branch - ^^^ - -References: - type_widening.js:3:27 - 3| function spread(x: T): { ...T, ...{||} } { return (null: any)} - ^^^^^^^^^^^^^^^^^ [1] - - -Error ------------------------------------------------------------------------------------------ type_widening.js:196:27 - -Cannot get `indexer_on_second_spread.baz` because property `baz` is missing in object type [1]. [prop-missing] - - type_widening.js:196:27 - 196| (indexer_on_second_spread.baz: number); // Error, no indexer if it's only in one branch - ^^^ - -References: - type_widening.js:3:27 - 3| function spread(x: T): { ...T, ...{||} } { return (null: any)} - ^^^^^^^^^^^^^^^^^ [1] - - -Error ------------------------------------------------------------------------------------------ type_widening.js:197:27 - -Cannot get `indexer_on_second_spread.qux` because property `qux` is missing in object type [1]. [prop-missing] - - type_widening.js:197:27 - 197| (indexer_on_second_spread.qux: number); // Error, no indexer if it's only in one branch - ^^^ - -References: - type_widening.js:3:27 - 3| function spread(x: T): { ...T, ...{||} } { return (null: any)} - ^^^^^^^^^^^^^^^^^ [1] - - -Error ------------------------------------------------------------------------------------------ type_widening.js:207:42 - -Cannot call `inexactSpread` with `inexact` bound to `x` because Flow cannot determine a type for object type [1]. object -type [2] is inexact, so it may contain `bar` with a type that conflicts with `bar`'s definition in object type [1]. Try -making object type [2] exact. [cannot-spread-inexact] - - type_widening.js:207:42 - 207| const inexact_spread_err = inexactSpread(inexact); - ^^^^^^^ - -References: - type_widening.js:206:42 - 206| declare function inexactSpread(x: T): {bar: 3, ...T, ...{||}}; - ^^^^^^^^^^^^^^^^^^^^^^^ [1] - type_widening.js:203:24 - 203| inexact = ({foo: 3}: {foo: number}); - ^^^^^^^^^^^^^ [2] - - - -Found 51 errors diff --git a/tests/objects/objects.exp b/tests/objects/objects.exp index 7dba2bcba30..d9af1ceead5 100644 --- a/tests/objects/objects.exp +++ b/tests/objects/objects.exp @@ -303,21 +303,18 @@ References: ^^^^^^ [2] -Error ---------------------------------------------------------------------------------------- unaliased_assign.js:20:10 +Error ---------------------------------------------------------------------------------------- unaliased_assign.js:26:11 -Cannot assign `obj` to `glob` because number [1] is incompatible with string [2] in property `x`. [incompatible-type] +Cannot assign `10` to `obj.x` because number [1] is incompatible with string [2]. [incompatible-type] - unaliased_assign.js:20:10 - 20| glob = obj; // error: subsequent assignment might make glob.x a number - ^^^ + unaliased_assign.js:26:11 + 26| obj.x = 10; // error + ^^ [1] References: - unaliased_assign.js:18:26 - 18| var obj: { x: string | number }; - ^^^^^^ [1] - unaliased_assign.js:15:16 - 15| var glob: { x: string } = { x: "hey" }; - ^^^^^^ [2] + unaliased_assign.js:25:14 + 25| obj = { x: "hey" }; + ^^^^^ [2] diff --git a/tests/objects/unaliased_assign.js b/tests/objects/unaliased_assign.js index c1cebeea526..54a6a69a502 100644 --- a/tests/objects/unaliased_assign.js +++ b/tests/objects/unaliased_assign.js @@ -17,11 +17,11 @@ var glob: { x: string } = { x: "hey" }; function assign_then_alias() { var obj: { x: string | number }; obj = { x: "hey" }; - glob = obj; // error: subsequent assignment might make glob.x a number + glob = obj; // ok } function assign_then_widen() { var obj: { x: string | number }; obj = { x: "hey" }; - obj.x = 10; // ok, by lvalue's given type + obj.x = 10; // error } diff --git a/tests/optional_props/optional_props.exp b/tests/optional_props/optional_props.exp index dfecd93782c..0fc1c1e3454 100644 --- a/tests/optional_props/optional_props.exp +++ b/tests/optional_props/optional_props.exp @@ -16,20 +16,6 @@ References: ^^^^^^^^^^^^^^^^ [2] -Error ------------------------------------------------------------------------------------------------------ test.js:8:9 - -Cannot assign `0` to `o.foo` because number [1] is incompatible with string [2]. [incompatible-type] - - test.js:8:9 - 8| o.foo = 0; // future widening is constrained - ^ [1] - -References: - test.js:2:16 - 2| var y: { foo?: string } = x; // OK in TypeScript, not OK in Flow - ^^^^^^ [2] - - Error ---------------------------------------------------------------------------------------------------- test.js:12:11 Cannot call `bar` with object literal bound to `config` because string [1] is incompatible with number [2] in property @@ -74,6 +60,20 @@ References: ^^^^^^ [2] +Error ---------------------------------------------------------------------------------------------------- test3.js:40:3 + +Cannot assign `1` to `x.b` because property `b` is missing in object literal [1]. [prop-missing] + + test3.js:40:3 + 40| x.b = 1; + ^ + +References: + test3.js:37:5 + 37| x = { a: 0 }; + ^^^^^^^^ [1] + + Error --------------------------------------------------------------------------------------------------- test3.js:54:16 Cannot assign `'hello'` to `this.x.b` because property `b` is missing in object literal [1]. [prop-missing] diff --git a/tests/optional_props/test.js b/tests/optional_props/test.js index ecb03948569..f936d39967a 100644 --- a/tests/optional_props/test.js +++ b/tests/optional_props/test.js @@ -5,7 +5,7 @@ var z: string = y.foo || ""; var o = { }; y = o; // OK; we know that narrowing could not have happened -o.foo = 0; // future widening is constrained +o.foo = 0; // OK function bar(config: { foo?: number }) {} bar({}); diff --git a/tests/resolved_env/resolved_env.exp b/tests/resolved_env/resolved_env.exp index 398c8bd4822..97d2223ff5f 100644 --- a/tests/resolved_env/resolved_env.exp +++ b/tests/resolved_env/resolved_env.exp @@ -148,9 +148,9 @@ Cannot cast `rest2.p` to string because number [1] is incompatible with string [ ^^^^^^^ References: - bindings.js:15:14 - 15| (rest2: { p: number }); - ^^^^^^ [1] + bindings.js:13:33 + 13| var {w, ...rest2} = { w: 42, p: 100 }; + ^^^ [1] bindings.js:16:11 16| (rest2.p: string); //err ^^^^^^ [2] diff --git a/tests/type_at_pos_react/type_at_pos_react.exp b/tests/type_at_pos_react/type_at_pos_react.exp index 14327449ccf..ed07c810fdb 100644 --- a/tests/type_at_pos_react/type_at_pos_react.exp +++ b/tests/type_at_pos_react/type_at_pos_react.exp @@ -1,6 +1,6 @@ lazy_ref.js:14:9 = {|default: React$AbstractComponent|} lazy_ref.js:14:9,14:9 -lazy_ref.js:19:9 = Promise<{|default: React$AbstractComponent|}> +lazy_ref.js:19:9 = Promise<{|+default: (x: Props) => Element<(x: Props) => Node>|}> lazy_ref.js:19:9,19:9 react_component.js:3:9 = module "react" { declare var version: string; diff --git a/tests/types_first/types_first.exp b/tests/types_first/types_first.exp index a12df51c40b..dc40c1036f1 100644 --- a/tests/types_first/types_first.exp +++ b/tests/types_first/types_first.exp @@ -131,5 +131,56 @@ References: ^^^^^^ [2] +Error ----------------------------------------------------------------------------------------------------- test.js:12:2 + +Cannot cast `o` to `O` because number [1] is incompatible with string [2] in property `y.x`. [incompatible-cast] + + test.js:12:2 + 12| (o: O); // error: number (property x) <~/~> string + ^ + +References: + import-value3.js:5:6 + 5| x: 0, + ^ [1] + import-type4.js:6:6 + 6| x: string; + ^^^^^^ [2] + + +Error ----------------------------------------------------------------------------------------------------- test.js:13:2 + +Cannot cast `o.y` to `O` because number [1] is incompatible with string [2] in property `x`. [incompatible-cast] + + test.js:13:2 + 13| (o.y: O); // error: number (property x) <~/~> string + ^^^ + +References: + import-value3.js:5:6 + 5| x: 0, + ^ [1] + import-type5.js:6:6 + 6| x: string; + ^^^^^^ [2] + + +Error ----------------------------------------------------------------------------------------------------- test.js:13:2 + +Cannot cast `o.y` to `O` because number [1] is incompatible with string [2] in property `y.x`. [incompatible-cast] + + test.js:13:2 + 13| (o.y: O); // error: number (property x) <~/~> string + ^^^ + +References: + import-value3.js:5:6 + 5| x: 0, + ^ [1] + import-type4.js:6:6 + 6| x: string; + ^^^^^^ [2] + + -Found 8 errors +Found 11 errors diff --git a/tests/types_first_lazy/types_first_lazy.exp b/tests/types_first_lazy/types_first_lazy.exp index e4207c0cb3b..9bc5583327d 100644 --- a/tests/types_first_lazy/types_first_lazy.exp +++ b/tests/types_first_lazy/types_first_lazy.exp @@ -88,8 +88,59 @@ References: ^^^^^^ [2] +Error ----------------------------------------------------------------------------------------------------- test.js:12:2 + +Cannot cast `o` to `O` because number [1] is incompatible with string [2] in property `y.x`. [incompatible-cast] + + test.js:12:2 + 12| (o: O); // error: number (property x) <~/~> string + ^ + +References: + import-value3.js:5:6 + 5| x: 0, + ^ [1] + import-type4.js:6:6 + 6| x: string; + ^^^^^^ [2] + + +Error ----------------------------------------------------------------------------------------------------- test.js:13:2 + +Cannot cast `o.y` to `O` because number [1] is incompatible with string [2] in property `x`. [incompatible-cast] + + test.js:13:2 + 13| (o.y: O); // error: number (property x) <~/~> string + ^^^ + +References: + import-value3.js:5:6 + 5| x: 0, + ^ [1] + import-type5.js:6:6 + 6| x: string; + ^^^^^^ [2] + + +Error ----------------------------------------------------------------------------------------------------- test.js:13:2 + +Cannot cast `o.y` to `O` because number [1] is incompatible with string [2] in property `y.x`. [incompatible-cast] + + test.js:13:2 + 13| (o.y: O); // error: number (property x) <~/~> string + ^^^ + +References: + import-value3.js:5:6 + 5| x: 0, + ^ [1] + import-type4.js:6:6 + 6| x: string; + ^^^^^^ [2] + + -Found 5 errors +Found 8 errors The Flow server is currently in lazy mode and is only checking 9/11 files. To learn more, visit flow.org/en/docs/lang/lazy-modes diff --git a/tests/types_first_object_spread/types_first_object_spread.exp b/tests/types_first_object_spread/types_first_object_spread.exp index 94f0632c9ad..928ee6324e6 100644 --- a/tests/types_first_object_spread/types_first_object_spread.exp +++ b/tests/types_first_object_spread/types_first_object_spread.exp @@ -71,9 +71,9 @@ Cannot cast `b1.z` to string because number [1] is incompatible with string [2]. ^^^^ References: - test1.js:11:23 - 11| export type B = {| z: number, ...A |} - ^^^^^^ [1] + test1.js:6:16 + 6| const b = { z: 0, ...a }; + ^ [1] driver.js:12:8 12| (b1.z: string); // Error, z may not exist, number ~> string ^^^^^^ [2] @@ -88,9 +88,9 @@ Cannot cast `b2.x` to string because number [1] is incompatible with string [2]. ^^^^ References: - test2.js:8:16 - 8| type A = {| x: number |} - ^^^^^^ [1] + test2.js:3:16 + 3| const a = { x: 0 }; + ^ [1] driver.js:15:8 15| (b2.x: string); // Error number ~> string ^^^^^^ [2] @@ -105,9 +105,9 @@ Cannot cast `b2.z` to string because number [1] is incompatible with string [2]. ^^^^ References: - test2.js:9:23 - 9| export type B = {| z: number, ...A |} - ^^^^^^ [1] + test2.js:4:16 + 4| const b = { z: 0, ...a }; + ^ [1] driver.js:16:8 16| (b2.z: string); // Error number ~> string ^^^^^^ [2]