Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: This diff moves the destructuring subtyping rules to be above the catch-all `Tvar _, _` rule and fixes the `ty_compare` function in the case of Tdestructure. Previously, it was saying that `list(#1, #2)` is equivalent to `list(#3, #4)`, so the lower bounds on the inner type variables were not being computed. Reviewed By: kmeht Differential Revision: D16846102 fbshipit-source-id: 051685e9991a63bc5dc09a3eba568a8027816ce7
- Loading branch information
1 parent
e329613
commit ef3e61e
Showing
5 changed files
with
98 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?hh | ||
|
||
class Box<T> { | ||
public function put(T $x): void {} | ||
public function get(): T { throw new Exception(); } | ||
} | ||
|
||
function pull<Tk, Tv1, Tv2>( | ||
Tv1 $input, | ||
(function(Tv1): Tv2) $value_func, | ||
(function(Tv1): Tk) $key_func, | ||
): void { | ||
throw new Exception(); | ||
} | ||
|
||
interface A1 {} | ||
interface A2 {} | ||
interface B1 {} | ||
interface B2 {} | ||
|
||
function test((A1, A2) $t1, (B1, B2) $t2): void { | ||
$x = new Box(); // Box<#1> | ||
$x->put($t1); | ||
$x->put($t2); | ||
$input = $x->get(); // {(A1, A2), (B1, B2)} <: #1 | ||
|
||
pull( | ||
$input, | ||
$in ==> { | ||
list( | ||
$v1, // A1 <: #3 /\ B1 <: #3 | ||
$v2 // A2 <: #4 /\ B2 <: #4 | ||
) = $in; // (A1, A2) <: list(#3, #4) /\ (B1, B2) <: list(#3, #4); | ||
}, | ||
$in ==> { | ||
list($v1, $v2) = $in; // same as above | ||
hh_force_solve(); | ||
hh_show($v1); | ||
hh_show($v2); | ||
}, | ||
); | ||
} |
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,10 @@ | ||
File "list_destructuring_tvar.php", line 38, characters 7-18: | ||
(A1 | B1) | ||
File "list_destructuring_tvar.php", line 39, characters 7-18: | ||
(A2 | B2) | ||
File "list_destructuring_tvar.php", line 35, characters 5-128: | ||
Invalid return type (Typing[4110]) | ||
File "list_destructuring_tvar.php", line 27, characters 3-6: | ||
Expected nothing | ||
File "list_destructuring_tvar.php", line 35, characters 5-128: | ||
But got void because this function implicitly returns void |
14 changes: 14 additions & 0 deletions
14
hphp/hack/test/typecheck/list_destructuring_tvar.php.like_types.exp
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 @@ | ||
File "list_destructuring_tvar.php", line 38, characters 7-18: | ||
~?(A1 | B1) | ||
File "list_destructuring_tvar.php", line 39, characters 7-18: | ||
~?(A2 | B2) | ||
File "list_destructuring_tvar.php", line 29, characters 5-177: | ||
Invalid return type (Typing[4110]) | ||
File "list_destructuring_tvar.php", line 8, characters 24-26: | ||
Some type constraint(s) are violated here | ||
File "list_destructuring_tvar.php", line 8, characters 24-26: | ||
Tv2 is a constrained type parameter | ||
File "list_destructuring_tvar.php", line 29, characters 5-177: | ||
Expected void because this function implicitly returns void | ||
File "list_destructuring_tvar.php", line 8, characters 24-26: | ||
But got dynamic |