forked from facebook/hhvm
-
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.
Module Newtype: Correctly declare and lower module newtypes to the ne…
…w visibility Summary: This diff adds declaration and lowering to enable module-level newtypes, completing the feature in the typechecker. After this diff, module level newtypes will behave properly in the typechecker. At runtime, they act like regular type aliases and behave properly as such. Reviewed By: hgoldstein Differential Revision: D37467891 fbshipit-source-id: 616c47f58f62cd11b30a7aab7cd2cd917b7b3559
- Loading branch information
1 parent
cf3f1a9
commit 9ebe9e4
Showing
14 changed files
with
96 additions
and
4 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
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,33 @@ | ||
//// module.php | ||
<?hh | ||
<<file:__EnableUnstableFeatures("modules")>> | ||
new module foo {} | ||
|
||
//// decl.php | ||
<?hh | ||
<<file:__EnableUnstableFeatures("modules")>> | ||
module foo; | ||
module newtype Foo = FooInternal; // ok | ||
module newtype FooBad as FooInternal = FooInternal; // error | ||
internal class FooInternal { | ||
public function foo(): void {} | ||
|
||
} | ||
function same_file(Foo $x) : void { | ||
$x->foo(); // ok | ||
} | ||
|
||
//// use.php | ||
<?hh | ||
<<file:__EnableUnstableFeatures("modules")>> | ||
module foo; | ||
function same_module(Foo $x) : void { | ||
$x->foo(); // ok, it's FooInternal | ||
} | ||
|
||
|
||
//// use_bad.php | ||
<?hh | ||
function bad(Foo $x): void { | ||
$x->foo(); | ||
} |
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,8 @@ | ||
File "module_newtype.php--decl.php", line 5, characters 26-36: | ||
You cannot use this type in a public declaration. (Typing[4446]) | ||
File "module_newtype.php--decl.php", line 6, characters 16-26: | ||
It is declared as `internal` here | ||
File "module_newtype.php--use_bad.php", line 3, characters 7-9: | ||
You are trying to access the method `foo` but this is a mixed value. Use a **specific** class or interface name. (Typing[4064]) | ||
File "module_newtype.php--use_bad.php", line 2, characters 14-16: | ||
Definition is here |
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,25 @@ | ||
<?hh | ||
<<file:__EnableUnstableFeatures("modules")>> | ||
module foo; | ||
module newtype Foo = FooInternal; // ok | ||
internal class FooInternal { | ||
public function foo(): void { | ||
echo "In function foo\n"; | ||
} | ||
|
||
} | ||
function same_file(Foo $x) : void { | ||
$x->foo(); // ok | ||
} | ||
|
||
<<__EntryPoint>> | ||
function main(): void { | ||
include "module_newtype_module.inc"; | ||
include "module_newtype_separate_file.inc"; | ||
include "module_newtype_outside_module.inc"; | ||
|
||
$x = new FooInternal(); | ||
same_file($x); // always ok | ||
separate_file($x); // always ok | ||
outside_module($x); // fails typechecker, but should pass at runtime | ||
} |
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,3 @@ | ||
In function foo | ||
In function foo | ||
In function foo |
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,3 @@ | ||
<?hh | ||
<<file:__EnableUnstableFeatures("modules")>> | ||
new module foo {} |
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 @@ | ||
<?hh | ||
<<file:__EnableUnstableFeatures("modules")>> | ||
function outside_module(Foo $x) : void { | ||
$x->foo(); // ok | ||
} |
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("modules")>> | ||
module foo; | ||
function separate_file(Foo $x) : void { | ||
$x->foo(); // ok | ||
} |