[swift-evolution] Smart KeyPaths

Joe Groff jgroff at apple.com
Fri Mar 17 16:56:22 CDT 2017


> On Mar 17, 2017, at 2:53 PM, Michael LeHew <lehewjr at apple.com> wrote:
> 
> 
>> On Mar 17, 2017, at 2:21 PM, BJ Homer <bjhomer at gmail.com <mailto:bjhomer at gmail.com>> wrote:
>> 
>> This looks great!
>> 
>> What happens in the case when there is a static property by the same name as an instance property? e.g.
>> 
>> struct Foo {
>>     static var bar: Bar
>>     var bar: Bar
>> }
>> 
>> Foo.bar // What is this?
>> 
>> Is it still possible to reference both the static property and a KeyPath to the instance method? 
> 
> This is essentially the same question that I arrived at in my reply to Vladimir.  I think Joe might be best able to answer here.

We already encounter this situation with static vs instance methods, since `Foo.bar` can refer to either a static method `bar` or an unbound instance method `bar`. We use type context to disambiguate, favoring the static member if context doesn't help:

struct X {
  static func foo() {}
  func foo() {}
}

let foo1 = X.foo // Defaults to static member
let foo2: () -> () = X.foo // Picks static member by type context
let foo3: (X) -> () -> () = X.foo // Picks instance member by type context

-Joe

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


More information about the swift-evolution mailing list