forked from facebook/flow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
distinguish between union branches for polymorphic instantiation caching
Summary: Consider the following code: ``` type Filter = [number] | [string]; function convert(filter: Filter) { filter.slice(0); } ``` When we call `slice` on the `filter` object, this produces a `UnionT ~> MethodT` flow, which decomposes into two separate `t ~> MethodT` flows, one for each branch of the union. It is important to note, however, that because `t` in this case is a tuple (this also applies to arrays and read-only arrays), the two `t`s in each of these flows have the same reason. When we later attempt to instantiate the polymorphic type of the return of `slice`, we unify these two `t`s with a tvar representing the return of `slice`. Unfortunately, because we use reasons to implement the polymorphic instantiation cache, and because these two `t`s have the same reason, we attempt to unify both `t`s with the same type variable, and thus get an incompatibility between `number` and `string`. This changes the instantiation cache to take into account the `desc` of the `reason_tapp`, and changes the union lower bound decomposition logic to modify the reason of each of the lower bounds with a "transparent" (in that it will not show up in any error output) description that differentiates between the different branches of the union. This way, the cache will properly recognize the difference between these two types and correctly produce a different unification variable for each case. Fixes facebook#8263 Reviewed By: mvitousek Differential Revision: D19436341 fbshipit-source-id: da44513d8727f3339c71a453f46b536912d295bc
- Loading branch information
1 parent
2b2aa13
commit 7f78643
Showing
8 changed files
with
31 additions
and
29 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
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
[options] | ||
module.system=haste | ||
all=true | ||
no_flowlib=false |
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,14 @@ | ||
// @flow | ||
|
||
|
||
type Filter = [number] | [string]; | ||
|
||
function convert(filter: Filter) { | ||
filter.slice(0); | ||
} | ||
|
||
type Filter2 = Array<number> | Array<string>; | ||
|
||
function convert(filter: Filter2) : Filter2 { | ||
return filter.slice(0); | ||
} |
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