Add default parameter support (_e.g._, `file:line:`) to dynamic member lookup

I filed a GitHub issue but it was suggested this might need to go through evolution.

Can file:line:-line default parameters be added to dynamic member lookup subscripts? It'd be super useful for surfacing the source context of an issue through to the dynamic caller in question.


I would find this very useful too, big plus 1


In general it would be nice to loosen the requirements around the dynamic member lookup. Right now it fails with subscript<T>(dynamicMember: KeyPath<Self, T>) but succeeds with subscript<T>(dynamicMember dynamicMember: KeyPath<Self, T>) which seems more specific than any other lookup I've seen. Being able to apply the general shape of the simple lookup with other defaulted parameters would be nice.

1 Like

Isn't this just a product of the fact that subscript<T>(dynamicMember: KeyPath<Self, T>) declares a subscript whose external name is subscript(_:)? You're allowed to rename the (inner) parameter name as you see fit for dynamic member lookup, so I wouldn't want it to be the case that any unlabeled subscript which accepts a String (or KeyPath) argument to be considered a 'match' for the purposes of dynamic member lookup.


Ah yes, I forgot that the subscript naming rules are different from funcs.


Yeah, that's its own can of worms, taking the naming rules for subscripts as given I think the 'matching' here is behaving appropriately.


Beyond DML, I think it'd be nice to extend file:line: support to otherwise protocol conforming methods.

This is very much related to the desire I've had for several years that operator functions should accept file: and line: for capturing point-of-use info.


This is the best argument I’ve seen thus far that these shouldn’t be represented as parameters, because the calling convention for a protocol method doesn’t have any place to put extra parameters. :-( Then again, sometimes you do want to propagate file/line info, so simply doing something besides parameters wouldn’t necessarily work either.