Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127117 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 5A7A61A00BC for ; Tue, 15 Apr 2025 21:29:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1744752421; bh=ZaEtGGgWynZPoHekL6hIIFCKYOzoI4aE5v37tt/qcGU=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=gkCfYsz/ZICQAj7oZbFAvsNOD7N/YsHdr5MYtaGX6Q3LtBIAV3LL2JFSLKJz6Po6T SrCPtexcLTNp7zjILJVGHqJRPBYuUxQAB16Z7GUqcyGPPj8wRSPwfZmKueAMlkz724 07B+rn6sPbBBWvAJ09It1FTzh3RQhLVlh92SWrcgVKvEfCSHkR7v4GbDAsKPBKK1Yo j5WJm46krADvV8EVW/c5eKYA5xkhi+fncF9rodE7fwqgEmaEsdMlpmj3X3JUczKP4y kt/wdiptpZWNh6oQNaOkLodwYO27m06PlukFMzjrX3PSK7h9OPdDZOplrzx3HiB9Ef Db3g9197Y2HYA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 26381180086 for ; Tue, 15 Apr 2025 21:27:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=BAYES_05,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-yw1-f179.google.com (mail-yw1-f179.google.com [209.85.128.179]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 15 Apr 2025 21:26:59 +0000 (UTC) Received: by mail-yw1-f179.google.com with SMTP id 00721157ae682-6f6ca9a3425so71367297b3.2 for ; Tue, 15 Apr 2025 14:29:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dqxtech.net; s=google; t=1744752561; x=1745357361; darn=lists.php.net; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=ZaEtGGgWynZPoHekL6hIIFCKYOzoI4aE5v37tt/qcGU=; b=Qwc7SaDp1pFT1urgphHACgFMgkzDnA36d35fmm7zXtgbqmv5MITlAmLnAZ4hpV5OUK Nr4lifeLHLPNpqtuXVP5XfQcGWYPuLnTmMv9rE8xw9T0/wUDPHZwbGvGnIxUx4Dn6URY wrjb6KEwhqwo/oneG0+kg8xdh4OYVgmcp5rTjrOurk2HX5VowZKrfTzxY7WYGAurHtNm dzyPwwV9X2LndRyw9IO5UFRUMZWg2pMrLrZntfW04EmHpOeenUVBAxsqDcdIEjMAmH+E 1z2GOSknwZaypr92INx3MauR4i5eLC4v+IGqUdRQ+k5WaP8j02WEu8a7DHSpeSuYR4pa Wcqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744752561; x=1745357361; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZaEtGGgWynZPoHekL6hIIFCKYOzoI4aE5v37tt/qcGU=; b=GeqU411nD1Zvj2UM/oNKjkKSmh7gFb2nKTvjJmroWu9FnyWWREeYbB4ob/GYeN4Wmt e3sUEVMdHCLc2XV6lu7iz+KN/JM8kdvoD6J7JK7EhCb/09QAWkX0rQGQ2wBjkhfAQI6W Zf6L6pAI5qPevtCGn1tWbExPwvn1hQwuFybnxeWPmf0VIF5HxyUSXa4+AYfHubSuUgSR /CFpbO8ysHoL039m957JpdegB7/TdlGneyA9UXrZoXI44inF7Q5HJqlW4335qUb/h2u1 FFDWFWkbVTZetdMdeLJyBNry/dciKwJW+3YNBvRAZ/65CzznYZlvmS8paaqMYay3SKHY fMVA== X-Gm-Message-State: AOJu0YxYzHxgrMIgdnSY1Tl5vhmnfXXYiL1hwqzw0ZkWVxLSenoyBB6W sJi7gh05y8cQzvG2d9IHzigLR9sB1Ac7cXQKU+wFP2YTpDgC21i1iNePiD7/n8lNXGWe1EmnIo1 urvm5yZ558yexnFi50pzp2t/OWft/fOEqA7DJqQ== X-Gm-Gg: ASbGncuV1U1pnX/rX0X0QHm9DZyu1tABwaIUGSGgBP0g2Ra4GLtstnjzkvtxW9yfAzo LuwcTcOvLcww935NR3pgXWi+DwTz5uw2i7wrvs+/tv9MneHeU0M9p4qesmAfoqYI3hw2E27ichz V+5yYraVrtRuckc5m34qwPrMU= X-Google-Smtp-Source: AGHT+IFgEUvCjNJlBi2NLPxYqvLVtb91KYR3WXdttlTPnsFkliuJM+2z4prhWRqhUfCGvNqVp07JpCjRP/i36Pg+UkY= X-Received: by 2002:a05:690c:6009:b0:6f9:af1f:fdd0 with SMTP id 00721157ae682-706ad1d8a76mr15099067b3.31.1744752561074; Tue, 15 Apr 2025 14:29:21 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 15 Apr 2025 23:29:09 +0200 X-Gm-Features: ATxdqUG59XFK2C0-xhKoM0MSmxgNClGogRKo1ykvXg9GtHm7xBP44xRtYTakIjo Message-ID: Subject: Re: [PHP-DEV] Re: [RFC] [Discussion] Never parameters To: Daniel Scherzer Cc: internals@lists.php.net Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: andreas@dqxtech.net (Andreas Hennings) On Tue, 15 Apr 2025 at 20:59, Daniel Scherzer wrote: > > On Tue, Apr 8, 2025 at 6:40=E2=80=AFPM Daniel Scherzer wrote: >> >> >> Since a lot of the discussion seems to be around static analysis and whe= ther there is a real use case for this, I wanted to share another use case = I just came across: in the `thephpleague/commonmark` package, different ren= derers are added to render different types (subclasses) of `League\CommonMa= rk\Node\Node`. > > > > I added this example to the RFC page as an example of how this could be u= seful in userland code. Barring further developments, I plan to open the RF= C for voting in a few days. > > -Daniel > Thank you, I have been wanting this since a long time! https://externals.io/message/100275 ---- One interesting application is intersection types. https://externals.io/message/115712#123276 The intersection of different types with "never" parameters and "mixed" return types naturally produces a valid new type: (function(A, never): mixed) & (function(never, B): mixed) & (function(never, never): R) =3D=3D=3D function (A, B): R (imagine all of the above to be interfaces) ---- An interesting question I wonder is whether we would ever want "constrained never" parameters. E.g. currently we can have an interface I with function (A&B), where A and B are classes/interfaces. A sub-interface J that extends I can have function (A) or function (B) or function (mixed) or function (A|SomethingElse). But it cannot have function (C), if neither A nor B extends C. In the same way, for function(int&string), a child method would have to allow at least int or string, e.g. it cannot be function(float) or function(C). (it could be extended as function(int|float) or function(mixed), but not function(float).) So in a way this could be a more suitable parameter type for BackedEnum::from() and ::tryFrom(). For the main part of this RFC we do not need to worry about this. For the BackedEnum::from() and ::tryFrom(), if we change the type to 'never' now, we can no longer change it to int&string later without breaking BC. ---- Another thing I wonder is whether the "Proposal" section needs to more explicitly define the behavior. Can we rely on the "Introduction" part and the examples in other sections, or does the "Proposal" part need to be complete and sufficient by itself? What would we add, and what would be redundant? "A method with a never parameter cannot be called." This already follows from "it cannot be used in the declaration of any method that has an implementation.", so we do not need to explicitly add it. "The never parameter type can only be used standalone, not as part of a union or intersection or nullable type". This might already be specified elsewhere, where never is defined as a return type. "A child class or interface that overrides a method with a never parameter can replace the never parameter type with any other type, or omit the parameter type altogether." This is obvious to us from LSP, but do we need to explicitly define it? It is currently mentioned in "Introduction" but not in "Proposal". "A child class or interface that overrides a method with a never parameter must respect LSP for the other parameters." So, you cannot extend a function(A, never) with function(never, never). I think this is pretty clear from general rules about covariance/contravari= ance. So the only point that might make sense to add is the third one about widening the type. -- Andreas