Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113879 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 8571 invoked from network); 31 Mar 2021 13:04:50 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 31 Mar 2021 13:04:50 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B2B081804B7 for ; Wed, 31 Mar 2021 06:02:21 -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,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (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, 31 Mar 2021 06:02:21 -0700 (PDT) Received: by mail-pl1-f170.google.com with SMTP id v23so7865333ple.9 for ; Wed, 31 Mar 2021 06:02:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dqxtech-net.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=+8mP4d98AJEoRgNVHntB2+CpYJpAeSwUWUZy9muMBR4=; b=eOFlMJ57MXhi+/5xQub4o6eLqJ14KwwHuDzBjGIosYDjaT6NfwqM5qGKGZeMe8ojI9 6i5c1pIGyTPos9nZiDVTFRPt/l0I8pk1RZEgJNqOfbLm0FZgjrgwWeFzSJrhy+2IEq4i Bzp1oJuB1bL5uHdPkLP7V46/imyUJ/XB+OpuCiwAJGXGL7azeXRtcGVQXHWu8Lhurrl8 LilSw3Acdp0wNONPiFgSGqw6/y6ouXVptMvVEfe4so6uRUUxrF8DpC+DicnnrrHe37PS JfPJbkufSYsaLnCEtVU+oxu8do+juqB5FuhjMzv/uvqa+twG2anu1u2Zb7F6L8Fsca3M +jFg== 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=+8mP4d98AJEoRgNVHntB2+CpYJpAeSwUWUZy9muMBR4=; b=aWkWZKSdNO16I2vrbQoJnlyRkon81DNDHOiTSj5kFZsXehQmD/gxSi6OpffVzEciKM vuSA9Af69PP6itm8HCULiAIfvH0x8Boox/ikoNOmNv0eGw7RhO0FtH39sYx46CJ4UIl3 lcYqM/NbdyP3jcnnIjFCwvKJ4duH9YW2c/pl2n4NZUmseH9ONBA8QZLS+28wB5G4C+mR Mxf3kJdZV9mTNgZ5DVF+MGTbP1AjX877f7ahI8rJ9D4vWnI9LGU3QF2xQgfZbOyDgEkT mkGM+pHcv6h5XfIq/fjul9tLsg3WfEdv//FKZO7RY2tDu++Re4UjKpAH9wIBHZzg/pzU gMwA== X-Gm-Message-State: AOAM5333NLdReO4J2CK3J+t1ATAKBQ4mJtUeShxWKWXv2MP+AimfxFoW OaAe9KwUkKN6EGjhd6Pw2pWCJRYtDQSwtTrI0MbOaw== X-Google-Smtp-Source: ABdhPJxU15ZWGJVIw0zF3IACuEq/YXJRthxYetOxPMfIIi0SCKkY/eQhJtJDP+LFZGCusmJ5XnipWs90bH/4WPabJzE= X-Received: by 2002:a17:90a:f40f:: with SMTP id ch15mr3456561pjb.128.1617195736335; Wed, 31 Mar 2021 06:02:16 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 31 Mar 2021 15:02:05 +0200 Message-ID: To: Ilija Tovilo Cc: Internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] [VOTE] noreturn type From: andreas@dqxtech.net (Andreas Hennings) On Wed, 31 Mar 2021 at 14:41, Ilija Tovilo wrote: > > Hi internals > > On Wed, Mar 31, 2021 at 2:14 PM Andreas Hennings wrote: > > > > Also check my comment in the other thread: > > If in the future we want a "bottom type" that also works for parameters > > (generics or abstract methods), should we create a new keyword, or should > > we attempt to find a keyword now that works for all cases? > > Neither "never" nor "noreturn" seems suitable for use in parameters, but > > "nothing" would be. > > While slightly misleading, noreturn absolutely could work as a > parameter type, it's just not part of this RFC. Technically any keyword would be "suitable" in parameters. But having "noreturn" as a parameter type would look weird. I think we should decide now if the new keyword should be suitable as a parameter type name in the future or not. > I don't see why nothing would be more suitable than never. For me "nothing" looks a bit more like a type name than "never". But seeing in your link that this already exists in typescript, I can live with "never" :) To your example below: For me the real use case would be formal interfaces or base classes. Ofc this will become more relevant with generics, but can already be useful now with reflection-based architectures. interface FormalHarvester { function harvest(never $x); } interface GraintHarvester extends FormalHarvester { function harvest(Grain $x); } So, if we introduce the "never" keyword now as a return type, with this future use case in mind, that seems to be fine for me. > > > I do think noreturn/never in parameter types could potentially be > useful as it would serve as static analysis information and a runtime > check at the same time. > > https://stackoverflow.com/a/39419171/1320374 > > ``` > function shouldNotHappen(never $never): void {} > > /** @param 1|2|3 $foo */ > function foo($foo) { > switch ($foo) { > case 1: return 'One'; > case 2: return 'Two'; > } > > // Static analyzer can understand this value is not never but 3 > // Throws a type error at runtime when reached as nothing can satisfy never > shouldNotHappen($foo); > } > ``` > > Although it's worth noting that match doesn't have that problem as it > throws implicitly on unhandled values. So maybe we should focus our > efforts on making match usable with code blocks instead of just > expressions. > > Ilija > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php >