[SR-12477] Assignments to projected PropertyWrappers with overlapping mutations of the var itself are not considered a memory exclusivity violation #54917
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
Attachment: Download
Environment
Xcode 11.2.1
Additional Detail from JIRA
md5: 93ad43f82fe1e8ac6327450662ceb78d
duplicates:
Issue Description:
As part of an attempt to work around SR-12350, I wrote code that amounts to
```
$myWrappedProperty.mutatingFunction {
// note: this function does not escape.
myWrappedProperty = someValue
}
```
My setter for the projection was the traditional { self = newValue }.
Initially, I expected myWrappedProperty to have a value of someValue after this code was run. In fact, however, it had a value of someValue while mutatingFunction is executing, then reverts to its original value. This is extremely confusing; especially because didSet is not run for the assignment of the projection.
To be fair, it seems to me that the compiler is actually following the letter of the law; post projection it is a different variable being mutated. But since the documentation also implies that a goal of memory exclusivity is to avoid situations where the programmer's intent is ambiguous, it seems reasonable to consider adding checks for this case.
Using _myProperty instead of $myProperty does produce a crash.
There are zero references to "wrapper" in the language reference page on memory exclusivity. I think that even if this is considered "working as intended" there should still be some documentation of how it behaves; ideally in the page for PropertyWrappers.
I've attached a sample file demonstrating the issue.
The text was updated successfully, but these errors were encountered: