[swift-evolution] [RFC] #Self
Timothy Wood
tjw at me.com
Tue May 10 17:41:52 CDT 2016
> On May 10, 2016, at 2:01 PM, Chris Lattner via swift-evolution <swift-evolution at swift.org> wrote:
> That said, I’m not sure I understand the concrete use-cases. When is this concept important? When is “Self” not good enough?
From my old mail on the subject:
> I would love to see a way to get the type of the "enclosing thing at compile time”. In my particular case, I’m using the type as a generic parameter to tag a created resource with something like:
>
> class Client: PropertyOwner {
> let intProperty = Client.property(“name”, Int(0))
> }
>
> where PropertyOwner has a static property<Owner, DataType>(...)
>
> With `Self` meaning the static version of the thing being compiled, I could at least write:
>
> class Client: PropertyOwner {
> let intProperty = Self.property(“name”, Int(0))
> }
>
> which would have the benefit of being harder to mess up due to copy-pasting between different PropertyOwner implementors.
and
> I was thinking about the syntax a bit further and it seems like the capability that would be added is like #file, in that it does some compile-time textual replacement. So, perhaps #Self would work?
>
> Also, along these lines, I would find use for call-site interpolation like #file has. I could then do a free function version of my property() call that was something like:
>
> func property(ownerType: PropertyOwner.Type = #Self, ...) { }
>
> which would only be callable from w/in things conforming to or subclassing PropertyOwner.
-tim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160510/2b88e0a3/attachment.html>
More information about the swift-evolution
mailing list