-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ TypeChecker ] Ban final private
on classes
#8805
Comments
Nice find!
|
Filed T88186581 internally to ban |
final private
methodfinal private
Would this remain supported in traits? The meaning of |
Yes, we’ll continue to support On T88186581, @periodic1236 wrote:
Long term, @periodic1236 advocates for changing both traits and
|
final private
final private
on classes
After doing some work on this, I kinda think we should ban it on traits too. If we only ban final private methods on classes, hh will still accept this code that HHVM rejects: trait MyTrait {
public function foo(): void { $this->bar(); }
final private function bar(): void {}
}
class MyClass {
use MyTrait;
}
class MyChild extends MyClass {
private function bar(): void {}
} @lexidor do you have any opinions here? |
Hmmm, almost all private methods in traits are (or should) final though. Overriding a private trait method is very counterintuitive. The trait author can not call private methods from the the trait without the using class getting a chance to override. |
Linking context from the commit log: c8faa1a |
Exported the trait issue to #9046. Private final is banned on classes, so the title of this issue has been resolved. Closing to minimize noise for people dealing with the trait case. |
Describe the bug
When a base class declares a
final private
method and a child class declares a method with the same name, only the runtime catches this error, the typechecker doesn't catch it.Standalone code, or other way to reproduce the problem
Steps to reproduce the behavior:
Expected behavior
The typechecker should emit an error that you are overriding a final private method of Base.
Actual behavior
The typechecker reports
No errors!
HHVM reports
Fatal error: Cannot override final method Base::privateFinal()
.Environment
Additional context
Either
private final
is an error in and of itself, orChild
is doing something that it should not be allowed to do.The text was updated successfully, but these errors were encountered: