Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113465 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 57372 invoked from network); 11 Mar 2021 08:32:05 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 11 Mar 2021 08:32:05 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 53A6A1804DD for ; Thu, 11 Mar 2021 00:24:33 -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=-0.2 required=5.0 tests=BAYES_40,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, 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-yb1-f174.google.com (mail-yb1-f174.google.com [209.85.219.174]) (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 ; Thu, 11 Mar 2021 00:24:32 -0800 (PST) Received: by mail-yb1-f174.google.com with SMTP id u75so20823575ybi.10 for ; Thu, 11 Mar 2021 00:24:32 -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 :content-transfer-encoding; bh=7949UApvavIJv3n0moq4FvdUsZrBvZRFXPpaKQXJxY8=; b=ZI/sB/guj9e/GZ8NErbh9rYJQIhQNnSRkQYzCKKvs2/l3Xvq5Cm1LIMsKQXxyN317T 8xmbxkhdftSWTzVCJQ5DXfEnpBE2+angbxtnrtkkubpZMDse+U2AYlsszV8jkbvuuRSN O8llqZIBAsqBB9/zkuX5wd9U5GyGUyS99gL93+M7llCOCp3sKPyyZ6RQBPJsMFnKEhux vBwoCf2VyRT07W52fkODdjpsA92wsCGs+ZgJBZJt2i2sjRZm0PolDSOUEoKwTTR7vjdd 9skAMOq/MCLT+/BTaSjsafPenIK1GKFfc/seXsBlrPDN+r2MqrSqcaaZitL7wr84S37v nU2Q== 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:content-transfer-encoding; bh=7949UApvavIJv3n0moq4FvdUsZrBvZRFXPpaKQXJxY8=; b=r/bnuvulThhl3NbMFNJgywds544AqY8beT6O1mR5IUF10uYiIzoTRBorKxSjW/fOPc RP9FnRCwscvyNfFxuyUWNz0FpUetXaNDpsxsYWbh8seO1BM1kUEBRfzwTbf9l5GAeavk xy7+OYGjLovs2mLqc7OCP+ApXT8VSx0nUzlHFT7LGkMvbGIetUS4/olQDfZJ2BNY4Gwt dNZGphy1B0L97RGpaxd0jnZPg7MXg+DDEzBTwjyXsbUWAX01VIHKuh7N4mmDJySJ/q7N NDwVlHg5Nq3H8ndvbb8nkr409gKHhaGlI8UyWL2RC7re3TIjtqejVB9gdGr2jhNklFTU MLJQ== X-Gm-Message-State: AOAM533gWuVGe346IjhI52L0GHJG4dZjcGLcu9iwIscG6qhf/ah2Ew2Z k5RB0FrFAg8TeDXrxlmAx+fYtxTu7hP/HJafL0Hj/dg7V35O9w== X-Google-Smtp-Source: ABdhPJy1JSov4cCz4aP9rfgVA6WYjy7EzwQghlTxFf926SyB0T+IoZJjeruINJ+UjymJPyK8xQivRdp905cwzxkJxaY= X-Received: by 2002:a25:f805:: with SMTP id u5mr9640796ybd.2.1615451069955; Thu, 11 Mar 2021 00:24:29 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 11 Mar 2021 09:24:18 +0100 Message-ID: To: PHP internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] noreturn type From: tovilo.ilija@gmail.com (Ilija Tovilo) Hi Aleksander > I see it's a subtype, I don't get why. Wouldn't it be better to be a > separate type so return type covariance is not allowed (as it is with > void)? Was it a design decision or a side product of the implementation? This is a fairly common technique. For example, this is from the TypeScript handbook: https://www.typescriptlang.org/docs/handbook/basic-types.html#never > The never type is a subtype of, and assignable to, every type; however, n= o type is a subtype of, or assignable to, never (except never itself). Even= any isn=E2=80=99t assignable to never. Imagine the following scenario: function foo(callable(): int $computeSomething) { $magicNumber =3D $computeSomething(); } function bar(): noreturn { throw new Exception('bar'); } // Is completely type-safe as $magicNumber will never be assigned foo('bar'); // Without noreturn being a bottom type you'd have to do this foo(function(): int { bar(); }); We don't have callable types yet but it's common in other languages. The point is that, since noreturn will throw, terminate or never end, $magicNumber will never be assigned. This means effectively the return type of any function can be safely substituted with noreturn. The other benefit is that you can accurately typehint an overridden method. class Foo { function baz(): int { return 42; } } class Bar extends Foo { function baz(): noreturn { throw new Exception(); } } $bar =3D new Bar(); $bar->baz(); // IDE will know this always terminates qux(); // Dead code Not every language allows this but it does make sense semantically. It's not a deal breaker if we don't have it but given that the implementation is fairly simple I don't see why we wouldn't. Ilija