In a struct annotated with @dynamicMemberLookup, we (apparently) can only access a dynamic member if we prefix it with self. If redudantSelf is enabled, self's are removed without considering this case, and the formatted code does not compile anymore.
@dynamicMemberLookup
struct Wrapper {
struct Wrapped {
var string: String = "A"
}
let wrapped = Wrapped()
subscript<T>(dynamicMember keyPath: KeyPath< Wrapped, T>) -> T {
wrapped[keyPath: keyPath]
}
func work() {
if self.string == "A" { // This compiles
//…
}
if string == "A" { // This is the formatted expression with redudantSelf enabled. Does not compile, on Xcode 12.5b1 at least
//…
}
}
}
Hello,
In a struct annotated with
@dynamicMemberLookup
, we (apparently) can only access a dynamic member if we prefix it withself
. IfredudantSelf
is enabled,self
's are removed without considering this case, and the formatted code does not compile anymore.