Skip to content

Commit 5ef3445

Browse files
SamChou19815meta-codesync[bot]
authored andcommitted
[flow] Check interface variance
Summary: Changelog: [errors] flow will now validate variance in interface declarations Reviewed By: marcoww6, gkz Differential Revision: D85993064 fbshipit-source-id: 1a324bbd6ab65161b3ac264ca01ea173ff983362
1 parent 6ecdd3a commit 5ef3445

3 files changed

Lines changed: 18 additions & 3 deletions

File tree

src/typing/type_annotation.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3060,7 +3060,7 @@ module Make (Statement : Statement_sig.S) : Type_annotation_sig.S = struct
30603060
let (iface_sig, properties) =
30613061
add_interface_properties env properties ~this:(implicit_mixed_this reason) iface_sig
30623062
in
3063-
let (_, t) = Class_type_sig.classtype ~check_polarity:false cx iface_sig in
3063+
let (_, t) = Class_type_sig.classtype ~check_polarity:true cx iface_sig in
30643064
( t,
30653065
iface_sig,
30663066
{

tests/polarity/call.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
type O<+T> = { (x: T): void }; // Error: +T in a negative position
2-
interface I<+T> { (x: T): void }; // Error: +T in a negative position (TODO)
2+
interface I<+T> { (x: T): void }; // Error: +T in a negative position

tests/polarity/polarity.exp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,21 @@ References:
1313
^ [1]
1414

1515

16+
Error ----------------------------------------------------------------------------------------------------- call.js:2:23
17+
18+
Cannot use `T` [1] in an input position because `T` [1] is expected to occur only in output positions.
19+
[incompatible-variance]
20+
21+
call.js:2:23
22+
2| interface I<+T> { (x: T): void }; // Error: +T in a negative position
23+
^
24+
25+
References:
26+
call.js:2:14
27+
2| interface I<+T> { (x: T): void }; // Error: +T in a negative position
28+
^ [1]
29+
30+
1631
Error ------------------------------------------------------------------------------------------------------ fun.js:3:19
1732

1833
Cannot use `T` [1] in an input position because `T` [1] is expected to occur only in output positions.
@@ -294,4 +309,4 @@ References:
294309

295310

296311

297-
Found 22 errors
312+
Found 23 errors

0 commit comments

Comments
 (0)