-
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.
Disallow override of async by non-async
Summary: There is a consensus on the Hack Pack workchat that it's a mistake for Hack to allow `async` methods to be overridden by non-async methods that return `Awaitable`. This pattern is a problem for Sound Dynamic pessimisation, as it is an example of an override that doesn't preserve enforcement (as an `async` method returning `Awaitable<int>` enforces `int` but a non-async method only enforces `Awaitable`). Let's outlaw this in Hack. A separate diff for www asyncifies the ~220 instances of this pattern in www. Reviewed By: vassilmladenov Differential Revision: D38940712 fbshipit-source-id: 64b0e3d63feeff4a945486307e3ddee15984ef9d
- Loading branch information
1 parent
e3daa15
commit 415b6f8
Showing
8 changed files
with
77 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?hh | ||
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary. | ||
|
||
class C { | ||
public async function foo():Awaitable<int> { | ||
return 3; | ||
} | ||
public function boo():Awaitable<int> { | ||
return $this->foo(); | ||
} | ||
} | ||
class D extends C { | ||
public async function bar():Awaitable<int> { | ||
return 4; | ||
} | ||
// Illegal: do not permit non-async methods to override async ones | ||
public function foo():Awaitable<int> { | ||
return $this->bar(); | ||
} | ||
// Legal: allow async methods to override non-async ones | ||
public async function boo():Awaitable<int> { | ||
return 5; | ||
} | ||
} |
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 @@ | ||
File "async_override_bad.php", line 17, characters 19-21: | ||
The method `foo` is not compatible with the overridden method (Typing[4341]) | ||
File "async_override_bad.php", line 17, characters 19-21: | ||
You cannot override this method with a non-async method | ||
File "async_override_bad.php", line 5, characters 25-27: | ||
It was declared as async |