-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Add support for indexing of values with types such as `(int, ...T)`. Simply recurse on the `T` with an adjusted index. Differential Revision: D66003892 fbshipit-source-id: 1509699cdef09e3ec5e72bd106c636eacec166dd
- Loading branch information
1 parent
4cf06f1
commit bf35c48
Showing
3 changed files
with
81 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?hh | ||
|
||
<<file: __EnableUnstableFeatures('open_tuples', 'type_splat')>> | ||
|
||
function proj1<T as (arraykey...)>((int, string, ...T) $tup):void { | ||
hh_expect_equivalent<int>($tup[0]); | ||
hh_expect_equivalent<string>($tup[1]); | ||
// This should be an array because the element may not exist | ||
$y = $tup[2]; | ||
hh_expect_equivalent<?arraykey>($tup[2] ?? null); | ||
} | ||
|
||
function proj2<T as (float, bool, arraykey...)>((int, string, ...T) $tup):void { | ||
hh_expect_equivalent<int>($tup[0]); | ||
hh_expect_equivalent<string>($tup[1]); | ||
hh_expect_equivalent<float>($tup[2]); | ||
hh_expect_equivalent<bool>($tup[3]); | ||
// This should be an array because the element may not exist | ||
$y = $tup[4]; | ||
hh_expect_equivalent<?arraykey>($tup[4] ?? null); | ||
} |
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,4 @@ | ||
ERROR: File "type_splat_tuple_proj.php", line 9, characters 13-13: | ||
Invalid index type for this tuple (Typing[4116]) | ||
ERROR: File "type_splat_tuple_proj.php", line 19, characters 13-13: | ||
Invalid index type for this tuple (Typing[4116]) |