Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113944 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 18511 invoked from network); 4 Apr 2021 02:30:34 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 4 Apr 2021 02:30:34 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 47B171804DC for ; Sat, 3 Apr 2021 19:28:59 -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=-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_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-ot1-f42.google.com (mail-ot1-f42.google.com [209.85.210.42]) (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 19:28:55 -0700 (PDT) Received: by mail-ot1-f42.google.com with SMTP id 68-20020a9d0f4a0000b02901b663e6258dso8316460ott.13 for ; Sat, 03 Apr 2021 19:28:55 -0700 (PDT) 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; bh=VNKw5GvawFFHbxl1AIZ6qvtowGejpp8oXt3XY4Z+luw=; b=dI6QntihZ/v6aLzCJifX1Np8OEIvg54O71xW/zmA/kmSTkmkeoOdp3a+Ijs7KiLZii DXZVdZBT+yVfrqeluKnZYHiDHSId6Vy1v8k1kHosh/FXDzN80xP/AKf+qBaS+OyVdkrX YhYieWdnLEU5yCMTox5538suwmlF9urI3wgWLbNl37btu33WX4WYg5f2mwEVxv0HFi9H DA0/IoQQ8m4Z8Yg9NKVngfikx/gzXSr8JDrNi/USP8c2eqSbn0J/4muvN0RmGr+R0ETp KaG67Ktok64dyPW72gwYcwMr+aZq5D28EOhq/zfq4lA2+3skfuQxOSqWDyu0gl9rHvAn UBGw== 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; bh=VNKw5GvawFFHbxl1AIZ6qvtowGejpp8oXt3XY4Z+luw=; b=N++zGJt1A+mcihHuJ5L5tHzAo+XeophC1mGBZa8YSWlyXWu5KY84kq0RoWPcwwmxqe rBIWcfj0E94ooSdE2XTmXYBogQwgwPgP3d7H67yvKqfEaxDXYedJ7CtQzFNEehnw6wQ1 jIkg1zRYG2uqKsQPQhViFr+FXgHDY2lGE7gX1S42f8AxyGaPJ74SszaHUeQZjjBhf2Yd n2eNcfEPBf4Iz4PaFkmfr4wu2sUuNsN9puTBEx702HR9Qcp9ZobEzY5rQvcVzKacqjx7 biKFh1DrM+Ur1H/NwHIprM8KZ92WDWyeBOB4POQFAZtQlMBf0+NtPPRC2YiDo4VHeHxw wKdA== X-Gm-Message-State: AOAM532ZL5vi1/7sfs3fw5Os84GEOeoZwpfXAyGfFNCcRu72MoIqZIdM 72kKBRyoYgwk90ZFeJC7ODkGe/sEDU6F4qOvimmG/6OyAJQAuQ== X-Google-Smtp-Source: ABdhPJwFypL5N0MRwqLCm2y57h0fL6X+goRwkH/dYm0sKYhiva3tJI7eLokym/OXIdTzu52iSXBSeTQtzbOKg4i0ijQ= X-Received: by 2002:a9d:7854:: with SMTP id c20mr18107070otm.114.1617503334691; Sat, 03 Apr 2021 19:28:54 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sat, 3 Apr 2021 23:28:41 -0300 Message-ID: To: Internals Content-Type: multipart/alternative; boundary="000000000000aff62605bf1c571a" Subject: Re: [PHP-DEV] [VOTE] noreturn type From: david.proweb@gmail.com (David Rodrigues) --000000000000aff62605bf1c571a Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Just to spice up the discussion a bit, I will try to give my opinion on this RFC... It is very likely that the proposal will be accepted (it is already 33/10), but I still find the terms "noreturn" or "never" unclear. "noreturn" are two words together, and I am not particularly a fan of this type of nomenclature (and it may sound repetitive and strange "return no return"), while "never" can be ambiguous, it could be read as "never return" (OK) or "return never" (and it sounds a little strange, I guess). I saw someone (sorry, I don't remember who) suggesting the term "terminus", so I thought of an alternative like "terminal". Or, if you still want to take advantage of a keyword and without losing the meaning, "exit" (including, it makes absolutely clear what is expected as "return": "return the exit"). Is there any chance of discussing terms, even if the "never" indication is winning at the moment? Or did I miss this discussion? Thanks! Atenciosamente, David Rodrigues Em s=C3=A1b., 3 de abr. de 2021 =C3=A0s 23:07, Matthew Brown escreveu: > On Sat, 3 Apr 2021 at 12:30, Benjamin Eberlei wrote= : > > > > > But adding a new keyword "noreturn" would not be necessary, it could ju= st > > 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 allowe= d, > > however on its own it is not: "foo() : null =3D> error". > > > > As Levi said, this noreturn/never just perpetuates/amplifies the existi= ng > > void mistake and feels off, given that other recent changes to PHP have > > been more bold, towards removing inconsistencies. > > > > > Clearly comparisons of "noreturn"/"never" to "void" are a bit of a > minefield, because a number of contributors feel that void was a mistake, > that its implementation doesn't feel PHP-like. > > While I disagree that our proposal is intrinsically connected with the vo= id > one =E2=80=93 noreturn/never could work equally well with a "null" return= =E2=80=94 our > proposal does perpetuate one idea behind "void": that PHP can benefit fro= m > types found in other languages and type systems, and especially types fou= nd > in Hack. > > It seems like some of the debate is over whether "noreturn"/"never" is a > behaviour or a type. If it were purely a behaviour, with no meaning as a > type, an Attribute would be a much more appropriate location. > > It's not just a behaviour, though =E2=80=94 it is a type that follows var= iance > rules, and it's a type that PHP can check. > > If "void" returns are too much of a distraction, think instead of "object= " > return type declarations: > > When executing the function > > function returnsObject($o) : object { > if (rand(0, 1)) { > return $o; > } > } > > Here PHP's engine checks two separate behaviours > > 1. when the function explicitly returns, does it return an object? > 2. does the function ever finish without returning or throwing or exiting= ? > > Only the first actually involves a strict type check. The second is a > generic behaviour check, triggered by the existence of a return type. Thi= s > is essentially the same check that we want to trigger with > "noreturn"/"never". > > In fact, as someone recently pointed out, running the following code > *today* produces similar errors to the ones we propose: > > function php7Redirect() : noreturn { > if (rand(0, 1)) { > return "bad"; // Fatal error: Uncaught TypeError > } > header("Location: https://php.net"); > exit; // OK > } > > Our RFC makes this code explicitly legal, and adds covariance. Indeed our > implementation is small because it correctly treats "noreturn"/"never" as= a > type, allowing us to use the existing return type handling. > --000000000000aff62605bf1c571a--