-
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
add object
type
#8461
Comments
I remember us explicitly not wanting this, but don't remember exactly why... maybe @Wilfred ? |
The situation today: The type checker does have a base type for objects ( I chatted about this briefly with @manzyuk and @andrewjkennedy. I think the view was that there aren't many use cases, and Andrew suggested that you often really want existential types. I'm not aware of any reason we'd explicitly not want this though. It seems fairly innocuous to me. |
this would be really helpful to limit generics to only with interface ServiceContainer {
public function has<T as object>(classname<T> $service): bool;
public function get<T as object>(classname<T> $service): T;
}
interface Factory<T as object> {
public function create(ServiceContainer $container): T;
}
// okay
interface SessionFactory implements Factory<Session> {
...
}
// noop
interface IdFactory implements Factory<string> {
...
} the work around for now would be : interface Service {}
interface ServiceContainer {
public function has<T as Service>(classname<T> $service): bool;
public function get<T as Service>(classname<T> $service): T;
}
interface Factory<T as Service> {
public function create(ServiceContainer $container): T;
}
// okay
interface SessionFactory implements Factory<Session> {
...
}
// noop
interface IdFactory implements Factory<string> {
...
} but this would require all services to implement the |
another usage example is provided in my comment on #5317 |
Resolved by adding |
Hack have a great type system, However it is not currently possible to declare that a function either needs to be passed an object as a parameter, or to declare that a function must return an object.
this feature request proposes that
object
should be used as a parameter type and as a return type. Any object would pass the type check.Passing a value that is not an
object
to a parameter that is declared as typeobject
would fail the type check, and aTypeError
would be thrown.Similarly, if a function is declared as returning an
object
but does not return anobject
, again aTypeError
would be thrown.As it would be used internally,
object
would become a reservedclassname
, unavailable for use as a class name in userland code.Examples
src/Objects/classname.hack
main.hack
object is not generic
if
object
is generics, it would be pointless, as this code :is same as :
meaning, there's no use case for a generic
object
type.covariance/contravariance
The text was updated successfully, but these errors were encountered: