Clarify struct!/2 update behavior
#13990
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a bit of a speculative PR. I'm not sure what the proper wording should be, but after a bit of discussion on Discord, this seems maybe okay.
My general complaint about the current text is that it's not very obvious why it's even there. The sentence starting with "However" seems like it may be better to remove entirely. However (heh), it seems like this can be improved. Really, there's a kind of strange table of behaviors possible for struct construction and updating, especially when involving
@enforce_keys. Part of me feels like this can be ignored until potential improvements to the static type system, but I think it is and will still be somewhat relevant for runtime behavior.I considered specifying that
struct/2can produce results that don't exactly honor@enforce_keys, but due to the dynamic nature of Elixir, it's not entirely true. Dialyzer makes this more complicated, since it will enforce keys better when using constructor functions, but you can also always do%{__struct__: Foo}to create a malformed struct.