-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Recursively concretize union-like types in AnnotT
Summary: The following case does not produce an error as expected: ``` type Fn2 = <A, B>(A, B) => A | B; declare var fn2: Fn2; const x = fn2((42: number), ('foo': string)); (true: typeof x); ``` https://flow.org/try/#0C4TwDgpgBAYgdgJigXigHgIIBooCEB8AFNngJQr5QZQA+eA3AFAAmEAxgDYCGATtAG68oAM0QAuWIiZsA9nADOwKAA8UIxIUIAWBBLgBXALYAjCD1I5CAcmEyZViYp4BLOAHNSpJoWA99ECVBIGWEVL0YgA This is because even though `A | B` is wrapped in an `AnnotT` and concretized, its individual members `A` and `B` are not. So when we flow `boolean ~> A | B` we add a lower bound of `boolean` to `A` instead of flowing `boolean ~> number` and `boolean ~> string`. This diff fixes this by wrapping union-like members in `AnnotT` so that they may be concretized before they are checked. I need this fix for the implementation of `$Call` which is then needed for the `$ObjMap` fix. **Note:** This diff includes the tests samwgoldman wrote in D5717999. Reviewed By: samwgoldman Differential Revision: D5722202 fbshipit-source-id: 8c8aaadfe69184281dfd3aa8cdbe619486a95eea
- Loading branch information
1 parent
98c7cc0
commit bd938ab
Showing
6 changed files
with
88 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
function f<A>(a: A): ?A { | ||
if (true) { | ||
return null; | ||
} else { | ||
return a; | ||
} | ||
} | ||
var x = f(42); | ||
('foo': typeof x); // error: string ~> number |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
function f<A>(a: A): {p?: A} { | ||
if (true) { | ||
return {}; | ||
} else { | ||
return {p: a}; | ||
} | ||
} | ||
var x = f(42).p; | ||
(null: typeof x); // error: null ~> $Optional<number> (i.e., void|number) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
function f<A, B>(a: A, b: B): A | B { | ||
if (true) { | ||
return a; | ||
} else { | ||
return b; | ||
} | ||
} | ||
const x = f(42, 'foo'); | ||
(null: typeof x); // error: null ~> number|string |