-
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.
Throw error when cannot resolve first argument's type in `type_struct…
…ure` Summary: The following fatals in HHVM and is not caught by Hack. ``` <?hh type MyCoolType = shape( 'a' => int, ... ); <<__EntryPoint>> function main(): void { PHP\var_dump(type_structure(MyCoolType::class, 'TUhOh')); } ``` This diff makes Hack throw an error when we can't properly resolve the type of the first argument to `type_structure`. Previously, we were typing the result of this to be `Tany` and not reporting an error. We should not allow type alias's here at all in part because we cannot support the type alias resolution at HackC time and HHVM does not support resolving type aliases here. Reviewed By: Wilfred Differential Revision: D39483470 fbshipit-source-id: 7bced5c09f5ac0210c752774a566a70d365dce42
- Loading branch information
1 parent
7323b1c
commit 7481994
Showing
10 changed files
with
62 additions
and
13 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
5 changes: 5 additions & 0 deletions
5
hphp/hack/test/typecheck/type_structure/type_structure4.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 |
---|---|---|
@@ -1,2 +1,7 @@ | ||
File "type_structure4.php", line 4, characters 18-33: | ||
Unbound name: `NonExistentClass` (an object type) (Naming[2049]) | ||
File "type_structure4.php", line 4, characters 3-16: | ||
The two arguments to `type_structure()` must be: | ||
- first: `ValidClassname::class` or an object of that class | ||
- second: a single-quoted string literal containing the name of a type constant of that class | ||
Could not resolve the type constant (Typing[4150]) |
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
9 changes: 7 additions & 2 deletions
9
hphp/hack/test/typecheck/type_structure/type_structure6.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 |
---|---|---|
@@ -1,4 +1,9 @@ | ||
File "type_structure6.php", line 6, characters 3-16: | ||
The two arguments to `type_structure()` must be: | ||
- first: `ValidClassname::class` or an object of that class | ||
- second: a single-quoted string literal containing the name of a type constant of that class | ||
Could not resolve the type constant (Typing[4150]) | ||
File "type_structure6.php", line 6, characters 28-30: | ||
No class constant `T` in `C` (Typing[4090]) | ||
File "type_structure6.php", line 3, characters 7-7: | ||
Declaration of `C` is here | ||
File "type_structure6.php", line 3, characters 7-7: | ||
Declaration of `C` is here |
5 changes: 5 additions & 0 deletions
5
hphp/hack/test/typecheck/type_structure/type_structure8.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 |
---|---|---|
@@ -1,2 +1,7 @@ | ||
File "type_structure8.php", line 8, characters 3-16: | ||
The two arguments to `type_structure()` must be: | ||
- first: `ValidClassname::class` or an object of that class | ||
- second: a single-quoted string literal containing the name of a type constant of that class | ||
Could not resolve the type constant (Typing[4150]) | ||
File "type_structure8.php", line 8, characters 18-20: | ||
Was expecting a class, but got a string (Typing[4026]) |
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,7 @@ | ||
<?hh | ||
|
||
type MyTypename = int; | ||
|
||
function test(): void { | ||
type_structure(MyTypename::class, 'Nonsense'); | ||
} |
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,5 @@ | ||
File "type_structure_typename.php", line 6, characters 3-16: | ||
The two arguments to `type_structure()` must be: | ||
- first: `ValidClassname::class` or an object of that class | ||
- second: a single-quoted string literal containing the name of a type constant of that class | ||
Could not resolve the type constant (Typing[4150]) |