On Thu, Mar 20, 2025 at 9:51 AM Daniel Scherzer <daniel.e.scher...@gmail.com> wrote:
> On Sun, Mar 16, 2025 at 12:31 PM Matt Fonda <matthewfo...@gmail.com> > wrote: > >> Hi Daniel, >> >> I believe this feature essentially amounts to "add methods which can >> never be called", which in my mind makes no sense. If a method types >> against an interface, and that interface uses a method with a never >> parameter type, then we cannot actually call that method. We'd need to know >> the specific concrete type, which defeats the purpose of using an interface >> in the first place. >> > > First, I would point out that I tried to make this limited to methods that > already cannot be called - only to interfaces and abstract methods. You > already can't call those directly, you need to have a subclass. And you can > always type against the implementation with the actual methods that are not > never-typed. > To clarify, what I mean by calling methods on an interface is typing against the interface (for example, as a parameter to a method/function) and then calling methods defined by the interface. As users of the interface, we can call methods on it without knowing or caring which specific subclass we're actually working with. In my mind, this is the entire point of interfaces. We can write code like the following: function foo(SomeInterface $i) { // ... call $i->someMethod(); } Within foo, all we know is that $i is an instance of SomeInterface. We can call any method on $i that SomeInterface defines. If one of those methods had a never argument, then we could never call it. If we did want to call the method with a never argument, then we'd need to know a specific subclass and what type it overrides never with. At that point, we're no longer using the interface; we're instead using the specific subclass, entirely eliminating the need for the interface in the first place. > So I would ask - if not `never` parameters, then what should users do? It > seems like, for the use case of "the interface adds a method but there are > no promises about what parameters it accepts" > If an interface adds a method but makes no promises about what parameters it accepts, then why is it part of the interface in the first place--why add a method that can't be used? Best regards, --Matthew