-
Notifications
You must be signed in to change notification settings - Fork 3.5k
dbg for with expressions #13886
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
dbg for with expressions #13886
Conversation
|
Thank you @dkuku for reopening the discussion 💜 A couple of comments from me:
Having several else blocks is officially an anti-pattern so I don't think I haven't tried, but I think that this approach might give an incorrect value for Behavior-wise, showing only the non-matching clause as suggested by José here is probably giving the most important piece of information, but my feeling is still that the behavior of the original PR is more helpful and consistent since it decomposes each step like |
lib/elixir/lib/macro.ex
Outdated
| quote do | ||
| [ | ||
| unquote(:->)( | ||
| [{unquote({:unmatched_ast, [], Elixir}), unquote({:result, [], Elixir})}], |
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.
FYI: You typically want to use unique_var for this, there are other examples in the dbg code around.
|
Thanks for the review—you’re right, handling I just wanted to reopen this because Maybe we should publicly ask how people think this should be handled? I know there are always strong opinions, but we could run a poll. What do you think, @josevalim |
|
To continue the discussion, I tried to reimplement my old PR without the process dict to see what it would mean: The support for guards and |
| assert formatted =~ "With clause unmatched on line" | ||
| assert formatted =~ "{:ok, height} <- Map.fetch(opts, :height) #=> :error" | ||
| assert formatted =~ "Then else clause matched on line" | ||
| assert formatted =~ "->(:error, 0) #=> 0" |
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.
This is being formatted incorrectly.
|
I would start with baby steps. Let's add the information about which clause failed (and why) and then return the overall result. We put this out there and collect feedback. If we know which clause failed, finding out the else clause should be straight-forward in almost all |
My take on the
dbgforwith- previous discussion is here: #12477I feel that without
dbgforwithclauses the dbg feature is incomplete:I started off with @sabiwara code but I took a different approach.
A with clause can have 3 possible ways of finishing:
In with expression only the lines with
<-can be unmatched so I focused only on these:Example code:
Currently the dbg does not print the whole code, just the important parts so the result is quite short:
<-section and then when it matched in->section - the printed result in this case is:The last one should be
:error -> 0- I need to check how to format this prorperly.