This repository has been archived by the owner on Jun 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pfff] support type constant definitions/declarations
Summary: This is diff 2/2; it adds support for declaring type consts in classes. I'm reusing some of the AST constructs for `type` and `newtype`, and wrapping them in a new type of const declaration. This also adds one or two `%left` precedence thingies, these seem to give ocamlyacc the right idea about "these are not the shift/reduce conflicts you're looking for." It takes us from 5 reported conflicts in the grammar to just the original 1. I'll need to test this change separately to make sure it doesn't cause sadness. Depends on D1880752. Test Plan: make tests # this fails if I add an intentional parse error to good_tconst_decl.php This test case should also cover the syntax introduced in D1880752; please let me know if something looks inadequately covered. Will run this on www when I get to the office. Reviewers: dominik, dreeves Reviewed By: dreeves Subscribers: dominik Differential Revision: https://phabricator.fb.com/D1880760 Tasks: 6358822 Signature: t1:1880760:1425321537:0d8da37962d49d524431d9d04106c5055c8d4ed8
- Loading branch information
Showing
14 changed files
with
132 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
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
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,66 @@ | ||
<?hh | ||
abstract class A { | ||
abstract const type abs_class_by_class as arraykey; | ||
const type TC as arraykey = arraykey; | ||
|
||
final public function __construct ( | ||
private this::abs_class_by_class $id, | ||
) {} | ||
|
||
public function overriding(): Aint::vec { | ||
return Vector {}; | ||
} | ||
|
||
public function getID(): this::abs_class_by_class { | ||
return $this->id; | ||
} | ||
|
||
public function testA(Aint::me::me::me::Aint $x): void {} | ||
} | ||
|
||
interface I { | ||
abstract const type abs_class_by_class; | ||
} | ||
|
||
class Aint extends A { | ||
const type abs_class_by_class = int; | ||
const type me as Aint = Aint; | ||
const type Aint = self::hop; | ||
const type hop = int; | ||
const type vec = ConstVector<int>; | ||
|
||
public function test(): void { | ||
$this->testA(101); | ||
} | ||
|
||
public function overriding(): ImmVector<int> { | ||
return ImmVector {}; | ||
} | ||
} | ||
|
||
class Astr extends A { | ||
const type abs_class_by_class = string; | ||
} | ||
|
||
abstract class B { | ||
abstract const type AType as A; | ||
abstract public static function getAID(): this::AType::abs_class_by_class; | ||
} | ||
|
||
class Bint extends B { | ||
const type AType = Aint; | ||
public static function getAID(): this::AType::abs_class_by_class { | ||
return 0; | ||
} | ||
} | ||
|
||
class Bstr extends B { | ||
const type AType = Astr; | ||
public static function getAID(): this::AType::abs_class_by_class { | ||
return ''; | ||
} | ||
} | ||
|
||
function test(Aint $x): int { | ||
return $x->getID(); | ||
} |