-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
base: main
Are you sure you want to change the base?
Conversation
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is!
lib/elixir/lib/inspect.ex
Outdated
for %{field: field} = map <- info, | ||
field != :__exception__, | ||
do: map | ||
if info = Inspect.Map.valid_struct_info(struct) do |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
lib/elixir/lib/inspect/algebra.ex
Outdated
@@ -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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Close #14717