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

fix @manipulate for upcoming base changes #46

Merged
merged 2 commits into from
Aug 16, 2021

Conversation

simeonschaub
Copy link
Contributor

@@ -79,6 +79,10 @@ macro manipulate(args...)
block = expr.args[2]
if expr.args[1].head == :block
bindings = expr.args[1].args
# remove trailing LineNumberNodes from loop body as to not just return `nothing`
Copy link
Owner

Choose a reason for hiding this comment

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

I'm not 100% sure I understand what will change in newer julia versions, but the loop body is block , defined a few lines above. expr is a for loop, so the body should be its second argument.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, that's embarassing... ^^ Yes, you are absolutely right!

@@ -79,6 +79,10 @@ macro manipulate(args...)
block = expr.args[2]
if expr.args[1].head == :block
bindings = expr.args[1].args
# remove trailing LineNumberNodes from loop body as to not just return `nothing`
if bindings[end] isa LineNumberNode
resize!(bindings, length(bindings) - 1)
Copy link
Owner

Choose a reason for hiding this comment

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

Why not just pop! instead of resize!(v, length(v) - 1)? I think it'd be a bit more readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, seems reasonable.

@piever
Copy link
Owner

piever commented Aug 14, 2021

Thanks for the PR!

For me to understand, the loop body already has some LineNumberNodes which are harmless (and may actually be useful for stacktraces if something within @manipulate errors), but the last one should be avoided, because it messes with the return value.

May be worth to also add a link to the PR to julia in the comments in the source code.

@simeonschaub
Copy link
Contributor Author

For me to understand, the loop body already has some LineNumberNodes which are harmless (and may actually be useful for stacktraces if something within @manipulate errors), but the last one should be avoided, because it messes with the return value.

Yes, blocks always return the return value of the last expression and if that's a LineNumberNode, that will evaluate to nothing.

May be worth to also add a link to the PR to julia in the comments in the source code.

done.

@piever piever merged commit cc0c4aa into piever:master Aug 16, 2021
@simeonschaub simeonschaub deleted the sds/41857_fix branch August 16, 2021 10:17
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.

2 participants