Skip to content

Inspect ill-formed structs as maps #14718

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

sabiwara
Copy link
Contributor

Close #14717

Comment on lines -203 to -209
test "inspect" do
asc = %{__struct__: Range, first: 1, last: 3}
desc = %{__struct__: Range, first: 3, last: 1}

assert inspect(asc) == "1..3"
assert inspect(desc) == "3..1//-1"
end
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These will be rendered as maps, which I think is acceptable now?
It's been a while since stepped ranges.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, it is!

for %{field: field} = map <- info,
field != :__exception__,
do: map
if info = Inspect.Map.valid_struct_info(struct) do
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually do we still need this if it is handled upstream in Inspect.Algebra?
Perhaps I could just call module.__info__(:struct) directly, I wasn't sure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I went with cab02a1, let me know if that's OK.

@@ -396,7 +396,7 @@ defmodule Inspect.Algebra do
def to_doc_with_opts(term, opts)

def to_doc_with_opts(%_{} = struct, %Inspect.Opts{inspect_fun: fun} = opts) do
if opts.structs do
if opts.structs and Inspect.Map.valid_struct?(struct) do
Copy link
Member

Choose a reason for hiding this comment

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

Should we move the function to this module instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed makes sense, I initially thought I'd need it at several places but not anymore 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

Unexpected behavior of Map.merge(<map set>, ...)
2 participants