Skip to content
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-4464] Assigning a property to itself fails in 3.1 #47041

Open
iby opened this issue Apr 1, 2017 · 4 comments
Open

[SR-4464] Assigning a property to itself fails in 3.1 #47041

iby opened this issue Apr 1, 2017 · 4 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation good first issue Good for newcomers

Comments

@iby
Copy link

iby commented Apr 1, 2017

Previous ID SR-4464
Radar None
Original Reporter @iby
Type Bug
Status In Progress
Resolution

Attachment: Download

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, 3.1Regression, DiagnosticsQoI, StarterBug
Assignee None
Priority Medium

md5: 702671bd69d19bebf1a102eb3ec92355

Issue Description:

Prior 3.1 we could assign property to itself if needed with self.name = (self.name), now it fails. Also, see this for details – http://stackoverflow.com/a/31931318/458356.

Just discovered by luck, apparently the supported syntax now is (self.name = self.name), is this official?

@belkadan
Copy link
Contributor

belkadan commented Apr 3, 2017

I think the original syntax is probably still what we'd want to support in the rare cases where you actually want to do this.

@belkadan
Copy link
Contributor

belkadan commented Apr 3, 2017

The fix would be to change TypeChecker::diagnoseSelfAssignment to ignore cases where the source of the assignment (the right-hand side) is a ParenExpr.

@swift-ci
Copy link
Collaborator

Comment by Adam Newton (JIRA)

I no longer have enough spare time to dedicate to this, so I'm going to unassign it. I have work-in-progress PR here with great feedback from the swift team which should help someone else get started. #10390

@swift-ci
Copy link
Collaborator

Comment by Jessy Catterwaul (JIRA)

Swift 5.3: Only parentheses solve this for instances. But for static properties, a `Self.` on either side of the assignment operator works. See the attached package.

Capturing [self] also subverts the error. I didn't demonstrate that in the package.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants