Re: [PHP-DEV] [RFC] Never For Argument Types

2024-05-08 Thread Andreas Hennings
Hello list, to revive this old RFC. One really nice application of never parameters is with intersection types: interface I {} interface ReturnI { public function foo(never $x): I; } interface AcceptI { public function foo(I $x): mixed; } function f(ReturnI $arg, I $x): I { return

Re: [PHP-DEV] [RFC] Never For Argument Types

2021-09-08 Thread Andreas Hennings
On Sat, 14 Aug 2021 at 15:05, Larry Garfield wrote: > > On Sat, Aug 14, 2021, at 7:48 AM, G. P. B. wrote: > > On Sat, 14 Aug 2021 at 10:55, Deleu wrote: > > > > > Hi Jordan, > > > > > > Does it make sense to explain in the RFC the difference between never and > > > mixed in this context? The RFC

Re: [PHP-DEV] [RFC] Never For Argument Types

2021-08-21 Thread Jordan LeDoux
Hey all, Thanks for the feedback and the engagement on this RFC. I'll be withdrawing this RFC as it's clear that its drawbacks are too large for the benefits it does provide from internals' perspective. Essentially, I saw a very small and safe change that could be made to the engine that would

Re: [PHP-DEV] [RFC] Never For Argument Types

2021-08-16 Thread Jordan LeDoux
On Mon, Aug 16, 2021 at 12:51 AM Nikita Popov wrote: > We have a better way to specify markers for the engine: Magic methods. I > think some people have a mistaken notion that engine-integrated interfaces > are always better than magic methods. This is only the case if such > interfaces are

Re: [PHP-DEV] [RFC] Never For Argument Types

2021-08-16 Thread Faizan Akram Dar
On Aug 16 2021, at 1:21 pm, Nikita Popov wrote: > On Sat, Aug 14, 2021 at 3:44 PM Jordan LeDoux > wrote: > > > > > > > On Sat, Aug 14, 2021 at 6:25 AM Nikita Popov wrote: > > > >> > >> function addMultiple(CollectionInterface $collection, mixed ...$inputs): > >> void { > >> foreach ($inputs as

Re: [PHP-DEV] [RFC] Never For Argument Types

2021-08-16 Thread Nikita Popov
On Sat, Aug 14, 2021 at 3:44 PM Jordan LeDoux wrote: > > > On Sat, Aug 14, 2021 at 6:25 AM Nikita Popov wrote: > >> >> function addMultiple(CollectionInterface $collection, mixed ...$inputs): >> void { >> foreach ($inputs as $input) $collection->add($input); >> } >> >> A static analyzer

Re: [PHP-DEV] [RFC] Never For Argument Types

2021-08-15 Thread Jordan LeDoux
On Sun, Aug 15, 2021 at 4:06 PM Alexandru Pătrănescu wrote: > Hey Jordan, > > From type perspective, this sounds good. > > But, in my view, types should be checked statically. > For inheritance, when defining a method, both the parameters and return > types are nicely checked statically and

Re: [PHP-DEV] [RFC] Never For Argument Types

2021-08-15 Thread Mike Schinkel
> On Aug 15, 2021, at 7:06 PM, Alexandru Pătrănescu wrote: > > If I see an interface that was created just so it can be implemented by > multiple classes but the caller doesn't use the interface but it uses the > actual classes, I call it out as that is the wrong abstraction and the > interface

Re: [PHP-DEV] [RFC] Never For Argument Types

2021-08-15 Thread Alexandru Pătrănescu
On Sat, Aug 14, 2021, 01:27 Jordan LeDoux wrote: > Hey internals, > > I've been working on the draft for my operator overloading RFC, and in > doing so I encountered a separate change that I would like to see. > > That is, the use of `never` as an argument type for interfaces. Since > arguments

Re: [PHP-DEV] [RFC] Never For Argument Types

2021-08-15 Thread Lynn
On Sun, Aug 15, 2021 at 1:11 PM Jordan LeDoux wrote: > > So your intuition is correct. `foo(never $something)` will result in a > `TypeError` if you try to call it directly. The only way it can be called > is by being overridden with a wider type, which is why most of the focus is > around

Re: [PHP-DEV] [RFC] Never For Argument Types

2021-08-15 Thread Jordan LeDoux
On Sun, Aug 15, 2021 at 3:43 AM Lynn wrote: > On Sat, Aug 14, 2021 at 1:27 AM Jordan LeDoux > wrote: > >> >> Any feedback is greatly appreciated. >> > > https://github.com/JordanRL/never-argument-type > > > My only feedback is that it should not be called `never`. If I see `never` > as the

Re: [PHP-DEV] [RFC] Never For Argument Types

2021-08-15 Thread Deleu
On Sun, Aug 15, 2021, 12:43 Lynn wrote: > My only feedback is that it should not be called `never`. If I see `never` > as the parameter type, I read this as never being allowed to pass anything, > which means that `foo('something')` with `foo(never $something)` will > result in a compile error.

Re: [PHP-DEV] [RFC] Never For Argument Types

2021-08-15 Thread Lynn
On Sat, Aug 14, 2021 at 1:27 AM Jordan LeDoux wrote: > > Any feedback is greatly appreciated. > https://github.com/JordanRL/never-argument-type My only feedback is that it should not be called `never`. If I see `never` as the parameter type, I read this as never being allowed to pass

Re: [PHP-DEV] [RFC] Never For Argument Types

2021-08-15 Thread Jordan LeDoux
On Sun, Aug 15, 2021 at 1:25 AM Ondřej Mirtes wrote: > It’s true that having “never” in a parameter type (please use “parameter” > name for the method declaration, “argument” is what you pass to a parameter > when you call the method) would allow to use any type in an overriding > method from

Re: [PHP-DEV] [RFC] Never For Argument Types

2021-08-15 Thread Ondřej Mirtes
It’s true that having “never” in a parameter type (please use “parameter” name for the method declaration, “argument” is what you pass to a parameter when you call the method) would allow to use any type in an overriding method from contravariance/LSP point of view. But at the same time the

Re: [PHP-DEV] [RFC] Never For Argument Types

2021-08-14 Thread Mike Schinkel
> On Aug 14, 2021, at 10:40 AM, Jordan LeDoux wrote: > > Never is treated as the bottom type for the purpose of Liskov substitution > already with its use as a return type. The exception to this in its use as > a return type is that it isn't treated as the union identity in the return > type.

Re: [PHP-DEV] [RFC] Never For Argument Types

2021-08-14 Thread Jordan LeDoux
On Sat, Aug 14, 2021 at 10:12 AM Claude Pache wrote: > > If users of that interface would suddenly be *required* to specify a > parameter type, whereas previously they were *forbidden* to specify one, > except a meaningless `mixed`... it would be not nice and useless. > > Moreover, note that

Re: [PHP-DEV] [RFC] Never For Argument Types

2021-08-14 Thread Claude Pache
> > On Fri, 13 Aug 2021 at 19:27, Jordan LeDoux wrote: > >> Hey internals, >> >> I've been working on the draft for my operator overloading RFC, and in >> doing so I encountered a separate change that I would like to see. >> >> That is, the use of `never` as an argument type for

Re: [PHP-DEV] [RFC] Never For Argument Types

2021-08-14 Thread Matthew Brown
Hey! Using the "never" type to require that downstream libs specify a type does not make intuitive sense to me, because the same is not true the other way (covariantly) for return types. The existence of a "never" type on an overriding method does not require that upstream libs specify a return

Re: [PHP-DEV] [RFC] Never For Argument Types

2021-08-14 Thread Jordan LeDoux
The RFC has been moved to the wiki: https://wiki.php.net/rfc/never_for_parameter_types The most critical points of discussion in my mind are: 1. Should never require **explicit** widening as discussed? This could be very useful but would make it the only case in PHP where omitting a type is not

Re: [PHP-DEV] [RFC] Never For Argument Types

2021-08-14 Thread Jordan LeDoux
On Sat, Aug 14, 2021 at 7:01 AM AllenJB wrote: > > Whilst I understand there's a historical aspect to the keyword naming > used in this RFC, as a PHP developer, I think the use of "never" here is > going to be confusing to people when considered along-side the never > return type. > > I think it

Re: [PHP-DEV] [RFC] Never For Argument Types

2021-08-14 Thread G. P. B.
On Sat, 14 Aug 2021 at 16:01, AllenJB wrote: > This RFC only considers this feature for arguments. Why is it also not a > valid feature for return types? I think it might be useful for abstract > classes and interfaces (for example, the Iterator interface) to force > implementers to specify a

Re: [PHP-DEV] [RFC] Never For Argument Types

2021-08-14 Thread AllenJB
On 14/08/2021 00:27, Jordan LeDoux wrote: Hey internals, I've been working on the draft for my operator overloading RFC, and in doing so I encountered a separate change that I would like to see. That is, the use of `never` as an argument type for interfaces. Since arguments in PHP are

Re: [PHP-DEV] [RFC] Never For Argument Types

2021-08-14 Thread Jordan LeDoux
On Sat, Aug 14, 2021 at 6:25 AM Nikita Popov wrote: > > function addMultiple(CollectionInterface $collection, mixed ...$inputs): > void { > foreach ($inputs as $input) $collection->add($input); > } > > A static analyzer should flag this CollectionInterface::add() call as > invalid, because

Re: [PHP-DEV] [RFC] Never For Argument Types

2021-08-14 Thread Nikita Popov
On Sat, Aug 14, 2021 at 1:27 AM Jordan LeDoux wrote: > Hey internals, > > I've been working on the draft for my operator overloading RFC, and in > doing so I encountered a separate change that I would like to see. > > That is, the use of `never` as an argument type for interfaces. Since >

Re: [PHP-DEV] [RFC] Never For Argument Types

2021-08-14 Thread Deleu
On Sat, Aug 14, 2021, 14:48 G. P. B. wrote: > On Sat, 14 Aug 2021 at 10:55, Deleu wrote: > >> Hi Jordan, >> >> Does it make sense to explain in the RFC the difference between never and >> mixed in this context? The RFC vaguely mentions that never can never be >> used directly, but if it's

Re: [PHP-DEV] [RFC] Never For Argument Types

2021-08-14 Thread Larry Garfield
On Sat, Aug 14, 2021, at 7:48 AM, G. P. B. wrote: > On Sat, 14 Aug 2021 at 10:55, Deleu wrote: > > > Hi Jordan, > > > > Does it make sense to explain in the RFC the difference between never and > > mixed in this context? The RFC vaguely mentions that never can never be > > used directly, but if

Re: [PHP-DEV] [RFC] Never For Argument Types

2021-08-14 Thread G. P. B.
On Sat, 14 Aug 2021 at 10:55, Deleu wrote: > Hi Jordan, > > Does it make sense to explain in the RFC the difference between never and > mixed in this context? The RFC vaguely mentions that never can never be > used directly, but if it's limited to abstract class and interfaces, isn't > that

Re: [PHP-DEV] [RFC] Never For Argument Types

2021-08-14 Thread Deleu
Hi Jordan, Does it make sense to explain in the RFC the difference between never and mixed in this context? The RFC vaguely mentions that never can never be used directly, but if it's limited to abstract class and interfaces, isn't that already impossible to use directly? Or does it mean that the

[PHP-DEV] [RFC] Never For Argument Types

2021-08-13 Thread Jordan LeDoux
Hey internals, I've been working on the draft for my operator overloading RFC, and in doing so I encountered a separate change that I would like to see. That is, the use of `never` as an argument type for interfaces. Since arguments in PHP are contravariant to preserve Liskov substitution,