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-7257] Property observers being called on a nil struct instance upon attempt to mutate a member property #49805
Comments
Hm. @rjmccall, what do you think is the right behavior here, with optional chaining involved? |
I think the right behavior is for things like this to abort the mutation and not call the setter. We currently can't do that consistently for all accesses because of materializeForSet, but generalized accessors will make it possible. |
@swift-ci create |
Comment by Stephan Schulz (JIRA) Please fix asap, the new behavior is annoying. |
This isn't new behavior; it's been like this since Xcode 8.3 at least. (There have been recent regressions in didSet behavior, but this isn't one of them.) |
Comment by Stephan Schulz (JIRA) Thanks for clarification. What kind of regressions have been made in the didSet behavior? I've experienced infinity loops connected to didSet and materializeForSet, which havn't been there in previous versions. This definitely feels like a bug to me after upgrading to Swift 4.1. |
Comment by Stephan Schulz (JIRA) I've created a bug report SR-7647 |
I wrote up an evolution pitch about fixing this. https://forums.swift.org/t/pitch-clarifying-the-semantics-of-abnormally-terminating-a-storage-access/16244 |
Environment
Xcode Version 9.2 (9C40b)
Additional Detail from JIRA
md5: 5ad4504b82dc7311d33318e3a9dbcb12
Issue Description:
Although apparently nothing is mutated, the observers of a are always called.
Refer to this thread for the discussion.
The SIL seems to be copying the entire composite variable
(Int -> A -> Optional<A>)
onto the stack, thedidSet
invocation simply being a side-effect of running the variable’s setter to copy back the contents from the stack."So no, evidently the compiler is not recognizing that it’s dealing with one big composite of value types and simply figuring that it can treat them all as one lump of data. It’s repeating the same unpacking process at every layer of nesting."
Might be related to SR-7220
The text was updated successfully, but these errors were encountered: