I've added dynamicMemberLookup keypath support to a generic class in hopes of achieving forwarding to the underlying type. This compiles and runs, and seems like it will work:
@dynamicMemberLookup
open class BaseClass<GenericType> {
public var child: GenericType!
subscript<T>(dynamicMember keyPath: KeyPath<GenericType, T>) -> T {
return child[keyPath: keyPath]
}
// ... impl omitted
}
public protocol Specialization: AnyObject {
var prop1: String { get }
var prop2: String { get }
}
public final class SubClass: BaseClass<Specialization> {
// ... impl omitted
}
While the above compiles, I am unable to use dynamicMemberLookup to proxy through to var child
as I'd expect. This doesn't compile:
let sub: SubClass<Specialization> = // ... impl omitted
print(sub.child.prop1) // ok
print(sub.prop1) // ERROR: Use of unresolved identifier
This should work, right?