avoid using Keyword.pop/2 in ExUnit.Diff.struct_module/2#15489
Merged
josevalim merged 1 commit intoJun 16, 2026
Merged
Conversation
`struct_module` is being called for both structs and maps. `diff_quoted_struct` uses the return of `struct_module` to determine when to call `diff_quoted_struct` or `diff_map`
Member
|
💚 💙 💜 💛 ❤️ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
In
ExUnit.Diff.struct_module/2we callKeyword.pop(kw, :__struct__)but we don't actually know if
kwis a Keyword here.I stumbled on this while looking at what @josevalim said in #15470 (comment)
I wanted to see what actually broke if we guarded Keyword functions for keyword lists.
Only few tests blew up, and only in ExUnit, examples:
elixir/lib/ex_unit/test/ex_unit/diff_test.exs
Lines 527 to 531 in 1d59997
elixir/lib/ex_unit/test/ex_unit/diff_test.exs
Lines 563 to 570 in 1d59997
ExUnit.Diff.struct_module/2is being called for both structs and maps.(since bbf54bc, before this point we delegated to
diff_mapearlier)diff_quoted_structuses the return ofstruct_moduleto determine when to calldiff_quoted_structordiff_map, so at this point, we don't actually know ifkwrepresents a Keyword or any other map pairs.This fix seemed straight forward, just don't use
Keyword.pop/2to get the:__struct__value out ofkw.I've used
Enum.split_withinstead, to make sure that all occurrences of:__struct__is removed (just likeKeyword.pop/2would have)I considered using
:lists.keytakeinstead ofEnum.split_with, but that would return at the first occurrence.