Re: [RFC] noreturn type

From: Date: Fri, 19 Mar 2021 14:52:54 +0000
Subject: Re: [RFC] noreturn type
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-113619@lists.php.net to get a copy of this message
On Fri, Mar 19, 2021 at 3:45 PM Marco Pivetta <ocramius@gmail.com> wrote:

> Hey Nikita,
>
> On Fri, Mar 19, 2021, 14:35 Nikita Popov <nikita.ppv@gmail.com> wrote:
>
>>
>> Is it allowed to declare a noreturn function that returns by reference?
>>
>> function &foo(): noreturn {}
>>
>
> Given that noreturn means it should throw, loop forever or exit, how
> would a by-ref usage be applied/useful?
>
> Or is it a hint at a missing test?
>

Mainly a hint for missing spec ;)

Context is that we're considering to deprecate by-ref void return (
https://wiki.php.net/rfc/deprecations_php_8_1#return_by_reference_with_void_type),
so it would make sense to me to prohibit this for noreturn from the start.

However, I could also see an argument for why allowing it may be useful due
to variance considerations. It would allow you to write something like this:

<?php
class A {
    public function &test(): int { ... }
}
class B extends A {
    public function &test(): noreturn { throw new Exception; }
}

While dropping the by-ref return on B::test() would be forbidden by
variance (and I don't think we'd want to add more special rules here, like
ignoring ref-return variance for noreturn functions).

Regards,
Nikita


Thread (37 messages)

« previous php.internals (#113619) next »