-
Notifications
You must be signed in to change notification settings - Fork 3.4k
implement dbg for if expressions #13603
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
Changes from 1 commit
57c58c7
4945153
5fc7161
3e3d797
d5e5734
6edbcfc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2642,6 +2642,15 @@ defmodule Macro do | |
end | ||
end | ||
|
||
defp dbg_ast_to_debuggable({:if, _meta, [condition_ast, _clauses]} = ast) do | ||
quote do | ||
condition_result = unquote(condition_ast) | ||
result = unquote(ast) | ||
|
||
{:if, unquote(escape(ast)), unquote(escape(condition_ast)), condition_result, result} | ||
end | ||
end | ||
|
||
# Any other AST. | ||
defp dbg_ast_to_debuggable(ast) do | ||
quote do: {:value, unquote(escape(ast)), unquote(ast)} | ||
|
@@ -2755,6 +2764,23 @@ defmodule Macro do | |
{formatted, value} | ||
end | ||
|
||
defp dbg_format_ast_to_debug( | ||
{:if, ast, condition_ast, condition_result, result}, | ||
options | ||
) do | ||
formatted = [ | ||
dbg_maybe_underline("If condition", options), | ||
":\n", | ||
dbg_format_ast_with_value(condition_ast, condition_result, options), | ||
?\n, | ||
dbg_maybe_underline("If expression", options), | ||
" (#{if result, do: "do", else: "else"} clause executed):\n", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we call the "do clause" the "truthy clause" instead? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Honestly, I would just print the value of the condition and the value we return. It is easy to infer which clause was executed from that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also think it's enough - I was trying to make it similar to other implementations. |
||
dbg_format_ast_with_value(ast, result, options) | ||
] | ||
|
||
{formatted, result} | ||
end | ||
|
||
defp dbg_format_ast_to_debug({:value, code_ast, value}, options) do | ||
{dbg_format_ast_with_value(code_ast, value, options), value} | ||
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.
I think we might need to check the meta here - since
if
is not a special form unlikecase
& co, it can be redefined.We'd need a test for this case too I think
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 did that but maybe there is a better way to implement it?