Skip to content

Don't crash when inspecting OTP 29 native records#15278

Merged
josevalim merged 2 commits into
elixir-lang:mainfrom
wojtekmach:wm-inspect-native-records
Apr 16, 2026
Merged

Don't crash when inspecting OTP 29 native records#15278
josevalim merged 2 commits into
elixir-lang:mainfrom
wojtekmach:wm-inspect-native-records

Conversation

@wojtekmach
Copy link
Copy Markdown
Member

No description provided.

Comment thread lib/elixir/lib/inspect.ex
end

def inspect(native_record, _opts) do
:io_lib.format("~p", [native_record]) |> IO.iodata_to_binary()
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is obviously very naive implementation just to prevent crashes, a more robust one would use :record.get_module/1, :record.get_name/1, :record.get_field_names/1, :record.get/2, and maybe the new guard :erlang.is_record/2 like here:

https://github.com/erlang/otp/blob/OTP-29.0-rc3/lib/stdlib/src/io_lib.erl#L727:L750

Copy link
Copy Markdown
Contributor

@sabiwara sabiwara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea! 💜

Comment thread lib/elixir/lib/inspect.ex
Inspect.Map.inspect_as_struct(struct, Macro.inspect_atom(:literal, module), info, opts)
end

def inspect(native_record, _opts) do
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could add a comment that this is only temporary code, that we'll need to revisit if we add proper support for native record?

Comment thread lib/elixir/lib/inspect.ex
@josevalim josevalim merged commit ed478e8 into elixir-lang:main Apr 16, 2026
14 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.

3 participants