diff --git a/lib/core.js b/lib/core.js index 40ed22b9b68..8019b9b1fe9 100644 --- a/lib/core.js +++ b/lib/core.js @@ -290,7 +290,8 @@ declare class Array extends $ReadOnlyArray { [key: number]: T; length: number; - static (...values:Array): Array; + static (length: number): Array; + static (...values: Array): Array; static isArray(obj: mixed): bool; static from(iter: Iterable, mapFn: (elem: A, index: number) => B, thisArg?: any): Array; static from(iter: Iterable, mapFn: void): Array; diff --git a/tests/arraylib/array_lib.js b/tests/arraylib/array_lib.js index 381b1933e34..018bbd4becd 100644 --- a/tests/arraylib/array_lib.js +++ b/tests/arraylib/array_lib.js @@ -20,6 +20,11 @@ var l: Array = h.concat(1,2,3); var m: Array = h.concat('a', 'b', 'c'); var n: Array = h.concat('a', 'b', 'c'); // Error +var o: Array = Array('a', 'b') +var p: Array = Array('a', 'b') // error, string ~> number +var q: Array = Array(0) // ok +var r: Array = Array(20) // ok + function reduce_test() { /* Adapted from the following source: * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce diff --git a/tests/arraylib/arraylib.exp b/tests/arraylib/arraylib.exp index e9a289ad8db..88b02643225 100644 --- a/tests/arraylib/arraylib.exp +++ b/tests/arraylib/arraylib.exp @@ -75,84 +75,127 @@ References: ^^^ [4] -Error ----------------------------------------------------------------------------------------------- array_lib.js:46:29 +Error ----------------------------------------------------------------------------------------------- array_lib.js:24:24 + +Cannot assign `Array(...)` to `p` because: + - string [1] is incompatible with number [2] in array element. + - string [3] is incompatible with number [2] in array element. + + array_lib.js:24:24 + 24| var p: Array = Array('a', 'b') // error, string ~> number + ^^^^^^^^^^^^^^^ + +References: + array_lib.js:24:30 + 24| var p: Array = Array('a', 'b') // error, string ~> number + ^^^ [1] + array_lib.js:24:14 + 24| var p: Array = Array('a', 'b') // error, string ~> number + ^^^^^^ [2] + array_lib.js:24:35 + 24| var p: Array = Array('a', 'b') // error, string ~> number + ^^^ [3] + + +Error ----------------------------------------------------------------------------------------------- array_lib.js:51:29 Cannot perform arithmetic operation because string [1] is not a number. - array_lib.js:46:29 - 46| [""].reduce((acc, str) => acc * str.length); // error, string ~> number + array_lib.js:51:29 + 51| [""].reduce((acc, str) => acc * str.length); // error, string ~> number ^^^ References: - array_lib.js:46:4 - 46| [""].reduce((acc, str) => acc * str.length); // error, string ~> number + array_lib.js:51:4 + 51| [""].reduce((acc, str) => acc * str.length); // error, string ~> number ^^ [1] -Error ----------------------------------------------------------------------------------------------- array_lib.js:46:35 +Error ----------------------------------------------------------------------------------------------- array_lib.js:51:35 Cannot get `str.length` because property `length` is missing in `Number` [1]. - array_lib.js:46:35 - 46| [""].reduce((acc, str) => acc * str.length); // error, string ~> number + array_lib.js:51:35 + 51| [""].reduce((acc, str) => acc * str.length); // error, string ~> number ^^^^^^^^^^ References: - array_lib.js:46:29 - 46| [""].reduce((acc, str) => acc * str.length); // error, string ~> number + array_lib.js:51:29 + 51| [""].reduce((acc, str) => acc * str.length); // error, string ~> number ^^^^^^^^^^^^^^^^ [1] -Error ----------------------------------------------------------------------------------------------- array_lib.js:47:34 +Error ----------------------------------------------------------------------------------------------- array_lib.js:52:34 Cannot perform arithmetic operation because string [1] is not a number. - array_lib.js:47:34 - 47| [""].reduceRight((acc, str) => acc * str.length); // error, string ~> number + array_lib.js:52:34 + 52| [""].reduceRight((acc, str) => acc * str.length); // error, string ~> number ^^^ References: - array_lib.js:47:4 - 47| [""].reduceRight((acc, str) => acc * str.length); // error, string ~> number + array_lib.js:52:4 + 52| [""].reduceRight((acc, str) => acc * str.length); // error, string ~> number ^^ [1] -Error ----------------------------------------------------------------------------------------------- array_lib.js:47:40 +Error ----------------------------------------------------------------------------------------------- array_lib.js:52:40 Cannot get `str.length` because property `length` is missing in `Number` [1]. - array_lib.js:47:40 - 47| [""].reduceRight((acc, str) => acc * str.length); // error, string ~> number + array_lib.js:52:40 + 52| [""].reduceRight((acc, str) => acc * str.length); // error, string ~> number ^^^^^^^^^^ References: - array_lib.js:47:34 - 47| [""].reduceRight((acc, str) => acc * str.length); // error, string ~> number + array_lib.js:52:34 + 52| [""].reduceRight((acc, str) => acc * str.length); // error, string ~> number ^^^^^^^^^^^^^^^^ [1] -Error ----------------------------------------------------------------------------------------------- array_lib.js:63:48 +Error ----------------------------------------------------------------------------------------------- array_lib.js:68:48 Cannot assign `Array.of(...)` to `incompatibleTypeNotOkay` because: - number [1] is incompatible with string [2] in array element. - number [3] is incompatible with string [2] in array element. - array_lib.js:63:48 - 63| var incompatibleTypeNotOkay: Array = Array.of(1, 2); + array_lib.js:68:48 + 68| var incompatibleTypeNotOkay: Array = Array.of(1, 2); ^^^^^^^^^^^^^^ References: - array_lib.js:63:57 - 63| var incompatibleTypeNotOkay: Array = Array.of(1, 2); + array_lib.js:68:57 + 68| var incompatibleTypeNotOkay: Array = Array.of(1, 2); ^ [1] - array_lib.js:63:38 - 63| var incompatibleTypeNotOkay: Array = Array.of(1, 2); + array_lib.js:68:38 + 68| var incompatibleTypeNotOkay: Array = Array.of(1, 2); ^^^^^^ [2] - array_lib.js:63:60 - 63| var incompatibleTypeNotOkay: Array = Array.of(1, 2); + array_lib.js:68:60 + 68| var incompatibleTypeNotOkay: Array = Array.of(1, 2); ^ [3] +Error ----------------------------------------------------------------------------------------------- issue_7887.js:7:15 + +Cannot assign object literal to `a` because number [1] is incompatible with string [2] in array element of property +`prop`. + + issue_7887.js:7:15 + v + 7| var a: Plop = { + 8| prop: Array(5).fill(1) // error + 9| }; + ^ + +References: + issue_7887.js:8:23 + 8| prop: Array(5).fill(1) // error + ^ [1] + issue_7887.js:4:9 + 4| prop: string[] + ^^^^^^ [2] + + Error ---------------------------------------------------------------------------------------------------- length.js:7:1 Cannot assign `6` to `r.length` because property `length` is not writable. @@ -170,4 +213,4 @@ Cannot assign `7` to `t.length` because property `length` is not writable. -Found 14 errors +Found 17 errors diff --git a/tests/arraylib/issue_7887.js b/tests/arraylib/issue_7887.js new file mode 100644 index 00000000000..a0b193e619a --- /dev/null +++ b/tests/arraylib/issue_7887.js @@ -0,0 +1,9 @@ +/* @flow */ + +type Plop = {| + prop: string[] +|}; + +var a: Plop = { + prop: Array(5).fill(1) // error +};