-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Parse] Enable self rebinding (to self) #15306
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
Conversation
Could you add a test cases for implicit method/property references? class MyCls {
func something() {}
func test() {
let self = OtherCls() // Even if `self` is shadowed,
something() // this should still refer `MyCls.something`.
}
} I know this currently works. But it prevents accidental breakage in the future. |
@rintaro added |
@swift-ci please test |
@rintaro does everything else look mergeable to you? cc @DougGregor (owner) |
No more objection from me. Defer to @DougGregor (or other core team member) on the decision. |
test/Parse/self_rebinding.swift
Outdated
func something() {} | ||
|
||
func test() { | ||
// expected-warning @+1 {{}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be nice to have some part of the warning text here, for others that read the test later on. Is the warning about rebinding self
to an unrelated type (which would be a really good warning, IMO!), or is it something else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in this case it's just about the variable being unused. I included the text.
test/Parse/self_rebinding.swift
Outdated
} | ||
} | ||
|
||
Writer().nonStop() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can delete this line; it doesn't add anything.
Instead of parisng identifiers and fallthrough to self, treat `kw_self` the same as identifiers. This enables binding to self.
@swift-ci please test |
Is this PR linked to an evolution proposal? There is an old evolution proposal here already merged, but in Deferred status. Seen the general acceptance shown in the discussion thread + the merge of this PR, would it make sense to consider updating the evolution proposal and taking it back to life? |
@dduan and @DougGregor can you two look at revising and updating SE-0079? It is related to this patch and is causing confusion for people who think that this behavior is not supposed to be supported. |
Will a simple update of status suffice? swiftlang/swift-evolution#900 |
Unfortunately, it seems like this may still not work in LLDB: https://bugs.swift.org/browse/SR-6156 😞 |
As discussed in this thread, this patch allows "self" to be an identifier bound to
self
(see added tests for examples), and is useful in closures whereself
is weakly captured to avoid retain cycles. The current behavior of allowingremains for source compatibility.
Instead of parsing identifiers and fallthrough to parsing self, treat
kw_self
the same as identifiers.