New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SR-1239] Implement SE-0064: Referencing the Objective-C selector of property getters and setters #43847
Comments
I have started implementing this proposal and am now at a point where I see two ways to progress in order to be able to be able to look up instance variables on types. Could you maybe have a look at the options below and tell me which one you prefer or if you have a better idea how to implement it? For sake of example let’s say we have the following class: class Foo {
var bar: Int = 0
func baz() {}
} The issue I ran into is that you can access I can currently think of two options on how to solve this: Allow looking up instance members on their typesThis would allow the lookup of instance members on types in the context of getter/setter {{#selector}}s. However, AFAIK this is a fairly heavyweight addition to the compiler, requiring two new expression kinds in the AST (unresolved/resolved instance member lookup on a type) and a new constraint kind (also for looking up an instance member on a type). Implement partial application of propertiesThis option would basically overload each property thrice, once as the actual variable ( |
I think performing lookup on instance members of the types is probably the best approach. For #selector on properties, I think it's reasonable to handle the semantic analysis outside of the constraint solver, with specialized code to look up the dotted path and find the appropriate entry points. It should give us clearer diagnostics, and it would be fine to say that we're going to restrict the grammar somewhat inside #selector to make that possible. I'm hoping we can re-use that same semantic analysis code for the also-accepted #keyPath, which has its own reasons why it shouldn't use the general constraint system. |
Ah, I didn’t think about bypassing the constraint system, seems like a good idea. Do you know if this is already done somewhere else? |
There is some "late" type checking in CSApply that crawls the AST (e.g., for #selector; see visitObjCSelectorExpr), but not much in the way of separate one-off type checking. |
Thanks for your help so far. |
I think it's reasonable to disallow arbitrary expressions inside `#selector`. I highly doubt they are actually used often enough to justify having them, and we gain the ability have some other custom rules (e.g., `#selector(Foo.bar())` can refer to a zero-parameter method). I do think we need to support "as" at the top-level to handle disambiguation via types. Do you want to take a shot at specifying a grammar for the argument to `#selector`? |
I have created a draft proposal including the formal grammar at https://github.com/ahoppen/swift-evolution/blob/arbitrary-expressions-in-selectors/proposals/0000-arbitrary-expressions-in-selectors.md. Would you mind having a look if you see any major issues? Otherwise I will submit it to swift-evolution. |
I have a few requests for the proposal: (1) Should you use the unqualified-name production from [SE-0021](https://github.com/apple/swift-evolution/blob/master/proposals/0021-generalized-naming.md) instead of inventing function-disambiguation? |
(1) Thanks, I didn’t know about that production rule. I looked inside “The Swift Programming Language” but couldn’t find it there. Maybe the book needs to be updated selector-path
=> selector-member-path
=> identifier . selector-member-path
=> identifier . unqualified-name
=> self.method(a:b:) (3) In retrospect, I would rather like to propose a way to reference the function with no parameters everywhere. |
Finished in GitHub master 3650ce8, as a joint effort between Alex Hoppen and I. |
Additional Detail from JIRA
md5: 3f6ae80e1558fced004a5c1354a23976
Issue Description:
https://github.com/apple/swift-evolution/blob/master/proposals/0064-property-selectors.md
The text was updated successfully, but these errors were encountered: