Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed a bug in replace returns (#352)
On master we have the following behavior for a test-case in Turing.jl: ```julia julia> @macroexpand @model empty_model() = begin x = 1; end quote function empty_model(__model__::DynamicPPL.Model, __varinfo__::DynamicPPL.AbstractVarInfo, __context__::DynamicPPL.AbstractContext; ) #= REPL[5]:1 =# begin #= REPL[5]:1 =# #= REPL[5]:1 =# return (x = 1, __varinfo__) end end begin $(Expr(:meta, :doc)) function empty_model(; ) #= REPL[5]:1 =# return (DynamicPPL.Model)(:empty_model, empty_model, NamedTuple(), NamedTuple()) end end end ``` Notice the `return` statement: it converted the statement `x = 1` which returns `1` into an attempt at a `NamedTuple{(:x, :__varinfo__)}`. On Julia 1.6 we don't really notice much of difference, because `first` and `last` will have the same behavior, but on Julia 1.3 the tests would fail in TuringLang/Turing.jl#1726 since "implicit" names in construction of `NamedTuple` isn't supported. This PR addresses this issue by simply capturing the return-value in separate variable, which is then combined with `__varinfo__` in a `Tuple` at the end. This should both fail and succeed whenever standard Julia code would.
- Loading branch information
57c50f1
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.
@JuliaRegistrator register
57c50f1
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.
Registration pull request created: JuliaRegistries/General/50616
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: