Skip to content
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

Feature request: object-protected and object-private access modifier #7574

Open
acrylic-origami opened this issue Jan 1, 2017 · 1 comment

Comments

@acrylic-origami
Copy link

acrylic-origami commented Jan 1, 2017

HHVM Version

$ hhvm --version
HipHop VM 3.16.0-dev (rel)

Standalone code, or other way to reproduce the problem

For the moment, private parameters and methods can use variant parameters in any position. private is also the only access modifier that allows these otherwise illegal definitions, but as pointed out in #7216 , it isn't actually typesafe. Instead, Scala's "object-private" and "object-protected" access modifiers would make such declarations sound. Object-private is purely stricter than the current scheme, so the advantage is solely for type safety.

However, object-protected brings something new and powerful, especially with properties. I've found it cumbersome, and sometimes impossible, to cleanly extend classes with variant parameters in properties, because there is no way to interact with them in the subclass in the opposite direction of their variance. For example, #7573 would actually ideally be solved by making ImmutableWrapper::collection object-protected.

The same is true of generic methods. object protected as a method access modifier would allow subclasses to override parent definitions of reused internal methods to refine the functionality.

An admittedly artificial but still demonstrative culminating example:

<?hh // strict
interface Tracker<T> { public function track(T $v): void; }
class CovWrapper<+T> {
	public function __construct(
		object protected T $v
		) {
		$this->set($v);
	}
	object protected function set(T $v): void {
		$this->v = $v;
	}
}
class TrackedWrapper<+T> extends CovWrapper<T> {
	public function __construct(
		object protected Tracker<T> $tracker,
		T $v
		) {
		parent::__construct($v);
	}
	<<__Override>>
	object protected function set(T $v): void {
		$this->tracker->track($v);
		parent::set($v);
	}
}

andrewjkennedy mentioned that this might come to Hack eventually. Any guesses as to when if ever?

@lexidor
Copy link
Collaborator

lexidor commented Oct 5, 2023

A subset of this feature request is tracked as hhvm/hhast#549.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants