-
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.
Reject use of open tuples in is or as tests
Summary: As the title says. We don't yet support this in HHVM, so should reject it for Hack. Differential Revision: D68208091 fbshipit-source-id: 80d93a81052822055ad8b2e0d26aac59fcbdbfaa
- Loading branch information
1 parent
9a1bf15
commit 591fe0a
Showing
6 changed files
with
71 additions
and
5 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
6 changes: 6 additions & 0 deletions
6
hphp/hack/test/typecheck/open_tuples/splat/tuple_splat_is_as_test_bad.php
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,6 @@ | ||
<?hh | ||
<<file: __EnableUnstableFeatures('open_tuples', 'type_splat')>> | ||
|
||
function test2<<<__Enforceable>> reify T as (mixed...)>(mixed $m): void { | ||
$m as (int, ...T); | ||
} |
4 changes: 4 additions & 0 deletions
4
hphp/hack/test/typecheck/open_tuples/splat/tuple_splat_is_as_test_bad.php.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,4 @@ | ||
ERROR: File "tuple_splat_is_as_test_bad.php", line 5, characters 9-19: | ||
Invalid `as` expression hint (Typing[4195]) | ||
File "tuple_splat_is_as_test_bad.php", line 5, characters 9-19: | ||
The `as` operator cannot be used with a tuple type with a splat element |
14 changes: 14 additions & 0 deletions
14
hphp/hack/test/typecheck/open_tuples/tuple_open_is_as_test_bad.php
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 @@ | ||
<?hh | ||
<<file: __EnableUnstableFeatures('open_tuples')>> | ||
|
||
function test1(mixed $m): string { | ||
$m as (nonnull...); | ||
if ($m is (int, optional string)) { | ||
return $m[1] ?? "default"; | ||
} | ||
if ($m is (int, string...)) { | ||
return $m[1] ?? "default"; | ||
} | ||
$m as (optional bool, optional int); | ||
return "fail"; | ||
} |
20 changes: 20 additions & 0 deletions
20
hphp/hack/test/typecheck/open_tuples/tuple_open_is_as_test_bad.php.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,20 @@ | ||
WARN: File "tuple_open_is_as_test_bad.php", line 6, characters 7-34: | ||
This `is` check is always `false`. The expression on the left has type `(nonnull...)` which shares no values with `(int, optional string)`. (Warn[12010]) | ||
WARN: File "tuple_open_is_as_test_bad.php", line 9, characters 7-28: | ||
This `is` check is always `false`. The expression on the left has type `(nonnull...)` which shares no values with `(int, string...)`. (Warn[12010]) | ||
ERROR: File "tuple_open_is_as_test_bad.php", line 5, characters 9-20: | ||
Invalid `as` expression hint (Typing[4195]) | ||
File "tuple_open_is_as_test_bad.php", line 5, characters 9-20: | ||
The `as` operator cannot be used with a tuple type with optional or variadic elements | ||
ERROR: File "tuple_open_is_as_test_bad.php", line 6, characters 13-34: | ||
Invalid `is` expression hint (Typing[4195]) | ||
File "tuple_open_is_as_test_bad.php", line 6, characters 13-34: | ||
The `is` operator cannot be used with a tuple type with optional or variadic elements | ||
ERROR: File "tuple_open_is_as_test_bad.php", line 9, characters 13-28: | ||
Invalid `is` expression hint (Typing[4195]) | ||
File "tuple_open_is_as_test_bad.php", line 9, characters 13-28: | ||
The `is` operator cannot be used with a tuple type with optional or variadic elements | ||
ERROR: File "tuple_open_is_as_test_bad.php", line 12, characters 9-37: | ||
Invalid `as` expression hint (Typing[4195]) | ||
File "tuple_open_is_as_test_bad.php", line 12, characters 9-37: | ||
The `as` operator cannot be used with a tuple type with optional or variadic elements |
16 changes: 16 additions & 0 deletions
16
hphp/hack/test/typecheck/open_tuples/tuple_open_is_as_test_bad.php.imp_pess_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,16 @@ | ||
ERROR: File "tuple_open_is_as_test_bad.php", line 5, characters 9-20: | ||
Invalid `as` expression hint (Typing[4195]) | ||
File "tuple_open_is_as_test_bad.php", line 5, characters 9-20: | ||
The `as` operator cannot be used with a tuple type with optional or variadic elements | ||
ERROR: File "tuple_open_is_as_test_bad.php", line 6, characters 13-34: | ||
Invalid `is` expression hint (Typing[4195]) | ||
File "tuple_open_is_as_test_bad.php", line 6, characters 13-34: | ||
The `is` operator cannot be used with a tuple type with optional or variadic elements | ||
ERROR: File "tuple_open_is_as_test_bad.php", line 9, characters 13-28: | ||
Invalid `is` expression hint (Typing[4195]) | ||
File "tuple_open_is_as_test_bad.php", line 9, characters 13-28: | ||
The `is` operator cannot be used with a tuple type with optional or variadic elements | ||
ERROR: File "tuple_open_is_as_test_bad.php", line 12, characters 9-37: | ||
Invalid `as` expression hint (Typing[4195]) | ||
File "tuple_open_is_as_test_bad.php", line 12, characters 9-37: | ||
The `as` operator cannot be used with a tuple type with optional or variadic elements |