> On Sep 15, 2017, at 3:45 PM, Joanna Carter via swift-evolution
> <[email protected]> wrote:
>
> Just came across this.
>
> I want to be able to hold onto the reference to a subscript "method" for
> later use.
>
> Assigning the subscript to a var in the init of a type raises a segmentation
> fault.
>
> Should this - could this - be allowed?
It really shouldn't be allowed. I think KeyPaths are the intended language
solution here.
Please file a bug about the crash, though.
John.
>
> protocol DataProvider
> {
> associatedtype ItemType
>
> subscript(index: Int) -> ItemType { get }
> }
>
> struct AnyDataProvider<providerType: DataProvider> : DataProvider
> {
> private var _subscript: (Int) -> providerType.ItemType
>
> subscript(index: Int) -> providerType.ItemType
> {
> return _subscript(index)
> }
>
> init<P : DataProvider>(_ base: P) where P.ItemType == providerType.ItemType
> {
> _subscript = base.subscript
> }
> }
>
> Joanna
>
> --
> Joanna Carter
> Carter Consulting
>
> _______________________________________________
> swift-evolution mailing list
> [email protected]
> https://lists.swift.org/mailman/listinfo/swift-evolution
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution