Skip to content

Conversation

@harrisi
Copy link
Contributor

@harrisi harrisi commented Nov 12, 2024

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/2 can 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.

@josevalim
Copy link
Member

I went with removing the sentence altogether. You are right, @enforce_keys is not relevant for updates, so we should not mention it. :)

@josevalim josevalim merged commit 7c6efcf into elixir-lang:main Nov 13, 2024
@josevalim
Copy link
Member

💚 💙 💜 💛 ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants