Re: [PHP-DEV] [RFC][Discussion] Return Type Variance Checking

2014-11-28 Thread Dmitry Stogov
Hi Levi, if you remember, in my patch return_type was actually stored in arg_info[-1]. it was mainly done for unification and to allow return type hinting for internal functions (they already use arg_info[-1]) So the strictures may be compatible. See https://gist.github.com/dstogov/8deb8b17e41c1a5

Re: [PHP-DEV] [RFC][Discussion] Return Type Variance Checking

2014-11-28 Thread Levi Morrison
> I prefer option (3) - invariant return types. > Actually, return type compatibility check should follow all the rules for > parameter type compatibility check (may be even reuse or share the code). Realistically there isn't much code to share, especially since the two structures are incompatible

Re: [PHP-DEV] [RFC][Discussion] Return Type Variance Checking

2014-11-28 Thread Andrea Faulds
> On 28 Nov 2014, at 12:27, Dmitry Stogov wrote: > > I didn't get what you mean. > parameters are invariant, "invariance, which is safe for both" and " it > shouldn't match parameters" are contradictory. Well, that’s why I said “the exception is invariance”. -- Andrea Faulds http://ajf.me/

Re: [PHP-DEV] [RFC][Discussion] Return Type Variance Checking

2014-11-28 Thread Dmitry Stogov
I didn't get what you mean. parameters are invariant, "invariance, which is safe for both" and " it shouldn't match parameters" are contradictory. Thanks. Dmitry. On Fri, Nov 28, 2014 at 1:57 PM, Andrea Faulds wrote: > > > On 28 Nov 2014, at 09:31, Dmitry Stogov wrote: > > > > I prefer option

Re: [PHP-DEV] [RFC][Discussion] Return Type Variance Checking

2014-11-28 Thread Rowan Collins
Andrea Faulds wrote on 28/11/2014 10:57: On 28 Nov 2014, at 09:31, Dmitry Stogov wrote: I prefer option (3) - invariant return types. Actually, return type compatibility check should follow all the rules for parameter type compatibility check (may be even reuse or share the code). No, it shoul

Re: [PHP-DEV] [RFC][Discussion] Return Type Variance Checking

2014-11-28 Thread Andrea Faulds
> On 28 Nov 2014, at 09:31, Dmitry Stogov wrote: > > I prefer option (3) - invariant return types. > Actually, return type compatibility check should follow all the rules for > parameter type compatibility check (may be even reuse or share the code). No, it shouldn't match parameters, that'd br

Re: [PHP-DEV] [RFC][Discussion] Return Type Variance Checking

2014-11-28 Thread Dmitry Stogov
I prefer option (3) - invariant return types. Actually, return type compatibility check should follow all the rules for parameter type compatibility check (may be even reuse or share the code). This solution may be implemented efficiently and consistently. It also must be enough for 99% use cases.

Re: [PHP-DEV] [RFC][Discussion] Return Type Variance Checking

2014-11-27 Thread Rowan Collins
Levi Morrison wrote on 25/11/2014 17:08: 1. Do covariant return types; check them at definition time 2. Do covariant return types; check them at runtime 3. Do invariant return types; check them at definition time I guess there's also option 4 - do "weak invariance", as we do with para

Re: [PHP-DEV] [RFC][Discussion] Return Type Variance Checking

2014-11-27 Thread Rowan Collins
Lazare Inepologlou wrote on 26/11/2014 10:21: * Parameter types are contravariant, otherwise they are not type sound. Yet, contravariance in general is of little interest (I cannot think of any practical example), so invariance is a good compromise. After reading the Wikipedia article, I've bee

Re: [PHP-DEV] [RFC][Discussion] Return Type Variance Checking

2014-11-26 Thread Stanislav Malyshev
Hi! >> class FooFactory { >> function create(Foo $foo): Foo { return $foo; } >> } >> >> class GooFactory extends FooFactory { >> function create(Goo $goo): Goo { return $goo; } >> } > OK HHVM allows it - we also allow it but trigger an E_STRICT error > @see http://3v4l.org/UhtOb This is b

Re: [PHP-DEV] [RFC][Discussion] Return Type Variance Checking

2014-11-26 Thread Rowan Collins
On 26 November 2014 10:21:12 GMT, Lazare Inepologlou wrote: >http://en.wikipedia.org/wiki/Covariance_and_contravariance_(computer_science)#Covariant_method_return_type Can I just recommend that everyone interested in this discussion read that whole article (at least until it gets into the guts o

Re: [PHP-DEV] [RFC][Discussion] Return Type Variance Checking

2014-11-26 Thread Lazare Inepologlou
2014-11-25 23:42 GMT+01:00 Nikita Popov : > On Tue, Nov 25, 2014 at 11:13 PM, Marc Bennewitz wrote: > > > > > Am 25.11.2014 um 22:43 schrieb Levi Morrison: > > > > On Tue, Nov 25, 2014 at 2:07 PM, Marc Bennewitz > wrote: > >> > >>> I think it's required to do the type check on runtime (Option 2

Re: [PHP-DEV] [RFC][Discussion] Return Type Variance Checking

2014-11-26 Thread Simon Schick
On Tue, Nov 25, 2014 at 11:42 PM, Nikita Popov wrote: > On Tue, Nov 25, 2014 at 11:13 PM, Marc Bennewitz wrote: > >> >> Am 25.11.2014 um 22:43 schrieb Levi Morrison: >> >> On Tue, Nov 25, 2014 at 2:07 PM, Marc Bennewitz wrote: >>> I think it's required to do the type check on runtime (Opti

Re: [PHP-DEV] [RFC][Discussion] Return Type Variance Checking

2014-11-25 Thread Nikita Popov
On Tue, Nov 25, 2014 at 11:13 PM, Marc Bennewitz wrote: > > Am 25.11.2014 um 22:43 schrieb Levi Morrison: > > On Tue, Nov 25, 2014 at 2:07 PM, Marc Bennewitz wrote: >> >>> I think it's required to do the type check on runtime (Option 2) because >>> one of the use cases for return type-hint are

Re: [PHP-DEV] [RFC][Discussion] Return Type Variance Checking

2014-11-25 Thread Marc Bennewitz
Am 25.11.2014 um 23:13 schrieb Marc Bennewitz: Am 25.11.2014 um 22:43 schrieb Levi Morrison: On Tue, Nov 25, 2014 at 2:07 PM, Marc Bennewitz wrote: I think it's required to do the type check on runtime (Option 2) because one of the use cases for return type-hint are factories and such often

Re: [PHP-DEV] [RFC][Discussion] Return Type Variance Checking

2014-11-25 Thread Marc Bennewitz
Am 25.11.2014 um 22:43 schrieb Levi Morrison: On Tue, Nov 25, 2014 at 2:07 PM, Marc Bennewitz wrote: I think it's required to do the type check on runtime (Option 2) because one of the use cases for return type-hint are factories and such often do instantiation in base of unknown string values

Re: [PHP-DEV] [RFC][Discussion] Return Type Variance Checking

2014-11-25 Thread Levi Morrison
On Tue, Nov 25, 2014 at 2:07 PM, Marc Bennewitz wrote: > I think it's required to do the type check on runtime (Option 2) because > one of the use cases for return type-hint are factories and such often do > instantiation in base of unknown string values: > > class MyFactory { > public static

Re: [PHP-DEV] [RFC][Discussion] Return Type Variance Checking

2014-11-25 Thread Marc Bennewitz
I think it's required to do the type check on runtime (Option 2) because one of the use cases for return type-hint are factories and such often do instantiation in base of unknown string values: class MyFactory { public static function factory($name) : AdapterInterface { $class = 'MyN

Re: [PHP-DEV] [RFC][Discussion] Return Type Variance Checking

2014-11-25 Thread Levi Morrison
> It should be mentioned for Option 3 that covariant return types are not > supported just at the definition level . Even with invariant return types the > following is perfectly fine: > class A { > function foo(): B { return new B; } > } > > class B extends A { > function foo(): B { return n