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

fixed __wrap and __throw #136

Merged
merged 1 commit into from
May 20, 2024
Merged

fixed __wrap and __throw #136

merged 1 commit into from
May 20, 2024

Conversation

jbcaillau
Copy link
Member

Quotations (= quote ... end) that defined local variables need these variables to be explicitly declared as local (local):

julia> foo() = quote
              try 0 + [ 0 ]
              catch a println(a) end
              end
foo (generic function with 1 method)

julia> eval(foo())
MethodError(+, (0, [0]), 0x0000000000007aef)

julia> a
ERROR: UndefVarError: `a` not defined

julia> a = 1
1

julia> eval(foo())
┌ Warning: Assignment to `a` in soft scope is ambiguous because a global variable by the same name exists: `a` will be treated as a new local. Disambiguate by using `local a` to suppress this warning or `global a` to assign to the existing global variable.
└ @ REPL[1]:2
MethodError(+, (0, [0]), 0x0000000000007aef)

julia> a
1

julia> foo() = quote local a
              try 0 + [ 0 ]
              catch a println(a) end
              end
foo (generic function with 1 method)

julia> eval(foo())
MethodError(+, (0, [0]), 0x0000000000007af0)

julia> a
1

NB. Also note the semantics of try ... catch depending on whether the variable exists or not in the global scope:

julia> b
ERROR: UndefVarError: `b` not defined

julia> try 0 + [ 0 ]
       catch b
       println(b)
       end
MethodError(+, (0, [0]), 0x0000000000007af0)

julia> b
ERROR: UndefVarError: `b` not defined

julia> b = 1
1

julia> try 0 + [ 0 ]
       catch b
       println(b)
       end
MethodError(+, (0, [0]), 0x0000000000007af0)

julia> b
MethodError(+, (0, [0]), 0x0000000000007af0)

@github-actions github-actions bot requested a review from ocots May 20, 2024 15:52
@jbcaillau
Copy link
Member Author

@ocots test passed, this one is for you 🙂

Copy link
Member

@ocots ocots left a comment

Choose a reason for hiding this comment

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

👌

@ocots ocots merged commit 32d0905 into main May 20, 2024
5 checks passed
@jbcaillau jbcaillau deleted the onepass-fix branch May 20, 2024 16:20
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