[swift-evolution] Proposal: Introduce User-defined "Dynamic Member Lookup" Types

Chris Lattner clattner at nondot.org
Sun Dec 10 15:02:20 CST 2017


On Dec 10, 2017, at 12:22 PM, Xiaodi Wu via swift-evolution <swift-evolution at swift.org> wrote:
> The last time I said this, I pointed out that this was a protocol which:
> 
> 1. Has no formal members,
> 2. But imposes informal requirements enforced by the compiler,
> 3. Permits and uses arbitrary overloads, and
> 4. Cannot be usefully used in a generic context or as a type constraint,
> 
> None of which are true of ordinary protocols. Since then, we have added:
> 
> 5. Can only be conformed to in the main declaration.
> 
> This is looking less like a protocol by the day. The square-peg grooves in the round hole are getting deeper and more splintery with every revision.
> 
> Synthesized conformances cannot be declared in extensions either. If you'd like, you could consider that this protocol is one for which the compiler synthesizes an infinite number of members.
> 
> I would like to see (4) addressed: a complete implementation should allow me to call any member on a type T in a generic context where T : DynamicMemberLookupProtocol, which I kind of assumed that this proposal would eventually permit.

The technical problem with this is that there are no witnesses in the protocol witness table - either for the subscripts or for the conceptual associated types of the index and return value of the subscript.

-Chris



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20171210/e196f471/attachment.html>


More information about the swift-evolution mailing list