Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113641 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 96972 invoked from network); 20 Mar 2021 18:51:22 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 20 Mar 2021 18:51:22 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A7E7C1804C0 for ; Sat, 20 Mar 2021 11:46:11 -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_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-f46.google.com (mail-ua1-f46.google.com [209.85.222.46]) (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, 20 Mar 2021 11:46:11 -0700 (PDT) Received: by mail-ua1-f46.google.com with SMTP id r8so245306ual.9 for ; Sat, 20 Mar 2021 11:46:11 -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 :cc; bh=ATwzYtitf/Y8nwjdAbz+c9ap5J7JHJmfWFOJyXm+ujg=; b=hb8EnsizQyaC6FbOP8C0gNlgKdFsg6rqI+CVn/9IpWgFM2fRgMDT8PczaCChnYD0qD PwHLlpPkAlmpZv6jyinwrwbj3UjHkQMRGtzgoNZfWlQbEOfah98CjT09jdr0skVi8pZk CH1JTBX4GtDTqr7KjpbSFx9ScUXoEse9fVUIhLzXTWv9vrVougGbpeDleGKvUlRMBQ99 +bGnN8XYoWu0fG9X/qaVCl6aaVcyZDwo6TF/VP3j45eMRCJwZly39Wq/bts5BUG86Ckc UbTzUttqQEdBjxXasZfyGTUEDGOZLZcHeFHsTbAltaWJcUL680TvmzNF84bDBZeT4prJ gJ3w== 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=ATwzYtitf/Y8nwjdAbz+c9ap5J7JHJmfWFOJyXm+ujg=; b=IhOqxbBKv41nDqUUiJ3qXlZ89p4+a9UnvKSUoTPTawGU+nj8MBaKQaTJB2QFjk0aeH em4Tg7ooqvJmYHNmyp39duRdpe34DXxT50toxSMl9f5WYOkGDk+qL1uGnaBjW5V3euLA dvMcqfF4qh5Au5zCxvN4zYTN6c2AxAW2tWkG9p5gJLwkv/Vl9zaGc0/KmIXKibczB28Q xn4srue6Dzo5UB11bVxIYKtrk5gKjfniYIvJU4vOkw4Xe6LENwkGLiFA44PgSWvv6VLT epZTjdsF7aLFEmeb6pLqPn7/dRNrhU+n+d57XOvnQZtEibLb2bgL9zSh5s0tTDMbHWpm ge/Q== X-Gm-Message-State: AOAM531+GET2Li/q8BQd/iFhVJ9QKgSZDe1A0t3YDRQc3PzoxSOGpvU1 IALaWD5F4TAQ4q+McgSMY09BIWsx/hNlkDgGnOWVNADyzaPU8w== X-Google-Smtp-Source: ABdhPJzHt1R4Sex0kIkbR929VZy56u1QHQDZRN2uZDIcMarq8P6emwcx/qjPrIFNe4L2dDX+ZcPfWAINcPo0+kz9Ujc= X-Received: by 2002:ab0:30d4:: with SMTP id c20mr1862485uam.86.1616265970457; Sat, 20 Mar 2021 11:46:10 -0700 (PDT) MIME-Version: 1.0 References: <96b4b678-6605-4b9b-a493-e4c9adfc11d5@www.fastmail.com> In-Reply-To: <96b4b678-6605-4b9b-a493-e4c9adfc11d5@www.fastmail.com> Date: Sat, 20 Mar 2021 14:45:59 -0400 Message-ID: To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="00000000000008201305bdfc3f52" Subject: Re: [PHP-DEV] [RFC] noreturn type From: matthewmatthew@gmail.com (Matthew Brown) --00000000000008201305bdfc3f52 Content-Type: text/plain; charset="UTF-8" On Sat, 20 Mar 2021 at 11:35, Larry Garfield wrote: > My main concern is around the covariance of inheritance. The example > given: > > abstract class Person > { > abstract public function hasAgreedToTerms(): bool; > } > > class Kid extends Person > { > public function hasAgreedToTerms(): noreturn > { > throw new \Exception('Kids cannot legally agree to terms'); > } > } > > While that may be technically correct from a type theory perspective (my > type theory isn't strong enough to say either way), I don't feel like that > obeys Liskov. It absolutely obeys Liskov, because noreturn is the subtype of all subtypes, aka the bottom type. > If I have an array of Person objects, and I iterate them to check if > they've all agreed to terms, I expect the return value to be a *usable* > type in the Person interface or a subtype of it *that I can still use*. I > cannot use Kid::hasAgreedToTerms's return type, because it's by definition > non-existent. Luckily your program will never have the chance to use its return type, because calling the method throws an exception. > That feels like a bad time bomb. > You might, in this scenario, add a `@throws` docblock and hope some sort of static analysis rule might catch the time bomb Another way that you can think of this is with throw expressions. The ternary in the function below is supposed to return `string`, or a subtype of `string` (the literal string "hello" is a subtype of `string`). The types are valid here if the type of `throw new Exception...` is treated as `noreturn`, and if `noreturn` is a subtype of `string`. ``` Other than that concern, I'm fine with the spec. I would marginally > prefer "never" over "noreturn", but not enough to vote against it just for > that. > There will be a separate vote for noreturn vs never! > > --Larry Garfield > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > > --00000000000008201305bdfc3f52--