Skip to content
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

Allow variable assignment with @infiltry #118

Merged
merged 6 commits into from
Apr 12, 2024
Merged

Conversation

theogf
Copy link
Contributor

@theogf theogf commented Apr 8, 2024

This will allow for code like

@infiltry x = 3
2x

to work.

Otherwise, x will be only defined in the try scope.

@pfitzseb
Copy link
Member

pfitzseb commented Apr 8, 2024

I don't think this is the correct fix because it makes x global, IIUC.
And, arguably, people should just write

x = @infiltry foo()
2x

instead.

@theogf
Copy link
Contributor Author

theogf commented Apr 9, 2024

Ah you're right, we could potentially manipulate the expression as

x = try
  ..
catch
 @infiltrate
end

if @infiltry x = f(..) is called?

@pfitzseb
Copy link
Member

pfitzseb commented Apr 9, 2024

Yeah, but I still think that's not really worth it. Most* macros like this return their value, so x = @infiltry foo() should already be familiar.

*: Citation needed

@theogf
Copy link
Contributor Author

theogf commented Apr 9, 2024

Yeah, but I still think that's not really worth it. Most* macros like this return their value, so x = @infiltry foo() should already be familiar.

*: Citation needed

Yeah but what's unexpected is that the macro creates a new scope? I mentioned the new macro to someone and their first reaction was "oh I cannot assign variables using the macro" (unlike @show for example)

@theogf
Copy link
Contributor Author

theogf commented Apr 10, 2024

I went forward with my proposal. Also, I don't know if it was intentional but the exception was not rethrown

@pfitzseb
Copy link
Member

Yeah, we definitely should rethrow here. I'm fine with this implementation, but it's not super generic -- ideally we'd somehow hoist all local assignments out of the new scope, but that's actually pretty tricky I think.

Also, can you please add a new test instead of modifying the old one?

@theogf
Copy link
Contributor Author

theogf commented Apr 10, 2024

ideally we'd somehow hoist all local assignments out of the new scope

So you mean in the case someone would do:

@infiltry begin
   x = 3
   y = 2x
end

Also, can you please add a new test instead of modifying the old one?

Yep, will rework the tests.

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 85.71429% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 76.61%. Comparing base (13f09b4) to head (278237c).

Files Patch % Lines
src/Infiltrator.jl 85.71% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #118      +/-   ##
==========================================
+ Coverage   76.53%   76.61%   +0.07%     
==========================================
  Files           1        1              
  Lines         439      449      +10     
==========================================
+ Hits          336      344       +8     
- Misses        103      105       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -111,19 +111,49 @@ end
Wraps expression in a try block, infiltrate if an exception is raised.
Equivalent to:

```julia
Copy link
Member

Choose a reason for hiding this comment

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

Don't need the indentation here if you add the fence.

Would also be good to add the rethrows in both cases.

$(esc(expr))
infiltrator_catch_and_rethrow = quote
$(Infiltrator.start_prompt)($(__module__), Base.@locals, $(String(__source__.file)), $(__source__.line), ex, catch_backtrace())
rethrow(ex)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
rethrow(ex)
rethrow()

is more correct I think.

@pfitzseb pfitzseb merged commit d75236d into JuliaDebug:master Apr 12, 2024
6 checks passed
@theogf theogf deleted the patch-1 branch April 12, 2024 09:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants