Skip to content

avoid using Keyword.pop/2 in ExUnit.Diff.struct_module/2#15489

Merged
josevalim merged 1 commit into
elixir-lang:mainfrom
tudborg:tudborg/ex_unit_diff_struct_module_keyword_issue
Jun 16, 2026
Merged

avoid using Keyword.pop/2 in ExUnit.Diff.struct_module/2#15489
josevalim merged 1 commit into
elixir-lang:mainfrom
tudborg:tudborg/ex_unit_diff_struct_module_keyword_issue

Conversation

@tudborg

@tudborg tudborg commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

In ExUnit.Diff.struct_module/2 we call Keyword.pop(kw, :__struct__)
but we don't actually know if kw is 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:

ExUnit.Diff.struct_module/2 is being called for both structs and maps.
(since bbf54bc, before this point we delegated to diff_map earlier)

diff_quoted_struct uses the return of struct_module to determine when to call diff_quoted_struct or diff_map, so at this point, we don't actually know if kw represents a Keyword or any other map pairs.

This fix seemed straight forward, just don't use Keyword.pop/2 to get the :__struct__ value out of kw.
I've used Enum.split_with instead, to make sure that all occurrences of :__struct__ is removed (just like Keyword.pop/2 would have)

I considered using :lists.keytake instead of Enum.split_with, but that would return at the first occurrence.

`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`
@josevalim josevalim merged commit 56bc730 into elixir-lang:main Jun 16, 2026
15 checks passed
@josevalim

Copy link
Copy Markdown
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