Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113937 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 78227 invoked from network); 3 Apr 2021 16:32:06 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 3 Apr 2021 16:32:06 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BFE7E1804D8 for ; Sat, 3 Apr 2021 09:30:24 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (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 ; Sat, 3 Apr 2021 09:30:23 -0700 (PDT) Received: by mail-wr1-f41.google.com with SMTP id k8so7203581wrc.3 for ; Sat, 03 Apr 2021 09:30:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=beberlei-de.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=XdU7Ww9Cx8ER5AGzeq64aZypwbTaH+3TlScb+sfEckU=; b=rcZ5KywIhoWtr/Edoz0IeY9p8Anwn2jh8c2aUYZhKGsyxeiaX+WD3nb73AnRkNo4iP /saynEPhhP8hzpDdlQ59Gf6qRBgp9H3R6piPVZ40QjLFkpu83sceimAPUWCaR8fxEfuv LluIbfN7KqbOCFsNV5McrbJ/axMXDNTYrBVkywS61PbMox4wM6LznjpCHeUNfl+/w2TE j4v/XnTpVfoViVygaLr0ypwD5DKxfh79wVhMhWboa6phNT5c4Ies9+Pbjr0LSUWHnzLH EYZ54JAPfMPUMv+7Da3o74SVYD3ov9A2jkBaM8sR0Jk972fZrmsPyvTPnnY2NHQdM2UM ZyHw== 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=XdU7Ww9Cx8ER5AGzeq64aZypwbTaH+3TlScb+sfEckU=; b=QBfUm5V6ZAzJIcT8c+e+UQD0gFKUbNB9jm7RBL5wy5DdxkwEYZ7lPFToRHVgF5ThzO LhfsJwAYxqo7qzeQ9BSKf67+0M/6euQnrjYKy0EZq8AkFDF4fXaxehI1wIhPdsBCZmC8 DA4vtaNal36ckSWMvifwAppV9GDyx5w+rlr0/NqhKu1gCcLXFe8y/+0WiURlL1cUSJ7+ FOTXctJ2p5/D+BIiwRaiIsaBzmCTScz2Q9BPS4iWI56EM/1U/eDsD+b/nj6SrSOlM3cY i3sAlDLp32mT7EahJmNlmGDxhj2IxRmKbj7E9umN9yDltAyo0JAABD9+ZVAeDjQb6/Bn Uuug== X-Gm-Message-State: AOAM5302P02d7oCMeUk5eBgmnIgFgvfvJYg0+i2d/7g3yjdcah+TW6Jq MrqXc2XrbE/2stMHriKx5oK93nP+8EoDg+GO0t92ow== X-Google-Smtp-Source: ABdhPJzYB84EdYvWsInv3/+R8IlLV5ZUBKbhB/pc2ZhzvNNpFlWtoUHs3116E8V3rxkqetodNIfruo//+auwR7rijc8= X-Received: by 2002:a5d:6152:: with SMTP id y18mr20990256wrt.255.1617467420441; Sat, 03 Apr 2021 09:30:20 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sat, 3 Apr 2021 18:30:09 +0200 Message-ID: To: Aaron Piotrowski Cc: Internals Content-Type: multipart/alternative; boundary="000000000000080da805bf13fbe8" Subject: Re: [PHP-DEV] [VOTE] noreturn type From: kontakt@beberlei.de (Benjamin Eberlei) --000000000000080da805bf13fbe8 Content-Type: text/plain; charset="UTF-8" On Sat, Apr 3, 2021 at 5:30 PM Benjamin Eberlei wrote: > > > On Fri, Apr 2, 2021 at 3:14 AM Aaron Piotrowski wrote: > >> >> > On Apr 1, 2021, at 2:03 PM, Levi Morrison via internals < >> internals@lists.php.net> wrote: >> > >> > I do not care which name is chosen, but if we are going to have this >> > sort of thing in the language, it ought to be a bottom type, not an >> > attribute. >> > >> >> You make an excellent point Levi. I initially chose `noreturn` simply >> because I was familiar with the name from C and didn't have a strong >> opinion. However, I agree that `noreturn` is a poor choice for reuse as a >> bottom type, so I changed my vote to `never`. >> > > i voted against this proposal, but changed my choice of "noreturn" to > "never", because it would ultimately be slightly less bad to have this name > for use as a bottom type. The name "never" is still unfortunate, because it > transmits "behavior" of being used in the context of a function, a better > name might have been "nothing" as Levi suggests. > > But I again get to the point of the problem with this RFC due to naming. > "never" is actually combining "nothing" type with "noreturn" flag, so for > me the most consistent way would have been "public noreturn function foo(): > nothing" > Sorry, i should have been more detailed/precise before: Why i think "never" is not a great solution, if you have the same example that TypeScript uses to explain their "never": if (is_string($value) && is_int($value)) { // inside here $value is_type == "never" } The naming "never" here makes no sense, because from a theoretical perspective reasoning about the type of $value it is nothing and only the block of code is "never reached". I suppose PHPStan and Psalm are eager to reuse the new type name for this kind of type interference, same as TypeScript does. The name is sub optiomal outside the context of a return type. So lets say we seperate the two behaviors of "never" into "nothing + noreturn". public noreturn function foo(): nothing { exit(); } But adding a new keyword "noreturn" would not be necessary, it could just be an Attribute as i said in my first e-mail explaining my no-vote: #[NoReturn] // sets a function flag modifying the void behavior public function foo(): nothing { return; // throws if it reaches this point } This would be closer to what Psalm and PHP-Stan use at the moment if we replace nothing with void. The problem is that "void" is already not perfect, since the callside doesn't care about "return null" with no return type vs "return" + void return type. If we had "nothing" and "null" instead of "void", and we'd say like PHP works, "return;" actually means "return null;", then: function foo(): nothing { return; // Error: cannot return null from a function that returns nothing. } function bar(): null { return; // or return null; } This would more consistently tie into union types where |null is allowed, however on its own it is not: "foo() : null => error". As Levi said, this noreturn/never just perpetuates/amplifies the existing void mistake and feels off, given that other recent changes to PHP have been more bold, towards removing inconsistencies. > Its said that composition is better than inheritance, so combining two > behaviors into one keyword will be limiting in the future, if we think of > other function flags that should compose with "never". > > >> Cheers, >> Aaron Piotrowski >> >> --000000000000080da805bf13fbe8--