Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113456 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 15165 invoked from network); 10 Mar 2021 21:51:29 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 10 Mar 2021 21:51:29 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 427EE1804D3 for ; Wed, 10 Mar 2021 13:43:50 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-ua1-f44.google.com (mail-ua1-f44.google.com [209.85.222.44]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 10 Mar 2021 13:43:49 -0800 (PST) Received: by mail-ua1-f44.google.com with SMTP id d3so9230uap.4 for ; Wed, 10 Mar 2021 13:43:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=XLSUd/LbF7MvBzW/KP6Enfgjr/J2UZPm0TX1+oKG1xM=; b=N+iROiwyXtWVZ7pwfpWNrIOi7DOQefZTIj06bMZHiOzb4wGfdldayoaf4eukOPdNzI XLZI5fJR97B/DDVVrI2RAbbtmlsyOmE/o6jz8Tsta2pWessXkNDuTo6U1GE4XopzLvbw /3dQvI5Sacdd+gpw6qtlp1uhP/QP2lFcIN+W7AK8FYGldtfXMui3RsiNW6JoNIl9hlcI 6GQB3rkxr9ZPwGc7yZyK3qhx3WO10nxYss004GzlbQ9R+5NTm7cBJOsgx6Hm6Z//F6ZU y0Dw8mNV3Qpj++GkDCZWDhgpX/jMHZcvlFznhbYAntqQINWZGP8BIOCwARKrwnNReBvz joAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=XLSUd/LbF7MvBzW/KP6Enfgjr/J2UZPm0TX1+oKG1xM=; b=ZAihuHftIpX0K2yobVU5I/CbFq7+6QgARIdeS0bEnqRApItJSXgWA+v5Ktohwpv8f/ SCssBzs/zSl5dZUSYiAAoYsarPBmI7I9SsT8vE8q5xSXw/7QovoPdmhbE+GG/DCwQEE2 j/i1IYN1SZDEu02CvcVkAzjj8skdfnnt5jvrfNmXsk+vwT6JBikvj5VTRYGSWG4yjhJn DE7uf38ylb1Kqj8/LB6rRhnX1CcvNkXZ4Gf8q7VqkZPhxu4IXeuMBdE130ln8+BXgfw+ SB+IDWbKGDgdybffAsXL2sFKvz1KSMu0f0vMCqihSwap+73sXdryNDkYaezOCZxOShoP XGrA== X-Gm-Message-State: AOAM533QtFE+6y7w0QiC1SFQ1NMbjiaEWjCD9lUSWyYfNZkQm4rI4S6i A5yFqeZy1FqAiXkyJLSw1pzKGBT4HItVuG//HOo= X-Google-Smtp-Source: ABdhPJz04z3Vcob30Zpud/sJs+ia9vciToYl1E+208U63eFoYZUILxCaVrdjplnlbpBASW6fPde2lHMPAZtg/1FajSY= X-Received: by 2002:ab0:6ce7:: with SMTP id l7mr3357144uai.116.1615412625753; Wed, 10 Mar 2021 13:43:45 -0800 (PST) MIME-Version: 1.0 References: <75a8a0ec-d988-7712-58b5-88c8061db605@gmail.com> In-Reply-To: Date: Wed, 10 Mar 2021 16:43:30 -0500 Message-ID: To: Kamil Tekiela Cc: =?UTF-8?Q?Alexandru_P=C4=83tr=C4=83nescu?= , Rowan Tommins , PHP internals Content-Type: multipart/alternative; boundary="000000000000b949c105bd358f24" Subject: Re: [PHP-DEV] [RFC] noreturn type From: matthewmatthew@gmail.com (Matthew Brown) --000000000000b949c105bd358f24 Content-Type: text/plain; charset="UTF-8" On Wed, 10 Mar 2021 at 16:04, Kamil Tekiela wrote: > I am concerned with some edge cases. What if a function both returns and > throws at the same time? For example: > > function a():noreturn { > return throw new Exception('Boom!'); > } > > or > > function a():noreturn { > try { > throw new Exception('Boom!'); > } finally { > return; > } > } > In both cases those are compile-time errors, since no return is allowed in a function that has the noreturn type. I've added both as tests ( https://github.com/php/php-src/pull/6761/commits/56ae52e84da5c063c28ba7739ac15979e61afc91) but I don't _think_ it's necessary to mention it in the PR given how much of an edge-case it is. > Also, the message "TypeError: a(): Nothing was expected to be returned" is > inaccurate. It should say that the function should terminate instead of > returning. It's also not a TypeError if no value is expected. At the moment > it sounds like we need to make the function somehow return nothing. > It's a TypeError because noreturn is a type, but I agree the error message could be improved. Ilija suggested "noreturn function was expected to throw, terminate or run infinitely" and I'd welcome other suggestions. > If we are to bikeshed about the name then we might also consider other > possibilities: None, Nothing, Returnless > I'd prefer to stick to noreturn and never, which have plenty of precedent in other languages' type systems. --000000000000b949c105bd358f24--